Skip to content

Commit 5b30ba1

Browse files
authored
Security node article updates 8.0 (#30210)
1 parent 0204648 commit 5b30ba1

24 files changed

+743
-331
lines changed

aspnetcore/blazor/globalization-localization.md

+2
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ Use the `CultureExample1` component shown in the [Demonstration component](#demo
496496

497497
## Dynamically set the server-side culture by user preference
498498

499+
<!-- UPDATE 8.0 Requires a new approach for BWA apps -->
500+
499501
:::moniker range=">= aspnetcore-8.0"
500502

501503
Examples of locations where an app might store a user's preference include in [browser local storage](https://developer.mozilla.org/docs/Web/API/Window/localStorage) (common for client-side rendering), in a localization cookie or database (common for server-side rendering), or in an external service attached to an external database and accessed by a [web API](xref:blazor/call-web-api).

aspnetcore/blazor/includes/location-client-and-server-net-6-or-later.md

-40
This file was deleted.

aspnetcore/blazor/includes/location-client-and-server-net-7-or-later.md

-26
This file was deleted.

aspnetcore/blazor/includes/location-client-and-server-net-8-or-later.md

-8
This file was deleted.

aspnetcore/blazor/security/content-security-policy.md

+22-20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ uid: blazor/security/content-security-policy
1414

1515
This article explains how to use a [Content Security Policy (CSP)](https://developer.mozilla.org/docs/Web/HTTP/CSP) with ASP.NET Core Blazor apps to help protect against [Cross-Site Scripting (XSS)](xref:security/cross-site-scripting) attacks.
1616

17+
[!INCLUDE[](~/blazor/includes/location-client-and-server-net31-or-later.md)]
18+
1719
[Cross-Site Scripting (XSS)](xref:security/cross-site-scripting) is a security vulnerability where an attacker places one or more malicious client-side scripts into an app's rendered content. A CSP helps protect against XSS attacks by informing the browser of valid:
1820

1921
* Sources for loaded content, including scripts, stylesheets, images, and plugins.
@@ -27,7 +29,7 @@ CSP is supported in most modern desktop and mobile browsers, including Chrome, E
2729

2830
## Policy directives
2931

30-
Minimally, specify the following directives and sources for Blazor apps. Add additional directives and sources as needed. The following directives are used in the *Apply the policy* section of this article, where example security policies for Blazor WebAssembly and Blazor Server are provided:
32+
Minimally, specify the following directives and sources for Blazor apps. Add additional directives and sources as needed. The following directives are used in the *Apply the policy* section of this article, where example security policies for Blazor apps are provided:
3133

3234
:::moniker range=">= aspnetcore-8.0"
3335

@@ -39,10 +41,10 @@ Minimally, specify the following directives and sources for Blazor apps. Add add
3941
* [object-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/object-src): Indicates valid sources for the `<object>`, `<embed>`, and `<applet>` tags. Specify `none` to prevent all URL sources.
4042
* [script-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src): Indicates valid sources for scripts.
4143
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
42-
* In a Blazor WebAssembly app:
43-
* Specify [`wasm-unsafe-eval`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution) to permit the Blazor WebAssembly Mono runtime to function.
44+
* In a client-side Blazor app:
45+
* Specify [`wasm-unsafe-eval`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution) to permit the client-side Blazor Mono runtime to function.
4446
* Specify any additional hashes to permit your required *non-framework scripts* to load.
45-
* In a Blazor Server app, specify hashes to permit required scripts to load.
47+
* In a server-side Blazor app, specify hashes to permit required scripts to load.
4648
* [style-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/style-src): Indicates valid sources for stylesheets.
4749
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
4850
* If the app uses inline styles, specify `unsafe-inline` to allow the use of your inline styles.
@@ -60,10 +62,10 @@ Minimally, specify the following directives and sources for Blazor apps. Add add
6062
* [object-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/object-src): Indicates valid sources for the `<object>`, `<embed>`, and `<applet>` tags. Specify `none` to prevent all URL sources.
6163
* [script-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src): Indicates valid sources for scripts.
6264
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
63-
* In a Blazor WebAssembly app:
64-
* Specify `unsafe-eval` to permit the Blazor WebAssembly Mono runtime to function.
65+
* In a client-side Blazor app:
66+
* Specify `unsafe-eval` to permit the client-side Blazor Mono runtime to function.
6567
* Specify any additional hashes to permit your required *non-framework scripts* to load.
66-
* In a Blazor Server app, specify hashes to permit required scripts to load.
68+
* In a server-side Blazor app, specify hashes to permit required scripts to load.
6769
* [style-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/style-src): Indicates valid sources for stylesheets.
6870
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
6971
* If the app uses inline styles, specify `unsafe-inline` to allow the use of your inline styles.
@@ -82,10 +84,10 @@ Minimally, specify the following directives and sources for Blazor apps. Add add
8284
* [script-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src): Indicates valid sources for scripts.
8385
* Specify the `https://stackpath.bootstrapcdn.com/` host source for Bootstrap scripts.
8486
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
85-
* In a Blazor WebAssembly app:
86-
* Specify `unsafe-eval` to permit the Blazor WebAssembly Mono runtime to function.
87+
* In a client-side Blazor app:
88+
* Specify `unsafe-eval` to permit the client-side Blazor Mono runtime to function.
8789
* Specify any additional hashes to permit your required *non-framework scripts* to load.
88-
* In a Blazor Server app, specify hashes to permit required scripts to load.
90+
* In a server-side Blazor app, specify hashes to permit required scripts to load.
8991
* [style-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/style-src): Indicates valid sources for stylesheets.
9092
* Specify the `https://stackpath.bootstrapcdn.com/` host source for Bootstrap stylesheets.
9193
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
@@ -105,14 +107,14 @@ Minimally, specify the following directives and sources for Blazor apps. Add add
105107
* [script-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src): Indicates valid sources for scripts.
106108
* Specify the `https://stackpath.bootstrapcdn.com/` host source for Bootstrap scripts.
107109
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
108-
* In a Blazor WebAssembly app:
110+
* In a client-side Blazor app:
109111
* Specify hashes to permit required scripts to load.
110112
* Specify `unsafe-eval` to use `eval()` and methods for creating code from strings.
111-
* In a Blazor Server app, specify hashes to permit required scripts to load.
113+
* In a server-side Blazor app, specify hashes to permit required scripts to load.
112114
* [style-src](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/style-src): Indicates valid sources for stylesheets.
113115
* Specify the `https://stackpath.bootstrapcdn.com/` host source for Bootstrap stylesheets.
114116
* Specify `self` to indicate that the app's origin, including the scheme and port number, is a valid source.
115-
* Specify `unsafe-inline` to allow the use of inline styles. The inline declaration is required for the UI in Blazor Server apps for reconnecting the client and server after the initial request. In a future release, inline styling might be removed so that `unsafe-inline` is no longer required.
117+
* Specify `unsafe-inline` to allow the use of inline styles. The inline declaration is required for the UI for reconnecting the client and server after the initial request. In a future release, inline styling might be removed so that `unsafe-inline` is no longer required.
116118
* [upgrade-insecure-requests](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/upgrade-insecure-requests): Indicates that content URLs from insecure (HTTP) sources should be acquired securely over HTTPS.
117119

118120
:::moniker-end
@@ -133,13 +135,13 @@ Use a `<meta>` tag to apply the policy:
133135

134136
* Set the value of the `http-equiv` attribute to `Content-Security-Policy`.
135137
* Place the directives in the `content` attribute value. Separate directives with a semicolon (`;`).
136-
* Always place the `meta` tag in the `<head>` content.
138+
* Always place the `meta` tag in the [`<head>` content](xref:blazor/project-structure#location-of-head-and-body-content).
137139

138-
The following sections show example policies for Blazor WebAssembly and Blazor Server. These examples are versioned with this article for each release of Blazor. To use a version appropriate for your release, select the document version with the **Version** dropdown selector on this webpage.
140+
The following sections show example policies. These examples are versioned with this article for each release of Blazor. To use a version appropriate for your release, select the document version with the **Version** dropdown selector on this webpage.
139141

140-
### Blazor WebAssembly
142+
### Client-side Blazor apps
141143

142-
In the `<head>` content of the `wwwroot/index.html` host page, apply the directives described in the *Policy directives* section:
144+
In the [`<head>` content](xref:blazor/project-structure#location-of-head-and-body-content), apply the directives described in the *Policy directives* section:
143145

144146
:::moniker range=">= aspnetcore-8.0"
145147

@@ -189,7 +191,7 @@ In the `<head>` content of the `wwwroot/index.html` host page, apply the directi
189191
```
190192

191193
> [!NOTE]
192-
> The `sha256-v8v3RKRPmN4odZ1CWM5gw80QKPCCWMcpNeOmimNL2AA=` hash represents the [inline](https://github.com/dotnet/aspnetcore/blob/57501251222b199597b9ac16888f362a69eb13c1/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts#L212) script that's used for Blazor WebAssembly. This may be removed in the future.
194+
> The `sha256-v8v3RKRPmN4odZ1CWM5gw80QKPCCWMcpNeOmimNL2AA=` hash represents the [inline](https://github.com/dotnet/aspnetcore/blob/57501251222b199597b9ac16888f362a69eb13c1/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts#L212) script that's used for client-side Blazor apps. This may be removed in the future.
193195
194196
:::moniker-end
195197

@@ -241,9 +243,9 @@ Add additional `script-src` and `style-src` hashes as required by the app. Durin
241243
242244
The particular script associated with the error is displayed in the console next to the error.
243245

244-
### Blazor Server
246+
### Server-side Blazor apps
245247

246-
In the `<head>` markup ([location of `<head>` content](xref:blazor/project-structure#location-of-head-and-body-content)), apply the directives described in the *Policy directives* section:
248+
In the [`<head>` content](xref:blazor/project-structure#location-of-head-and-body-content), apply the directives described in the *Policy directives* section:
247249

248250
:::moniker range=">= aspnetcore-6.0"
249251

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
**Don't use <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor>/<xref:Microsoft.AspNetCore.Http.HttpContext> directly or indirectly in the Razor components of Blazor Server apps.** Blazor apps run outside of the ASP.NET Core pipeline context. The <xref:Microsoft.AspNetCore.Http.HttpContext> isn't guaranteed to be available within the <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor>, and <xref:Microsoft.AspNetCore.Http.HttpContext> isn't guaranteed to hold the context that started the Blazor app.
1+
**Don't use <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor>/<xref:Microsoft.AspNetCore.Http.HttpContext> directly or indirectly in the Razor components of server-side Blazor apps.** Blazor apps run outside of the ASP.NET Core pipeline context. The <xref:Microsoft.AspNetCore.Http.HttpContext> isn't guaranteed to be available within the <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor>, and <xref:Microsoft.AspNetCore.Http.HttpContext> isn't guaranteed to hold the context that started the Blazor app.
22

3-
The recommended approach for passing request state to the Blazor app is through root component parameters during the app's initial rendering. Alternatively, the app can copy the data into a scoped service in the root component's initialization lifecycle event for use across the app. For more information, see <xref:blazor/security/server/additional-scenarios#pass-tokens-to-a-blazor-server-app>.
3+
The recommended approach for passing request state to the Blazor app is through root component parameters during the app's initial rendering. Alternatively, the app can copy the data into a scoped service in the root component's initialization lifecycle event for use across the app. For more information, see <xref:blazor/security/server/additional-scenarios#pass-tokens-to-a-server-side-blazor-app>.
44

5-
A critical aspect of Blazor Server security is that the user attached to a given circuit might become updated at some point after the Blazor circuit is established but the <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> ***isn't updated***. For more information on addressing this situation with custom services, see <xref:blazor/security/server/additional-scenarios#circuit-handler-to-capture-users-for-custom-services>.
5+
A critical aspect of server-side Blazor security is that the user attached to a given circuit might become updated at some point after the Blazor circuit is established but the <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> ***isn't updated***. For more information on addressing this situation with custom services, see <xref:blazor/security/server/additional-scenarios#circuit-handler-to-capture-users-for-custom-services>.

aspnetcore/blazor/security/includes/shared-state.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Blazor server apps live in server memory, and multiple app sessions are hosted within the same process. For each app session, Blazor starts a circuit with its own dependency injection container scope, thus scoped services are unique per Blazor session.
1+
Server-side Blazor apps live in server memory, and multiple app sessions are hosted within the same process. For each app session, Blazor starts a circuit with its own dependency injection container scope, thus scoped services are unique per Blazor session.
22

33
> [!WARNING]
44
> We don't recommend apps on the same server share state using singleton services unless extreme care is taken, as this can introduce security vulnerabilities, such as leaking user state across circuits.

0 commit comments

Comments
 (0)