Skip to content

Commit 94ede54

Browse files
authored
Merge pull request #5442 from MicrosoftEdge/api-IsEnhancedSecurityModeEnabled
API introduction: CoreWebView2Profile.EnhancedSecurityModeLevel
2 parents 37d5ce4 + 6fdde7f commit 94ede54

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

specs/EnhancedSecurityModeLevel.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
EnhancedSecurityModeLevel
2+
===
3+
4+
# Background
5+
6+
Enhanced Security Mode (ESM) is a Microsoft Edge security feature that reduces
7+
the risk of memory-related vulnerabilities by disabling JavaScript Just-in-Time
8+
(JIT) compilation and enabling additional operating system protections.
9+
10+
In WebView2, ESM is off by default to avoid performance impact. You can enable
11+
ESM for stricter security when rendering untrusted sites. While this improves
12+
security, it may reduce JavaScript performance.
13+
14+
In Microsoft Edge, ESM offers two levels:
15+
16+
- Balanced – Enhanced security is used for unfamiliar sites based on browser usage patterns.
17+
- Strict – Enhanced security is used for all sites.
18+
19+
![image](https://github.com/MicrosoftEdge/WebView2Feedback/assets/82386753/35977716-e46c-4257-82da-906b0c6f833e)
20+
21+
Unlike Microsoft Edge, WebView2 does not support the heuristic-based "Balanced"
22+
level; only Off and Strict are available.
23+
24+
Today, the ESM level in WebView2 can be set only at environment creation by using
25+
the `--sdsm-state` browser feature flag ([webview2 browser flag docs](https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/webview-features-flags?tabs=dotnetcsharp)).
26+
The setting applies globally to all profiles and cannot be changed at runtime.
27+
28+
This proposal introduces an API to configure the Enhanced Security Mode level.
29+
The configuration is not persisted to the user data folder. The property is reset when the profile is recreated.
30+
31+
# Description
32+
33+
The `EnhancedSecurityModeLevel` property allows you to control the Enhanced Security
34+
Mode level for WebView2 instances associated with a profile. This level applies to the context of the profile. That is, all WebView2s sharing the same profile are affected.
35+
The configuration is not persisted to the user data folder. The property is reset when the profile is recreated.
36+
37+
The default value is `COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_OFF`.
38+
39+
When set to `Off`, Enhanced Security Mode is completely disabled. When set to
40+
`Strict`, the feature is enabled and applies strict security policies to all sites.
41+
42+
See `COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL` for descriptions of levels.
43+
44+
Changes apply to future navigations; a reload may be required for the change to take effect.
45+
46+
# Examples
47+
48+
## Setting the ESM Level
49+
50+
Set Enhanced Security Mode level for a profile.
51+
52+
```c#
53+
void SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel value)
54+
{
55+
var profile = webView2.CoreWebView2.Profile;
56+
profile.EnhancedSecurityModeLevel = value;
57+
MessageBox.Show(this,
58+
"Enhanced Security Mode level is set successfully",
59+
"Enhanced Security Mode");
60+
}
61+
```
62+
63+
```cpp
64+
void SettingsComponent::SetEnhancedSecurityModeLevel(
65+
COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value)
66+
{
67+
wil::com_ptr<ICoreWebView2_13> webView2_13;
68+
webView2_13 = m_webView.try_query<ICoreWebView2_13>();
69+
70+
if (webView2_13)
71+
{
72+
wil::com_ptr<ICoreWebView2Profile> profile;
73+
CHECK_FAILURE(webView2_13->get_Profile(&profile));
74+
75+
auto profile12 = profile.try_query<ICoreWebView2Profile12>();
76+
if (profile12)
77+
{
78+
CHECK_FAILURE(profile12->put_EnhancedSecurityModeLevel(value));
79+
MessageBox(
80+
nullptr,
81+
L"Enhanced Security Mode level is set successfully",
82+
L"Enhanced Security Mode", MB_OK);
83+
}
84+
}
85+
}
86+
```
87+
88+
# API Details
89+
90+
```
91+
/// Enhanced Security Mode levels.
92+
[v1_enum]
93+
typedef enum COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL {
94+
/// Enhanced Security Mode is turned off.
95+
COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_OFF,
96+
/// Enhanced Security Mode is enabled in Strict level. Disables JavaScript
97+
/// Just-in-Time (JIT) compilation and enables additional operating system protections.
98+
///
99+
/// This level applies enhanced security for all sites but may reduce JavaScript performance.
100+
///
101+
/// See [Browsing more safely with Microsoft Edge](https://learn.microsoft.com/en-us/DeployEdge/microsoft-edge-security-browse-safer)
102+
/// for more details about Enhanced Security Mode.
103+
COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_STRICT,
104+
} COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL;
105+
106+
/// Extension of ICoreWebView2Profile to control Enhanced Security Mode (ESM) level.
107+
///
108+
/// ESM reduces the risk of memory-related vulnerabilities by disabling JavaScript
109+
/// Just-in-Time (JIT) compilation and enabling additional operating system protections.
110+
/// This property applies to all WebView2 instances sharing the same profile.
111+
/// The configuration is not persisted to the user data folder.
112+
/// The property is reset when the profile is recreated.
113+
///
114+
/// See `COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL` for descriptions of levels.
115+
///
116+
/// Changes apply to future navigations; reload may be required.
117+
///
118+
/// Enabling ESM improves security but may reduce JavaScript performance.
119+
[uuid(450fab50-f6d8-4517-baea-964ec12d5c8c), object, pointer_default(unique)]
120+
interface ICoreWebView2Profile12 : IUnknown {
121+
/// Gets the `EnhancedSecurityModeLevel` property.
122+
[propget] HRESULT EnhancedSecurityModeLevel([out, retval] COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL* value);
123+
124+
/// Sets the `EnhancedSecurityModeLevel` property.
125+
[propput] HRESULT EnhancedSecurityModeLevel([in] COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value);
126+
}
127+
```
128+
129+
```c# (but really MIDL3)
130+
namespace Microsoft.Web.WebView2.Core
131+
{
132+
enum CoreWebView2EnhancedSecurityModeLevel
133+
{
134+
Off = 0,
135+
Strict = 1
136+
};
137+
138+
runtimeclass CoreWebView2Profile
139+
{
140+
// ...
141+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile12")]
142+
{
143+
// ICoreWebView2Profile12 members
144+
CoreWebView2EnhancedSecurityModeLevel EnhancedSecurityModeLevel { get; set; };
145+
}
146+
}
147+
}
148+
```

0 commit comments

Comments
 (0)