Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeromelaban opened this issue Nov 18, 2024 · 8 comments
Open
Assignees
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono os-browser Browser variant of arch-wasm
Milestone

Comments

@jeromelaban
Copy link
Contributor

Description

When running an app using the WasmAppHost, the server forces COOP/COEP:

if (options.WebServerUseCrossOriginPolicy)
{
app.Use((context, next) =>
{
context.Response.Headers.Append("Cross-Origin-Embedder-Policy", "require-corp");
context.Response.Headers.Append("Cross-Origin-Opener-Policy", "same-origin");
return next();
});
}

This causes issues for apps that don't need this particular feature.

Reproduction Steps

Create an browser wasm app, then add a img that references a non-compatible image.

Expected behavior

The image displays when starting the app from VS.

Actual behavior

net::ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep 200 (OK)

Regression?

Not sure.

Known Workarounds

None, since the headers are set unconditionally:

private static WebServerOptions CreateWebServerOptions(string[] urls, string appPath, Func<WebSocket, Task>? onConsoleConnected) => new
(
OnConsoleConnected: onConsoleConnected,
ContentRootPath: Path.GetFullPath(appPath),
WebServerUseCors: true,
WebServerUseCrossOriginPolicy: true,
Urls: urls
);

Configuration

9.0.100

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 18, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 18, 2024
@jeromelaban jeromelaban changed the title WasmAppHost should not force COOP/COEP when not using threading [Wasm] WasmAppHost should not force COOP/COEP when not using threading Nov 18, 2024
@jkotas jkotas added os-browser Browser variant of arch-wasm arch-wasm WebAssembly architecture labels Nov 19, 2024
Copy link
Contributor

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

@jkotas jkotas added area-VM-meta-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 19, 2024
@pavelsavara pavelsavara added this to the 9.0.x milestone Nov 19, 2024
@pavelsavara pavelsavara removed the untriaged New issue has not been triaged by the area owner label Nov 19, 2024
@pavelsavara
Copy link
Member

I guess it creates a problem when your application is also trying to call services on other domains ?

What would be good fix ?

  • CLI option to opt-out or opt-in
  • set COOP to * domain, is that possible ?
  • only use COOP when we know that we are targeting MT, does the host have ability to read MSBuild properties ?

@jeromelaban
Copy link
Contributor Author

I think a CLI option would be best, driven by:

<RunArguments>exec &quot;$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))&quot; --use-staticwebassets --runtime-config &quot;$(_RuntimeConfigJsonPath)&quot; $(WasmHostArguments)</RunArguments>

Allowing COOP to be enabled when threading is used.

@maraf
Copy link
Member

maraf commented Nov 20, 2024

In Blazor's version of DevServer we went with additional arg in RunArguments when WasmEnableThreads=true.
The only problem is when the property is passed to run from cmd, not csproj, like dotnet run -p:WasmEnableThreads=true, because msbuild doesn't evaluate the property correctly. But I believe this is not the common use case here.
We can implement the same pattern here as well.

@maraf maraf changed the title [Wasm] WasmAppHost should not force COOP/COEP when not using threading [browser] WasmAppHost should not force COOP/COEP when not using threading Nov 20, 2024
@premiaware
Copy link

if the solution is to be inserted in the project the line:
<WasmShellEnableThreads>true</WasmShellEnableThreads>

then i think my app will never run on "azure static web app" again and i will have to stay on .net 8 at the moment.

even using these settings in the file staticwebapp.config.json on azure has no effect, and even changing the app settings on azure will not work

    "Cross-Origin-Embedder-Policy": "require-corp",
    "Cross-Origin-Opener-Policy": "same-origin",
    "Cross-Origin-Resource-Policy": "cross-origin"

@maraf
Copy link
Member

maraf commented Nov 20, 2024

@premiaware The other way around. If you need multithreading (not supported yet and enabled by WasmEnableThreads=true), you would need COOP/COEP headers, and you would need to setup them on yous production server.

As of now, the dotnet run server (used only in development), adds these headers even when they are not needed.

@premiaware
Copy link

excuse me, I do not need

<WasmShellEnableThreads>true</WasmShellEnableThreads>.

currently my app in .net 8 works correctly on azure, without WasmShellEnableThreads = true,
but now that i have upgraded to .net 9 it works but not correctly.

unoplatform/uno#18823

Image not work, i must fix the image download from external domain.

@jeromelaban
Copy link
Contributor Author

@premiaware this issue is only about starting the server using dotnet run and from VS. Publishing through Azure Static Apps will not have any effect and the staticwebapp.config.json configuration will be used instead. If you have issues in Static Apps, this is not related to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono os-browser Browser variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

5 participants