fix: hash finalized public assets for SRI - #756
Open
maximtrp wants to merge 1 commit into
Open
Conversation
|
@maximtrp is attempting to deploy a commit to the Baroshem's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
I moved public asset hashing into the async
#sri-hashesvirtual module factory. Nitro loads this afterrollup:before, so SRI hashes are now calculated from the final asset contents.Previously, nuxt-security generated the manifest in
nitro:build:before. This was too early for modules such as@nuxt/fonts, which creates empty font placeholders first and writes the real font data inrollup:before. Nuxt-security therefore hashed the empty files, and browsers rejected the finished fonts because their integrity values did not match.I noticed this while using
@nuxt/fonts: every generated font preload failed in the browser withFailed to find a valid digest in the 'integrity' attribute. The emitted integrity value started withsha384-OLBgp1Gsljh..., which is the SHA-384 digest of an empty file, rather than the digest of the final.woff2file.This fix also covers other modules that finalize public assets at the same stage.
I added a regression test that creates an empty public asset, replaces it in
rollup:before, and checks that the emitted integrity value matches the final contents.I confirmed that the test fails with the previous implementation, which emits the known empty-file digest (
sha384-OLBgp1Gsljh...).yarn lintyarn test(155 passed, 1 skipped)yarn prepackChecklist: