fix: compute CSP hashes from final HTML in render:response#705
Open
harlan-zw wants to merge 2 commits intoBaroshem:mainfrom
Open
fix: compute CSP hashes from final HTML in render:response#705harlan-zw wants to merge 2 commits intoBaroshem:mainfrom
harlan-zw wants to merge 2 commits intoBaroshem:mainfrom
Conversation
Move SSG CSP hash computation, CSP directive update, and CSP meta tag injection from `render:html` to `render:response`. This ensures hashes reflect the final served HTML regardless of the order that other modules' `render:html` listeners run. Previously the hashes were computed inside `render:html` and relied on `reorderNitroPlugins()` placing security plugins last in the Nitro plugin array so their callbacks registered last. Any module that mutated inline <script>/<style> content in a `render:html` callback that wasn't guaranteed to run before nuxt-security's (for example, a minifier running late in the pipeline) would cause the stored hashes to not match the served content, producing CSP violations. By hashing the finalized `response.body` string in `render:response`, the correctness of CSP hashes no longer depends on plugin registration order. Reported in harlan-zw/nuxt-seo-utils#103.
|
@harlan-zw is attempting to deploy a commit to the Baroshem's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Fix: #699 |
|
@Baroshem Hello, do we need something for a merge ? thanks @harlan-zw ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Description
CSP SSG hashes were computed during
render:html, so any module that mutated inline<script>/<style>content in a laterrender:htmlcallback (e.g. a minifier) produced served content that no longer matched the stored hashes, causing CSP violations.reorderNitroPlugins()dodged this most of the time but left the ordering fragile.This moves hash computation, CSP directive update, and CSP meta injection to
render:response, whereresponse.bodyis the finalized HTML string. Hashes now always match what gets served, regardless of other modules'render:htmlordering.Related: nuxt-seo-utils#103.
Checklist:
A new fixture plugin (
test/fixtures/ssgHashes/server/plugins/transform-inline.ts) collapses whitespace inside inline<script>/<style>tags duringrender:html, modelling a third-party HTML mutator. New parametrized tests intest/ssgHashes.test.tsassert every inline script/style in the served body hashes into both the CSP meta tag and the response header, across 8 routes.