Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 8b2704b 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 |
commit: |
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.
Fixes solidjs/solid#5196.
Behind a TLS-terminating proxy, every server function call that the CSRF check protects got a
403from Safari before 16.4. The emittednode.jsentry took the request scheme only fromreq.socket.encrypted, so behind nginxrequest.urlwas alwayshttp://. Browsers that send noSec-Fetch-Sitefall back to theOrigincheck in@solidjs/web, and that check comparesOrigin: https://example.comwithnew URL(request.url).origin, which washttp://example.com.webRequestFromNodenow takes an optionaltrustProxysetting. When the connecting peer is trusted, the scheme comes from the lastX-Forwarded-Protovalue, which is the one the nearest proxy set. Onlyhttpandhttpsare accepted. The emitted entry exposes it ascreateListener({ trustProxy })andserve({ trustProxy }). Its default comes from theTRUST_PROXYenvironment variable, soTRUST_PROXY=loopback node dist/server/node.jsworks without code changes.truetrusts any peer,loopbacktrusts a proxy on the same host, and a comma-separated list trusts those exact peer addresses. The default is off, and the dev and preview middlewares do not change.Only the scheme is taken from the proxy. The host still comes from the
Hostheader, because nginx passes a client'sX-Forwarded-Hostthrough unless it is configured to set it, and trusting that header would let a client choose the host ofrequest.url.The README now covers the proxy case in the Node server section and in "Server-function requests are same-origin protected", as the issue suggested.
Verification
vitest run: 165 tests pass, including newtrustProxyandparseTrustProxycases insrc/http.test.ts.tsc --noEmit -p .is clean.src/node-entry/index.tswith a stub handler that echoesrequest.url. WithX-Forwarded-Proto: httpsandHost: example.com,TRUST_PROXY=loopbackreturnedhttps://example.com/_server, and an unsetTRUST_PROXYreturnedhttp://example.com/_server.This was not tested against a real Safari 14.1 or a real server function.
Left open
An absolute-form request target (
GET https://other.example/x HTTP/1.1) still sets the scheme and host ofrequest.url, becauseparseRequestTargetresolves it withnew URL(target, origin). That was already the case before this change.🤖 Generated with Claude Code