Skip to content

Commit

Permalink
Threats for SSR article (#31063)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Nov 17, 2023
1 parent 0ff13ec commit afe0400
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 24 deletions.
7 changes: 6 additions & 1 deletion .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@
},
{
"source_path": "aspnetcore/security/blazor/server/threat-mitigation.md",
"redirect_url": "/aspnet/core/blazor/security/server/threat-mitigation",
"redirect_url": "/aspnet/core/blazor/security/server/interactive-server-side-rendering",
"redirect_document_id": false
},
{
Expand Down Expand Up @@ -1267,6 +1267,11 @@
"source_path": "aspnetcore/blazor/forms-and-input-components.md",
"redirect_url": "/aspnet/core/blazor/forms/",
"redirect_document_id": false
},
{
"source_path": "aspnetcore/blazor/security/server/threat-mitigation.md",
"redirect_url": "/aspnet/core/blazor/security/server/interactive-server-side-rendering",
"redirect_document_id": false
}
]
}
2 changes: 1 addition & 1 deletion aspnetcore/blazor/components/prerender.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Prerendering guidance is organized in the Blazor documentation by subject matter
* [QuickGrid component sample app](xref:blazor/components/quickgrid#sample-app): The [**QuickGrid for Blazor** sample app](https://aspnet.github.io/quickgridsamples/) is hosted on GitHub Pages. The site loads fast thanks to static prerendering using the community-maintained [`BlazorWasmPrerendering.Build` GitHub project](https://github.com/jsakamoto/BlazorWasmPreRendering.Build).
* [Prerendering when integrating components into Razor Pages and MVC apps](xref:blazor/components/integration)
* Authentication and authorization
* [Server-side threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/threat-mitigation#cross-site-scripting-xss)
* [Server-side threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/interactive-server-side-rendering#cross-site-scripting-xss)
* [Unauthorized content display while prerendering with a custom `AuthenticationStateProvider`](xref:blazor/security/server/index#unauthorized-content-display-while-prerendering-with-a-custom-authenticationstateprovider)
* [WebAssembly prerendering support](xref:blazor/security/webassembly/index#prerendering-support)
<!-- UPDATE 8.0 HOLD LINK FOR WORK AT DESTINATION * [Blazor WebAssembly rendered component authentication with prerendering](xref:blazor/security/webassembly/additional-scenarios#prerendering-with-authentication) -->
Expand Down
8 changes: 4 additions & 4 deletions aspnetcore/blazor/components/prerendering-and-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ To resolve the problem, use ***either*** of the following approaches:
* [Authentication and authorization: General aspects](xref:blazor/security/index#aspnet-core-blazor-authentication-and-authorization)
* [Handle Errors: Prerendering](xref:blazor/fundamentals/handle-errors#prerendering)
* [Host and deploy: Blazor Server](xref:blazor/host-and-deploy/server)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/threat-mitigation#cross-site-scripting-xss)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/interactive-server-side-rendering#cross-site-scripting-xss)
* <xref:Microsoft.AspNetCore.Components.Routing.Router.OnNavigateAsync> is executed *twice* when prerendering: [Handle asynchronous navigation events with `OnNavigateAsync`](xref:blazor/fundamentals/routing#handle-asynchronous-navigation-events-with-onnavigateasync)

:::zone-end
Expand Down Expand Up @@ -1908,7 +1908,7 @@ To resolve the problem, use ***either*** of the following approaches:
* [Authentication and authorization: General aspects](xref:blazor/security/index#aspnet-core-blazor-authentication-and-authorization)
* [Handle Errors: Prerendering](xref:blazor/fundamentals/handle-errors#prerendering)
* [Host and deploy: Blazor Server](xref:blazor/host-and-deploy/server)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/threat-mitigation#cross-site-scripting-xss)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/interactive-server-side-rendering#cross-site-scripting-xss)

:::zone-end

Expand Down Expand Up @@ -2614,7 +2614,7 @@ To resolve the problem, use ***either*** of the following approaches:
* [Authentication and authorization: General aspects](xref:blazor/security/index#aspnet-core-blazor-authentication-and-authorization)
* [Handle Errors: Prerendering](xref:blazor/fundamentals/handle-errors#prerendering)
* [Host and deploy: Blazor Server](xref:blazor/host-and-deploy/server)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/threat-mitigation#cross-site-scripting-xss)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/interactive-server-side-rendering#cross-site-scripting-xss)

:::zone-end

Expand Down Expand Up @@ -3054,7 +3054,7 @@ To resolve the problem, use ***either*** of the following approaches:
* [Authentication and authorization: General aspects](xref:blazor/security/index#aspnet-core-blazor-authentication-and-authorization)
* [Handle Errors: Prerendering](xref:blazor/fundamentals/handle-errors#prerendering)
* [Host and deploy: Blazor Server](xref:blazor/host-and-deploy/server)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/threat-mitigation#cross-site-scripting-xss)
* [Threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/server/interactive-server-side-rendering#cross-site-scripting-xss)

:::zone-end

Expand Down
10 changes: 5 additions & 5 deletions aspnetcore/blazor/fundamentals/signalr.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ services.AddServerSideBlazor().AddHubOptions(options =>
:::moniker-end

> [!WARNING]
> The default value of <xref:Microsoft.AspNetCore.SignalR.HubOptions.MaximumReceiveMessageSize> is 32 KB. Increasing the value may increase the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/threat-mitigation#denial-of-service-dos-attacks).
> The default value of <xref:Microsoft.AspNetCore.SignalR.HubOptions.MaximumReceiveMessageSize> is 32 KB. Increasing the value may increase the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/interactive-server-side-rendering#denial-of-service-dos-attacks).
For information on memory management, see <xref:blazor/host-and-deploy/server#memory-management>.

Expand Down Expand Up @@ -376,7 +376,7 @@ builder.Services.AddRazorComponents().AddInteractiveServerComponents()
.AddHubOptions(options => options.MaximumReceiveMessageSize = 64 * 1024);
```

Increasing the SignalR incoming message size limit comes at the cost of requiring more server resources, and it increases the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/threat-mitigation#denial-of-service-dos-attacks). Additionally, reading a large amount of content in to memory as strings or byte arrays can also result in allocations that work poorly with the garbage collector, resulting in additional performance penalties.
Increasing the SignalR incoming message size limit comes at the cost of requiring more server resources, and it increases the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/interactive-server-side-rendering#denial-of-service-dos-attacks). Additionally, reading a large amount of content in to memory as strings or byte arrays can also result in allocations that work poorly with the garbage collector, resulting in additional performance penalties.

A better option for reading large payloads is to send the content in smaller chunks and process the payload as a <xref:System.IO.Stream>. This can be used when reading large JavaScript (JS) interop JSON payloads or if JS interop data is available as raw bytes. For an example that demonstrates sending large binary payloads in server-side apps that uses techniques similar to the [`InputFile` component](xref:blazor/file-uploads), see the [Binary Submit sample app](https://github.com/aspnet/samples/tree/main/samples/aspnetcore/blazor/BinarySubmit) and the [Blazor `InputLargeTextArea` Component Sample](https://github.com/aspnet/samples/tree/main/samples/aspnetcore/blazor/InputLargeTextArea).

Expand All @@ -395,7 +395,7 @@ builder.Services.AddServerSideBlazor()
.AddHubOptions(options => options.MaximumReceiveMessageSize = 64 * 1024);
```

Increasing the SignalR incoming message size limit comes at the cost of requiring more server resources, and it increases the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/threat-mitigation#denial-of-service-dos-attacks). Additionally, reading a large amount of content in to memory as strings or byte arrays can also result in allocations that work poorly with the garbage collector, resulting in additional performance penalties.
Increasing the SignalR incoming message size limit comes at the cost of requiring more server resources, and it increases the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/interactive-server-side-rendering#denial-of-service-dos-attacks). Additionally, reading a large amount of content in to memory as strings or byte arrays can also result in allocations that work poorly with the garbage collector, resulting in additional performance penalties.

A better option for reading large payloads is to send the content in smaller chunks and process the payload as a <xref:System.IO.Stream>. This can be used when reading large JavaScript (JS) interop JSON payloads or if JS interop data is available as raw bytes. For an example that demonstrates sending large binary payloads in Blazor Server that uses techniques similar to the [`InputFile` component](xref:blazor/file-uploads), see the [Binary Submit sample app](https://github.com/aspnet/samples/tree/main/samples/aspnetcore/blazor/BinarySubmit) and the [Blazor `InputLargeTextArea` Component Sample](https://github.com/aspnet/samples/tree/main/samples/aspnetcore/blazor/InputLargeTextArea).

Expand All @@ -414,7 +414,7 @@ services.AddServerSideBlazor()
.AddHubOptions(options => options.MaximumReceiveMessageSize = 64 * 1024);
```

Increasing the SignalR incoming message size limit comes at the cost of requiring more server resources, and it increases the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/threat-mitigation#denial-of-service-dos-attacks). Additionally, reading a large amount of content in to memory as strings or byte arrays can also result in allocations that work poorly with the garbage collector, resulting in additional performance penalties.
Increasing the SignalR incoming message size limit comes at the cost of requiring more server resources, and it increases the risk of [Denial of Service (DoS) attacks](xref:blazor/security/server/interactive-server-side-rendering#denial-of-service-dos-attacks). Additionally, reading a large amount of content in to memory as strings or byte arrays can also result in allocations that work poorly with the garbage collector, resulting in additional performance penalties.

:::moniker-end

Expand Down Expand Up @@ -1173,7 +1173,7 @@ Use a <xref:Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler> to c
* Server-side security documentation
* <xref:blazor/security/index>
* <xref:blazor/security/server/index>
* <xref:blazor/security/server/threat-mitigation>
* <xref:blazor/security/server/interactive-server-side-rendering>
* <xref:blazor/security/server/additional-scenarios>
* [Server-side reconnection events and component lifecycle events](xref:blazor/components/lifecycle#blazor-server-reconnection-events)
* [What is Azure SignalR Service?](/azure/azure-signalr/signalr-overview)
Expand Down
5 changes: 4 additions & 1 deletion aspnetcore/blazor/host-and-deploy/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ When considering the scalability of a single server (scale up), the memory avail
* Number of active circuits that a server can support.
* UI latency on the client.

For guidance on building secure and scalable server-side Blazor apps, see <xref:blazor/security/server/threat-mitigation>.
For guidance on building secure and scalable server-side Blazor apps, see the following resources:

* <xref:blazor/security/server/static-server-side-rendering>
* <xref:blazor/security/server/interactive-server-side-rendering>

Each circuit uses approximately 250 KB of memory for a minimal *Hello World*-style app. The size of a circuit depends on the app's code and the state maintenance requirements associated with each component. We recommend that you measure resource demands during development for your app and infrastructure, but the following baseline can be a starting point in planning your deployment target: If you expect your app to support 5,000 concurrent users, consider budgeting at least 1.3 GB of server memory to the app (or ~273 KB per user).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If your app must reference content from an external origin, we recommend that yo
* Institute a [Content Security Policy (CSP)](https://developer.mozilla.org/docs/Web/HTTP/CSP).
* Perform [subresource integrity](https://developer.mozilla.org/docs/Web/Security/Subresource_Integrity) checks.

Even if all of the resources are packed into the app and don't load from any external origin, remain cautious about problems in the resources' code that run inside the Web View, as the resources might have vulnerabilities that could allow [cross-site scripting (XSS)](xref:blazor/security/server/threat-mitigation#cross-site-scripting-xss) attacks.
Even if all of the resources are packed into the app and don't load from any external origin, remain cautious about problems in the resources' code that run inside the Web View, as the resources might have vulnerabilities that could allow [cross-site scripting (XSS)](xref:blazor/security/server/interactive-server-side-rendering#cross-site-scripting-xss) attacks.

In general, the Blazor framework protects against XSS by dealing with HTML in safe ways. However, some programming patterns allow Razor components to inject raw HTML into rendered output, such as rendering content from an untrusted source. For example, rendering HTML content directly from a database should be avoided. Additionally, JavaScript libraries used by the app might manipulate HTML in unsafe ways to inadvertently or deliberately render unsafe output.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1850,4 +1850,4 @@ For more information, see <xref:blazor/js-interop/index#javascript-interop-calls
* [Interaction with the DOM](xref:blazor/js-interop/index#interaction-with-the-dom)
* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples)
* <xref:blazor/fundamentals/handle-errors#javascript-interop> (*JavaScript interop* section)
* [Threat mitigation: .NET methods invoked from the browser](xref:blazor/security/server/threat-mitigation#net-methods-invoked-from-the-browser)
* [Threat mitigation: .NET methods invoked from the browser](xref:blazor/security/server/interactive-server-side-rendering#net-methods-invoked-from-the-browser)
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ In the preceding example:

Although a common cause of JS interop failures are network failures with server-side components, per-invocation timeouts can be set for JS interop calls for client-side components. Although no SignalR circuit exists for a client-side component, JS interop calls might fail for other reasons that apply.

For more information on resource exhaustion, see <xref:blazor/security/server/threat-mitigation>.
For more information on resource exhaustion, see <xref:blazor/security/server/interactive-server-side-rendering>.

## Avoid circular object references

Expand Down Expand Up @@ -1813,4 +1813,4 @@ For more information, see <xref:blazor/js-interop/index#javascript-interop-calls
* [`InteropComponent.razor` example (dotnet/AspNetCore GitHub repository `main` branch)](https://github.com/dotnet/AspNetCore/blob/main/src/Components/test/testassets/BasicTestApp/InteropComponent.razor): The `main` branch represents the product unit's current development for the next release of ASP.NET Core. To select the branch for a different release (for example, `release/5.0`), use the **Switch branches or tags** dropdown list to select the branch.
* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples)
* <xref:blazor/fundamentals/handle-errors#javascript-interop> (*JavaScript interop* section)
* [Threat mitigation: JavaScript functions invoked from .NET](xref:blazor/security/server/threat-mitigation#javascript-functions-invoked-from-net)
* [Threat mitigation: JavaScript functions invoked from .NET](xref:blazor/security/server/interactive-server-side-rendering#javascript-functions-invoked-from-net)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: Threat mitigation guidance for server-side ASP.NET Core Blazor
title: Threat mitigation guidance for ASP.NET Core Blazor interactive server-side rendering
author: guardrex
description: Learn how to mitigate security threats to server-side Blazor apps.
description: Learn how to mitigate security threats in interactive server-side Blazor.
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.custom: mvc
ms.date: 11/14/2023
uid: blazor/security/server/threat-mitigation
uid: blazor/security/server/interactive-server-side-rendering
---
# Threat mitigation guidance for server-side ASP.NET Core Blazor
# Threat mitigation guidance for ASP.NET Core Blazor interactive server-side rendering

[!INCLUDE[](~/includes/not-latest-version.md)]

This article explains how to mitigate security threats to server-side Blazor apps.
This article explains how to mitigate security threats in interactive server-side Blazor.

[!INCLUDE[](~/blazor/includes/location-client-and-server-net31-or-later.md)]

Expand Down
Loading

0 comments on commit afe0400

Please sign in to comment.