question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No Content Security Policy is compatible with Blazor WASM .Net 5.0 and Chrome 89.0

See original GitHub issue

Describe the bug

I have found with Chrome 89.0 it appears impossible to use a Content Security Policy with Blazor WASM. It appears the way it is invoked via eval violates any possible Chrome 89.0 CSP policy. For my Blazor WASM app Chrome warns if I don’t add wasm-eval Chrome won’t run the WASM code. But if it add wasm-eval and/or wasm-unsafe-eval (in addition to unsafe-eval) Chrome say is will both ignore all those and still won’t run WASM because no wasm-eval 🤣

With script-src 'self' 'wasm-eval' 'wasm-unsafe-eval' 'unsafe-eval' 'unsafe-inline' the CSP is basically a no-op policy at this point yet it still can’t support WASM.

image

While this appears to be a Chrome Browser issue, it also appears to be triggered by the way the WASM code is invoked by the loader. More discussion here:

https://github.com/WebAssembly/content-security-policy/issues/7

To Reproduce

Publish a Blazor WASM application with Content Security Policy HTTP header. Add everything possible to script-src and note that Blazor WASM loader still violates the CSP.

Exceptions (if any)

image

Further technical details

  • ASP.NET Core version 5.0.201
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version: Visual Studio 2019

.NET SDK (reflecting any global.json): Version: 5.0.201 Commit: a09bd5c86c

Runtime Environment: OS Name: ubuntu OS Version: 18.04 OS Platform: Linux RID: ubuntu.18.04-x64 Base Path: /usr/share/dotnet/sdk/5.0.201/

Host (useful for support): Version: 5.0.4 Commit: f27d337295

.NET SDKs installed: 3.1.404 [/usr/share/dotnet/sdk] 5.0.201 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mkArtakMSFTcommented, Mar 25, 2021

Thanks for contacting us. This seems to be a WebAssembly issue on Chrome. It’s tracked at https://github.com/WebAssembly/content-security-policy/issues/7

0reactions
whereisaaroncommented, Mar 27, 2021

@coderanger you correct; the error you get in CSP ‘report-only’ mode is bogus - ignore it. The ‘issue’ you get in CSP enforcing mode it also bogus, ignore that too. See https://github.com/WebAssembly/content-security-policy/issues/7 for the full detail and screen shots. The script-src unsafe-eval does work to enable WebAssembly for Chrome same as other browsers, despite what the errors/issues say 😄. Thanks for the 2018 bug reference, that looks like exactly my experience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enforce a Content Security Policy for ASP.NET Core Blazor
Learn how to use a Content Security Policy (CSP) with ASP.NET Core Blazor apps to help protect against Cross-Site Scripting (XSS) attacks.
Read more >
Content Security Policy | Blazor
A Content Security Policy (CSP) is a built-in browser mechanism that helps you to prevent certain types of attacks on your web application, ......
Read more >
Content Security Policy blocks 'eval' in Blazor Wasm ...
When hosting a Blazor WebAssembly project under NGINX I get the following warning in Chrome Dev console under "Issues" tab: Content Security ......
Read more >
CSP in Blazor and Blazor WASM
«Content Security Policy in Blazor and Blazor WASM WebAssembly, violation reporting in Blazor; WASM requires 'unsafe-eval', what is 'unsafe-wasm', 'wasm-eval', ...
Read more >
Content Security Policy - Radzen.Blazor Components
Learn how to use a Content Security Policy (CSP) with ASP.NET Core Blazor apps to help protect against Cross-Site Scripting (XSS) attacks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found