Repository navigation
[Feature] Add AllowedDomains URL allowlisting for WebView, HybridWebView, and BlazorWebView #35470
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
Changes from 18 commits
6a91398
bb0b49d
8dc67ef
308f5a7
77f5a6e
2204a43
0e1a305
0b93340
3aad311
517413b
8e1a2c2
6c9d184
757d00f
f462f84
a6d6067
e689c3a
a30208a
fabc94a
ac9f1a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| #nullable enable | ||
| override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.ConnectHandler(Android.Webkit.WebView! platformView) -> void | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.get -> System.Collections.Generic.IList<string!>? | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.set -> void | ||
| static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomainsProperty -> Microsoft.Maui.Controls.BindableProperty! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.get -> System.Collections.Generic.IList<string!>? | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.set -> void | ||
| static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomainsProperty -> Microsoft.Maui.Controls.BindableProperty! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.get -> System.Collections.Generic.IList<string!>? | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.set -> void | ||
| static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomainsProperty -> Microsoft.Maui.Controls.BindableProperty! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.get -> System.Collections.Generic.IList<string!>? | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.set -> void | ||
| static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomainsProperty -> Microsoft.Maui.Controls.BindableProperty! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.get -> System.Collections.Generic.IList<string!>? | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.set -> void | ||
| static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomainsProperty -> Microsoft.Maui.Controls.BindableProperty! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.get -> System.Collections.Generic.IList<string!>? | ||
| Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomains.set -> void | ||
| static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.AllowedDomainsProperty -> Microsoft.Maui.Controls.BindableProperty! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,18 @@ protected override WKWebView CreatePlatformView() | |
| // iOS WKWebView doesn't allow handling 'http'/'https' schemes, so we use the fake 'app' scheme | ||
| config.SetUrlSchemeHandler(new SchemeHandler(this), urlScheme: "app"); | ||
|
|
||
| // When AllowedDomains is set, enable WKAppBoundDomains enforcement for sub-resource blocking | ||
| var allowedDomains = (VirtualView as IAllowedDomainsWebView)?.AllowedDomains; | ||
| if (allowedDomains is not null && allowedDomains.Count > 0) | ||
| { | ||
| if (OperatingSystem.IsIOSVersionAtLeast(14) || OperatingSystem.IsMacCatalystVersionAtLeast(14)) | ||
| { | ||
| config.LimitsNavigationsToAppBoundDomains = true; | ||
| } | ||
|
|
||
| Microsoft.Maui.Handlers.WebViewPlistValidator.ValidateAllowedDomainsAgainstPlist(allowedDomains, Logger); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS/MacCatalyst enforcement relies entirely on the app correctly configuring |
||
| } | ||
|
|
||
| var webview = new WKWebView(RectangleF.Empty, config) | ||
| { | ||
| BackgroundColor = UIColor.Clear, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.