Repository navigation
feat: add first-class CSP nonce support - #5693
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 86b74fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
quantizor
force-pushed
the
feat/nonce-support
branch
from
March 19, 2026 19:00
40cf8bf to
b5c7867
Compare
quantizor
added a commit
to styled-components/styled-components-website
that referenced
this pull request
Mar 19, 2026
- Add Content Security Policy section to security page with all nonce configuration methods (StyleSheetManager prop, ServerStyleSheet option, meta tag auto-detection, __webpack_nonce__) - Add Next.js App Router CSP nonce guide with middleware + registry example - Add Remix/React Router v7 CSP nonce guide with entry.server.tsx example - Add Vite CSP nonce guide using html.cspNonce auto-detection - Add nonce prop to StyleSheetManager API reference Companion to styled-components/styled-components#5693
quantizor
added a commit
to styled-components/styled-components-website
that referenced
this pull request
Mar 19, 2026
- Add Content Security Policy section to security page with all nonce configuration methods (StyleSheetManager prop, ServerStyleSheet option, meta tag auto-detection, __webpack_nonce__) - Add Next.js App Router CSP nonce guide with middleware + registry example - Add Remix/React Router v7 CSP nonce guide with entry.server.tsx example - Add Vite CSP nonce guide using html.cspNonce auto-detection - Add nonce prop to StyleSheetManager API reference Companion to styled-components/styled-components#5693
quantizor
force-pushed
the
feat/nonce-support
branch
3 times, most recently
from
March 19, 2026 19:19
a37e67f to
dd6af1e
Compare
Add multiple ways to configure a CSP nonce for injected <style> tags: 1. StyleSheetManager nonce prop (recommended for Next.js, Remix) 2. ServerStyleSheet constructor nonce option (SSR) 3. <meta property="csp-nonce"> auto-detection (Vite convention) 4. <meta name="sc-nonce"> auto-detection (SC convention) 5. __webpack_nonce__ global (legacy, preserved for backward compat) The nonce flows through SheetOptions to makeStyleTag, ensuring all dynamically created style elements receive the nonce attribute. Based on PR #4356 by @ericsen-tsai. Closes #4258
quantizor
force-pushed
the
feat/nonce-support
branch
from
March 19, 2026 19:23
dd6af1e to
86b74fd
Compare
quantizor
marked this pull request as ready for review
March 19, 2026 19:26
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.
Summary
Add multiple ways to configure a CSP nonce for injected
<style>tags:<StyleSheetManager nonce="...">new ServerStyleSheet({ nonce: '...' })<meta property="csp-nonce" nonce="..."><meta name="sc-nonce" content="...">__webpack_nonce__Framework integration examples
Next.js App Router:
Vite: Zero-config — set
html.cspNoncein vite.config.js and the<meta property="csp-nonce">tag is auto-detected.Remix: Pass nonce from
entry.server.tsxto<StyleSheetManager nonce={nonce}>.Changes
StyleSheetManager— newnoncepropServerStyleSheet— new{ nonce }constructor optiongetNonce()— auto-detects from<meta property="csp-nonce">(Vite) and<meta name="sc-nonce">; reads.nonceDOM property (notgetAttribute) per browser security modelSheetOptions/makeStyleTag/Tagconstructors — nonce threaded throughBased on #4356 by @ericsen-tsai. Seed commit attributed to the original author.
Test plan
html.cspNonceCloses #4258