Skip to content

[browser] Apply COOP/COEP headers only when threads are enabled#118767

Merged
maraf merged 1 commit intodotnet:mainfrom
maraf:BrowserThreadsOnlyCop
Aug 15, 2025
Merged

[browser] Apply COOP/COEP headers only when threads are enabled#118767
maraf merged 1 commit intodotnet:mainfrom
maraf:BrowserThreadsOnlyCop

Conversation

@maraf
Copy link
Member

@maraf maraf commented Aug 15, 2025

Apply COOP/COEP headers only when WasmEnableThreads=true the same as Blazor's DevServer does.
Originally it was partially blocked by dotnet/sdk#32551, but that is resolved as well.

Fixes #109937

@maraf maraf added this to the 10.0.0 milestone Aug 15, 2025
@maraf maraf self-assigned this Aug 15, 2025
Copilot AI review requested due to automatic review settings August 15, 2025 09:08
@maraf maraf added arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm labels Aug 15, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR conditionally applies Cross-Origin Opener Policy (COOP) and Cross-Origin Embedder Policy (COEP) headers in WebAssembly applications based on the WasmEnableThreads setting. The changes ensure that these security headers, which are required for SharedArrayBuffer support in multi-threaded applications, are only applied when threading is actually enabled.

Key changes:

  • Added a new command-line flag --apply-cop-headers to control COOP/COEP header application
  • Modified build targets to conditionally pass the flag when WasmEnableThreads=true
  • Updated host configuration to respect the new setting when configuring web server options

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/mono/wasm/host/CommonConfiguration.cs Adds ApplyCopHeaders property and --apply-cop-headers command-line option
src/mono/wasm/host/BrowserHost.cs Updates web server configuration methods to use the new COOP/COEP setting conditionally
src/mono/wasm/build/WasmApp.Common.targets Conditionally adds --apply-cop-headers argument when WasmEnableThreads=true
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets Same conditional logic for WebAssembly SDK projects

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

@maraf maraf requested a review from a team August 15, 2025 09:10
@maraf maraf enabled auto-merge (squash) August 15, 2025 13:39
@maraf maraf merged commit 06ac247 into dotnet:main Aug 15, 2025
37 checks passed
@maraf maraf deleted the BrowserThreadsOnlyCop branch August 15, 2025 15:25
@github-actions github-actions bot locked and limited conversation to collaborators Sep 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[browser] WasmAppHost should not force COOP/COEP when not using threading

3 participants