feat(csp): Extend CSP support of SSG mode #272
Merged
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.
Types of changes
Extend CSP support of SSG applications:
Description
This PR extends how we support CSP for SSG applications.
Currently, in SSG mode, Nuxt Security only searches for inline scripts in the
bodyAppend
section of Ntro's html rendering step.With this PR, the following functionalities are added:
Scan all sections of the
html
being rendered by Nitro.This covers the case where scripts or styles are added to the
<head>
tag, or to other parts of the<body>
section.Scan inline styles, and add SHA hashes to the
style-src
policy.This covers the case where, in the absence of the
unsafe-inline
value, CSP requires that inline styles are individually authorized.Scan external script ressources that carry the
integrity
attribute and add SHA hashes to thescript-src
policy.This covers the case where an external ressource is not explicitely whitelisted (or where whitelisting is ignored by the use of
strict-dynamic
).In that case, CSP provides the ability to authorize an external script by its hash, provided this hash is present in its
integrity
attribute.In addition, this PR improves SSG support for hosting providers that can automatically generate headers for static serving via their
nitro: preset
option.<meta http-equiv>
tag. This ensures that, for hosting providers that cannot set HTTP headers, the static CSP policy is still being provided.Note: This PR does not make any change to CSP in SSR mode
Checklist: