Skip to content

Add ability to use maui-blazor from http context #5639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sake402 opened this issue Mar 29, 2022 · 5 comments
Closed

Add ability to use maui-blazor from http context #5639

sake402 opened this issue Mar 29, 2022 · 5 comments
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView proposal/open

Comments

@sake402
Copy link

sake402 commented Mar 29, 2022

Description

Currently maui-blazor run in a browser client with url https://0.0.0.0. This makes it difficult to reference external url with http scheme due to browser security.

Public API Changes

Would love to be able configure builder.RegisterBlazorMauiWebView() to allow the url for the dom to be http instead of https.

Possibly like

builder.RegisterBlazorMauiWebView(options => options.SSL = false)

Intended Use-Case

In our case we are fetching external data from url that doesn't not have https at all

@Eilon Eilon added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Mar 29, 2022
@Eilon
Copy link
Contributor

Eilon commented Mar 29, 2022

@sake402 is this for displaying web assets directly from HTML, such as <img src="http://www.example.com/image.jpg" />? Or is this for the app making outgoing HTTP requests using something like HttpClient?

It should be noted that HTTP is not a secure protocol in any sense, so it is strongly discouraged to be used in any scenario at all. HTTP requests are vulnerable to many kinds of attacks.

@sake402
Copy link
Author

sake402 commented Mar 29, 2022

@Eilon Yes for assets.

But In our case, we don't have control over the url of these assets as the source does not support https;

@Eilon
Copy link
Contributor

Eilon commented Mar 29, 2022

@sake402 got it, thank you for clarifying.

@mkArtakMSFT mkArtakMSFT added this to the .NET 7 milestone Mar 29, 2022
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 7, Future May 4, 2022
@ghost
Copy link

ghost commented May 4, 2022

We've moved this issue to the Future milestone. This means that it is not going to be worked on for the coming release. We will reassess the issue following the current release and consider this item at that time.

@javiercn
Copy link
Member

javiercn commented May 4, 2022

@sake402 Allowing the webview to disable HTTPS has security implications since there is nothing that tells users that the page is in an unsafe context. (It might also disable some APIs) and might cause issues with Blazor itself.

There are ways in which you can accomplish this without having to change the URL scheme which will lower the security guarantees for your entire app.

You can create a component that receives the URL, downloads the file, passes it down to JavaScript via JS interop, creates an object URL and passes that object URL to the actual image tag.

@inject IJSRuntime JS

@if(@_objectUrl != null)
{
  @ChildContent(_objectUrl);
}

@code{
  private string _objectUrl;
  
  [Parameter] RenderFragment<string> Src { get; set; }
  
  protected override OnParametersSet()
  {
    var client = new HttpClient();
    var stream = await client.GetStreamAsync(Src);
    var streamReference = new DotNetStreamReference(reference);
    _objectUrl = await JS.InvokeAsync("URL.createObjectUrl", streamReference);
  }
}

We do have an issue for having a built-in component in .NET 7.0 that will help with something like this.

Based on this, I'm going to close this issue, since there are ways in which you can achieve this scenario and we are in general not comfortable with any flag that can lower the security in a production application. If we see more feedback in the future, we might reconsider.

@javiercn javiercn closed this as completed May 4, 2022
@javiercn javiercn removed this from the Future milestone May 4, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView proposal/open
Projects
None yet
Development

No branches or pull requests

4 participants