Skip to content

Conversation

@chetanpandey1266
Copy link
Contributor

@chetanpandey1266 chetanpandey1266 commented Dec 11, 2025

This pull request introduces a new specification for Trusted Origin support in WebView2, enabling applications to apply different security and feature policies based on the trust level of content origins. The changes provide APIs for designating trusted origins and configuring feature access and security settings per origin, addressing previous limitations around uniform policy enforcement.

Trusted Origin API and Feature Management:

  • Added APIs to CoreWebView2Profile for creating, setting, and retrieving feature settings for trusted origins, allowing fine-grained control over security and feature policies.
  • Defined new interfaces and enums (ICoreWebView2StagingProfile3, ICoreWebView2StagingTrustedOriginFeatureSetting, and COREWEBVIEW2_TRUSTED_ORIGIN_FEATURE) to represent origin-specific feature configurations, including AccentColor, PersistentStorage, and EnhancedSecurityMode.

Usage Examples and API Details:

  • Provided C++ and .NET/WinRT code samples demonstrating how to set and get trusted origin feature settings, including support for wildcard origin patterns.
  • Documented API details for both C++ and .NET/WinRT, specifying method signatures and usage for managing trusted origin features.

Background and Motivation:

  • Explained the need for Trusted Origin support, highlighting challenges with uniform security policies and the benefits of selective feature enable

@chetanpandey1266 chetanpandey1266 added the API Proposal Review WebView2 API Proposal for review. label Dec 11, 2025
Copy link

@billxc billxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we considering supporting an API that allows updating a single feature at a time? There are scenarios where users don't want to update the entire feature list, but rather just toggle one specific feature on or off.

In the current API design, all other features are kept at their default state. This forces users to set the entire list, which means they must first retrieve the current state of all features to safely make updates. Since our API is asynchronous, this adds further complexity to the user's code.

Ideal sample code:

profile.SetTrustedOriginFeature("https://*.contoso.com", CoreWebView2TrustedOriginFeature.AccentColor, false);

@shrinaths
Copy link

The API does not mandate setting all features. However if you do want to set more than one, that is allowed.

/// This method allows configuring multiple features for trusted origins,
/// such as accent color, persistent storage, and enhanced security mode.
/// The origins can be both exact origin strings and wildcard patterns.
/// For detailed examples, refer to the table at: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.addwebresourcerequestedfilter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document what happens for multiple subsequent calls that overlap. I'm not sure that it matters too much what the answer is, but we do need to say how it works.

For instance if you call once:
https://example.com, AccentColor: true
And then after that you call:
https://example.com, PersistentStorage: true
What happens when you navigate to https://example.com? Does only the latest call apply (only PersistentStorage: true) or is it the aggregate of all previous calls (both AccentColor: true, and PersistentStorage: true)?

Or if you call
https://example.com, AccentColor: true, PersistentStorage: true
And then
https://*.com, AccentColor: false
What happens when you navigate to https://example.com? Does it get only the latest rule applied (AccentColor: false), or an aggregate of the rules ordered by when they were called (AccentColor: false, PersistentStorage: true)?

@chetanpandey1266 chetanpandey1266 force-pushed the user/chetanpandey/TrustedOriginNewApproach-draft branch from c465b5d to 507a3ea Compare December 16, 2025 11:01
[in] ICoreWebView2StagingTrustedOriginFeatureSetting** features
);

/// Gets the feature configurations for a specified origin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify in the documentation comment if you get only the configuration specified explicitly for that origin, or if its all the applicable configurations that apply to that origin due to wildcards as well. For example if you call

https://example.com/, PersistentStorage: true
And then
https://*.com, AccentColor: true

And then do a Get for https://example.com, is it just the PersistentStorage: true, or both of them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Proposal Review WebView2 API Proposal for review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants