Skip to content

refactor(cspSsrNonce): refactor html injection - #738

Open
GalacticHypernova wants to merge 10 commits into
Baroshem:mainfrom
GalacticHypernova:patch-7
Open

refactor(cspSsrNonce): refactor html injection#738
GalacticHypernova wants to merge 10 commits into
Baroshem:mainfrom
GalacticHypernova:patch-7

Conversation

@GalacticHypernova

@GalacticHypernova GalacticHypernova commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR introduces several changes and fixes issues brought on by #670 and #710 :

  1. It unifies the nonce replacement logic from 3 passes (for each elem type) to a single pass, improving performance on large HTML and unifying nonce overwrite/prepending logic (which also means script and style nonces are now deduped)
  2. It adjusts the nonce pass to accommodate the lack of outer quotes, so it would capture them correctly
  3. Most importantly, it fixes the XSS openings that the previous PR's re-introduced

While I couldn't seem to get a minimal test case to demonstrate it, I did encounter it myself in my own app:
image

Where some of the data in NUXT_DATA has gotten malformed:
image

With these changes, the app loads with no issues

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

@GalacticHypernova is attempting to deploy a commit to the Baroshem's projects Team on Vercel.

A member of the Team first needs to authorize it.

@GalacticHypernova GalacticHypernova changed the title refactor(cspSSrNonce): refactor html injection refactor(cspSsrNonce): refactor html injection Jul 18, 2026
@GalacticHypernova
GalacticHypernova marked this pull request as ready for review July 18, 2026 08:48
@GalacticHypernova
GalacticHypernova marked this pull request as draft July 18, 2026 09:36
@GalacticHypernova
GalacticHypernova marked this pull request as ready for review July 18, 2026 13:13
@GalacticHypernova
GalacticHypernova marked this pull request as draft July 18, 2026 17:11
@GalacticHypernova
GalacticHypernova marked this pull request as ready for review July 19, 2026 04:07
@GalacticHypernova

GalacticHypernova commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

There may be a way to improve the performance of this fix by converting from a negative look-behind to a regular preceding match (negative look-behind is a slower op), which I tried, but I couldn't get it to work on my test case, so due to the urgency of this PR to patch the existing XSS risks I will keep working on it independently and open a new PR when I find the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant