Adding support for CSP script-src safe inline, for SSR state transfer #2549
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 eithertrue
or an object containing the keyhashAlgorithm
. ThehashAlgorithm
may besha256
,sha384
orsha512
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 issha256
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