fix: accept the { script, style } CSP nonce in handleRequest - #392
Open
everton-dgn wants to merge 1 commit into
Open
everton-dgn wants to merge 1 commit into
everton-dgn wants to merge 1 commit into
Conversation
The generated handler passed `options.nonce` unchanged to the
client-entry transform, whose `escapeAttribute` calls `.replace` on it,
and to `createSSRResponse`, which takes a string, so a `{ script, style }`
nonce threw `TypeError: value.replace is not a function`. Project it with
`scriptNonce` for both, and declare the option in the
`virtual:solid-ssr-handler` types.
🦋 Changeset detectedLatest commit: 970bc19 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 |
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.
Problem
handleRequest(request, { nonce })throws when the nonce is the{ script, style }form of@solidjs/web'sCSPNonce:The generated handler passes
options.nonceunchanged tocreateHtmlChunkTransform, whoseescapeAttributecalls.replaceon it, and tocreateSSRResponse, whosenonceoption is typedstring.@solidjs/webdocuments that its single-script surfaces (HydrationScript,generateHydrationScript,createSSRResponse) take a string and that aCSPNonceis projected withscriptNonce.The option is also missing from the
virtual:solid-ssr-handlertypes, so a typed caller getsTS2353fornoncealthough the handler reads it.This is the bug fix from #389 on its own, so it can land without the
start.noncefeature (#388).Fix
scriptNoncebefore both uses. A string behaves as before, a pair contributes itsscriptvalue, andscript: falseleaves both tags without a nonce.virtual-solid-manifest.d.tsdeclaresnonce?: CSPNonceon thehandleRequestoptions and names the two tags it reaches.What the nonce reaches doesn't change: the generated entry still renders without it, which is #388.
A value outside the type (a number, an object without
script) threw the sameTypeErrorbefore. It now leaves the tags without a nonce, sincescriptNoncereturnsundefinedfor it. #389 rejects such values with an error that names their source.Verification
Four assertions in the prod mode of
examples/start-ssr/test/run.mjs, next to the nonce check from #311. A pair puts its script nonce, never its style one, on the client-entry tag and on the post-flush redirect fallback (/redirect-post).{ script: false, style }leaves both without a nonce. Onnext(e4cdee4) the prod mode ends at 63/67, with the four new checks throwingTypeError: value.replace is not a function. On this branch it passes 67/67.With the fix,
pnpm testinexamples/start-ssrpasses (run.mjs649/649,http-bridge10/10,components-warning11/11,webworker-warning12/12,dedupe8/8), and so doesexamples/start-client(65/65).For the types, a scratch
tscproject overvirtual-solid-manifest.d.tsaccepts a string and both pair shapes and rejects{ script }alone and a number. Againstnext's declarations the three valid calls fail withTS2353.