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

Adding support for CSP script-src safe inline, for SSR state transfer #2549

Merged
merged 3 commits into from
Jan 10, 2018

Conversation

samuelhorwitz
Copy link

@samuelhorwitz samuelhorwitz commented Jan 10, 2018

VueJS is fully CSP compliant (script-wise) when using runtime-only builds [1].

Nuxt appears to follow suit, with the single exception that a strict locked-down CSP policy should not allow inline scripts. SSR state transfer relies on inline scripts in a non-avoidable way. The CSP spec allows for inline scripts to be whitelisted by nonce or checksum.

There appears to be an issue open on this topic already: #2422

My solution allows a user to opt in to CSP script compliance by setting the options.render.csp variable to either true or an object containing the key hashAlgorithm. The hashAlgorithm may be sha256, sha384 or sha512 per the CSP spec [2] and these three hash algorithms should also be supported in most builds of Node (it is technically dependent on the version of OpenSSL on the platform, but these are three very common algorithms [3]). The default value is sha256 if the user just sets the option to true.

[1] https://vuejs.org/v2/guide/installation.html#CSP-environments
[2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
[3] https://nodejs.org/api/crypto.html#crypto_class_hash

@Atinux Atinux merged commit cd97797 into nuxt:dev Jan 10, 2018
@Atinux
Copy link
Member

Atinux commented Jan 10, 2018

This is awesome, thank you so much!

@samuelhorwitz
Copy link
Author

No problem, thank you for the lib!

@dohomi
Copy link

dohomi commented Apr 23, 2018

Great news! @Atinux is this option available for 1.4 or will it be shipped in v2.?

@Atinux
Copy link
Member

Atinux commented Apr 23, 2018 via email

@dohomi
Copy link

dohomi commented Apr 23, 2018

great to hear, I think its just missing in the docs: https://nuxtjs.org/api/configuration-render

@lock
Copy link

lock bot commented Nov 1, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 1, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants