Skip to content

Conversation

@GalacticHypernova
Copy link
Contributor

@GalacticHypernova GalacticHypernova commented Oct 26, 2025

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

Closes #594
Closes #610
The previous regex implementation, upon further review, had quite a few edge cases. Custom elements, and tags within other elements' props, can cause false modifications, yielding unexpected behavior. This PR fixes the regexes to make them much more robust, fixing said pitfalls. It uses a 2 step approach to mask stringified elements and word-boundaried regex to fix custom elements

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
Copy link

vercel bot commented Oct 26, 2025

@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 fix(cspSsrNonce): element boundaries and full elements fix(cspSsrNonce): element boundaries Oct 26, 2025
@GalacticHypernova GalacticHypernova marked this pull request as ready for review October 27, 2025 23:44
@GalacticHypernova GalacticHypernova changed the title fix(cspSsrNonce): element boundaries fix(cspSsrNonce): more robust tag replacement Oct 27, 2025
@GalacticHypernova
Copy link
Contributor Author

GalacticHypernova commented Oct 27, 2025

Hey @vejja @Baroshem

Sorry for the double mention, but could this be prioritized for a push?

I tried to make a test for the fix (as you can see from the below commits) but I unfortunately failed. If you could assist with writing the test that would be appreciated (it's commented out in the ssr nonce test file)

@GalacticHypernova
Copy link
Contributor Author

This appears to be even more performant than current variation (I'm assuming maybe the word boundary has something to do with that), but we can probably optimize it further. For exanple, we could perhaps quote entire attribute lines as opposed to individual attribute values, which might lead to a moderately smaller internal array, but it is low priority as the current approach is not a bottleneck, so this optimization could be safely pushed separately and should not be a blocker for merging this fix.

@GalacticHypernova
Copy link
Contributor Author

I just pushed a PR to Nuxt Image to remove the insecure nonce prop, hopefully it is merged and allows us to simplify link handling 😅

Copy link
Owner

@Baroshem Baroshem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks!

@vercel
Copy link

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nuxt-security Ready Ready Preview Comment Nov 14, 2025 9:33am

@Baroshem Baroshem changed the base branch from main to chore/2.5.0 November 14, 2025 09:32
@Baroshem Baroshem merged commit 1eba69a into Baroshem:chore/2.5.0 Nov 14, 2025
6 checks passed
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.

Script injection vulnerability in combination with useHead Current cspSsrNonce plugin can result in security problem in some cases

3 participants