Skip to content

Commit bb21ba7

Browse files
committed
Remove automatic nonce-adding to rendered scripts
1 parent dc3ceba commit bb21ba7

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,14 +3042,6 @@ export function pushStartInstance(
30423042
formatContext.noscriptTagInScope,
30433043
);
30443044
case 'script':
3045-
if (responseState.nonce) {
3046-
// add nonce to props, but allow override
3047-
props = {
3048-
nonce: responseState.nonce,
3049-
...props,
3050-
};
3051-
}
3052-
30533045
return enableFloat
30543046
? pushScript(
30553047
target,

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,15 @@ describe('ReactDOMFizzServer', () => {
620620
}
621621
});
622622

623-
it('should render scripts with nonce added', async () => {
623+
it('should not automatically add nonce to rendered scripts', async () => {
624624
CSPnonce = 'R4nd0m';
625625
try {
626626
await act(async () => {
627627
const {pipe} = renderToPipeableStream(
628628
<html>
629629
<body>
630-
<script>{'try { foo() } catch (e) {} ;'}</script>
631-
<script src="foo" async={true} />
630+
<script nonce={CSPnonce}>{'try { foo() } catch (e) {} ;'}</script>
631+
<script nonce={CSPnonce} src="foo" async={true} />
632632
<script src="bar" />
633633
<script src="baz" integrity="qux" async={true} />
634634
<script type="module" src="quux" async={true} />
@@ -654,14 +654,13 @@ describe('ReactDOMFizzServer', () => {
654654
renderOptions.unstable_externalRuntimeSrc,
655655
).map(n => n.outerHTML),
656656
).toEqual([
657-
// async scripts get inserted first in render
658657
`<script nonce="${CSPnonce}" src="foo" async=""></script>`,
659-
`<script nonce="${CSPnonce}" src="baz" integrity="qux" async=""></script>`,
660-
`<script nonce="${CSPnonce}" type="module" src="quux" async=""></script>`,
661-
`<script nonce="${CSPnonce}" type="module" src="corge" async=""></script>`,
662-
`<script nonce="${CSPnonce}" type="module" src="grault" integrity="garply" async=""></script>`,
658+
`<script src="baz" integrity="qux" async=""></script>`,
659+
`<script type="module" src="quux" async=""></script>`,
660+
`<script type="module" src="corge" async=""></script>`,
661+
`<script type="module" src="grault" integrity="garply" async=""></script>`,
663662
`<script nonce="${CSPnonce}">try { foo() } catch (e) {} ;</script>`,
664-
`<script nonce="${CSPnonce}" src="bar"></script>`,
663+
`<script src="bar"></script>`,
665664
]);
666665
} finally {
667666
CSPnonce = null;

0 commit comments

Comments
 (0)