fix(app-render): HTML-escape bootstrapScriptContent to prevent dev-mode XSS#93733
Open
tomohiro86 wants to merge 1 commit intovercel:canaryfrom
Open
fix(app-render): HTML-escape bootstrapScriptContent to prevent dev-mode XSS#93733tomohiro86 wants to merge 1 commit intovercel:canaryfrom
tomohiro86 wants to merge 1 commit intovercel:canaryfrom
Conversation
The `x-nextjs-request-id` header value was embedded into an inline <script> tag using `JSON.stringify()` alone, which does not escape `</script>`. An attacker with access to the dev server could send a crafted header to break out of the script tag and execute arbitrary JS. The same class of bug was fixed in `stream-ops.node.ts` and `use-flight-response.tsx` in the GHSA security patch (647d923), but the `bootstrapScriptContent` assignment in `app-render.tsx` was missed. Applying `htmlEscapeJsonString()` consistently closes the gap. Only affects the development server (`process.env.__NEXT_DEV_SERVER`); production builds are not impacted.
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.
What?
Applies
htmlEscapeJsonString()to thebootstrapScriptContentinline script generated in development server mode, closing a reflected XSS vector via thex-nextjs-request-idrequest header.Why?
The GHSA security patch (commit
647d923a3f) fixed the same class of bug —JSON.stringify()without HTML escaping in an inline<script>— in two places:packages/next/src/server/app-render/stream-ops.node.ts✅packages/next/src/server/app-render/use-flight-response.tsx✅The
bootstrapScriptContentassignment inapp-render.tsxwas missed:requestIdcomes from thex-nextjs-request-idheader (not inINTERNAL_HEADERS). Sending:produces a broken script tag in the HTML output, allowing arbitrary JS execution. Only the dev server is affected — production builds never reach this branch (
process.env.__NEXT_DEV_SERVERis undefined).Related issue: #93732
How?
A unit test is added at
packages/next/src/server/app-render/bootstrap-script-content.test.tsverifying that a malicious request ID containing</script>is safely escaped and round-trips correctly viaJSON.parse.