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

Trunk should not generate nonces in static HTML assets #853

Open
rjmac opened this issue Aug 18, 2024 · 3 comments
Open

Trunk should not generate nonces in static HTML assets #853

rjmac opened this issue Aug 18, 2024 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed need info Further information is requested

Comments

@rjmac
Copy link

rjmac commented Aug 18, 2024

In 0.20.2, Trunk started baking nonce attributes into the HTML files that it generates, but the security of nonces requires that they not be re-used across multiple requests. If CSP functionality is desired, Trunk should instead generate the sha256/384/512 hashes of the contents of those tags and put them someplace those hashes can be includes in the header.

(Note the insecure nature of the static nonce only matters if the html is served with a csp header that allows that nonce. If it's not then the nonce is irrelevant, but it's better not to encourage insecure practices.)

@ctron ctron added bug Something isn't working help wanted Extra attention is needed need info Further information is requested labels Aug 26, 2024
@Jelmerta
Copy link

I find this a bit annoying as well as I generate nonces for every request in nginx and now I have to remove the nonce provided by trunk from my html (which is not trivial). Wonder if this helps anyone as indeed the result of trunk is a static html.

@Jelmerta
Copy link

Jelmerta commented Sep 28, 2024

Additionally, trunk seems to generate code that leads to unsafe-eval with CSP header:
mycode_bin.js:258 Uncaught CompileError: WebAssembly.instantiateStreaming(): Refused to compile or instantiate WebAssembly module because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'nonce-blabla'"

I'm using version 0.21.0-rc.4

Is that desired behaviour? I guess I should just add 'wasm-unsafe-eval' to CSP header?

@ctron
Copy link
Collaborator

ctron commented Sep 30, 2024

It would be great if someone could come up with a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed need info Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants