Skip to content

feat(node-entry): take the request scheme from a trusted proxy - #559

Open
brenelz wants to merge 2 commits into
mainfrom
fix/node-entry-trust-proxy
Open

brenelz wants to merge 2 commits into
mainfrom
fix/node-entry-trust-proxy

Conversation

@brenelz

@brenelz brenelz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Fixes solidjs/solid#5196.

Behind a TLS-terminating proxy, every server function call that the CSRF check protects got a 403 from Safari before 16.4. The emitted node.js entry took the request scheme only from req.socket.encrypted, so behind nginx request.url was always http://. Browsers that send no Sec-Fetch-Site fall back to the Origin check in @solidjs/web, and that check compares Origin: https://example.com with new URL(request.url).origin, which was http://example.com.

webRequestFromNode now takes an optional trustProxy setting. When the connecting peer is trusted, the scheme comes from the last X-Forwarded-Proto value, which is the one the nearest proxy set. Only http and https are accepted. The emitted entry exposes it as createListener({ trustProxy }) and serve({ trustProxy }). Its default comes from the TRUST_PROXY environment variable, so TRUST_PROXY=loopback node dist/server/node.js works without code changes. true trusts any peer, loopback trusts 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 Host header, because nginx passes a client's X-Forwarded-Host through unless it is configured to set it, and trusting that header would let a client choose the host of request.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 new trustProxy and parseTrustProxy cases in src/http.test.ts.
  • tsc --noEmit -p . is clean.
  • I bundled src/node-entry/index.ts with a stub handler that echoes request.url. With X-Forwarded-Proto: https and Host: example.com, TRUST_PROXY=loopback returned https://example.com/_server, and an unset TRUST_PROXY returned http://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 of request.url, because parseRequestTarget resolves it with new URL(target, origin). That was already the case before this change.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b2704b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/vite-plugin Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/vite-plugin@559

commit: 8b2704b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSRF check returns 403 to Safari < 16.4 behind an HTTPS proxy

1 participant