CSRF check returns 403 to Safari < 16.4 behind an HTTPS proxy
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- Une demi-journée
- Accessibilité débutants
- 55/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- nginx, node.js, typescript
- Domaine
- documentation, security
Piste de recherche
Start with allowsServerFunctionRequest in packages/web/server-functions/src/server.ts, where the Sec-Fetch-Site check is followed by the Origin fallback that compares against new URL(request.url).origin. Then read req.socket.encrypted handling in the plugin's src/http.ts and the 'Server-function requests are same-origin protected' section of the plugin README. Done when the README explains the proxy case, or a request with no Fetch Metadata and an https Origin behind a TLS-terminating proxy is shown to pass or fail as the docs state.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Behind a TLS-terminating proxy, the default same-origin check refuses every server function call from Safari < 16.4
Versions
@solidjs/web 2.0.3 (the check is the same in 2.0.4 and on main), @solidjs/vite-plugin 3.0.1, @solidjs/router 2.0.1
What happens
The app runs as plain HTTP behind nginx, and nginx terminates TLS. This is the setup the plugin README recommends: "the entry speaks plain HTTP — terminate TLS and compress at the reverse proxy or CDN in front of it" (README).
In Safari 14.1, every server function call that the CSRF check protects (form actions, mutations) gets a 403 with an empty body. Chrome, Firefox and Safari 16.4+ work.
Why
allowsServerFunctionRequestadmitsSec-Fetch-Site: same-originright away (server.ts#L4158). Safari sends Fetch Metadata only since 16.4 (MDN), so a request from an older Safari falls through to theOrigincheck (L4179-L4188). The comment there names this case: "No fetch metadata (older WebKit), soOrigindecided."csrf: trueis the default (L700). With nocsrf.originset,Originis compared withnew URL(request.url).origin(L4140-L4141).- Behind the proxy,
request.urlishttp://…. The plugin's Node bridge takes the scheme only fromreq.socket.encrypted(http.ts#L28-L33), and the emittednode.jsentry passes every request through it (node-entry/index.ts#L173). The README describes the same thing: "https:on TLS sockets" (README). The entry has no option to trustX-Forwarded-Proto. Origin: https://example.comdoesn't matchhttp://example.com, so the gate answers403(L4627-L4628). Outside dev, the response has no body (L4330-L4337).
We deploy through nitro. srvx behaves the same way until trustProxy is set: "false (default): ignore the headers; use the real connection protocol". So with srvx the app can fix request.url, while with the plugin's own entry it can only set csrf.origin.
Repro
This works with any Solid 2 app behind an HTTPS proxy.
- Use a real function id: an unknown id gets a
404before the check runs (L4613-L4625). - Pick a function without side effects, because an admitted request runs it.
URL=https://example.com/_server/<function-id>
# No Sec-Fetch-Site, like Safari < 16.4: 403
curl -s -o /dev/null -w "%{http_code}\n" -H 'Origin: https://example.com' -F x=1 "$URL"
# The same request with Fetch Metadata, like Chrome: admitted
curl -s -o /dev/null -w "%{http_code}\n" -H 'Origin: https://example.com' -H 'Sec-Fetch-Site: same-origin' -F x=1 "$URL"
# An http:// Origin is admitted: the server takes its own origin to be http://
curl -s -o /dev/null -w "%{http_code}\n" -H 'Origin: http://example.com' -F x=1 "$URL"
We got 403, 303 and 303. A real Safari 14.1 gets the same 403 when it submits a form.
Why it goes unnoticed
Chrome 76+, Firefox 90+ and Safari 16.4+ send Sec-Fetch-Site (MDN), so the Origin fallback never runs in the browsers that developers usually test with. In production, every form fails for Safari and iOS before 16.4, and all the user sees is an empty 403.
The README presents csrf.origin as the way "to allow another trusted origin" (README), so it isn't obvious that an app behind a proxy has to list its own origin there.
Suggestion
- In the README section "Server-function requests are same-origin protected", note that behind a TLS-terminating proxy the request URL's origin is
http://. Browsers without Fetch Metadata then get403, unless the app setscsrf: { origin: 'https://example.com' }or the server buildsrequest.urlfrom a trustedX-Forwarded-Proto. - Optionally, give the emitted
node.jsentry a trusted-proxy option, like srvx'strustProxy: 'loopback', so thatrequest.urlcarries the public scheme.
Co-Authored-By: Claude Opus 5.5
- Langage dominant
- TypeScript
- Étoiles
- 37k
- Forks
- 1.2k
- Merge moyen
- 8 h 43 min
- PR mergées (30 j)
- 365
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de solidjs/solid
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
Les mainteneurs répondent en général sous 1 jour
-
[2.0.4] Nested `<Errored>`: the outer boundary stays on an error the inner one rethrew, after the next error is one the inner one handlesPeut-être pris @MilindChatrabhuji l’a pris il y a 2 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de solidjs/solid
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 69/100
activepieces/activepieces#17974 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
OHDSI/Data2Evidence#3777 ·
Les mainteneurs répondent en général sous 3 jours
-
bug enhancement
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
AOSSIE-Org/PictoPy#1802 · 2 commentaires ·
Les mainteneurs répondent en général sous 3 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Termix-SSH/Plugin-Snippets#26 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
agent-reported bug from-app needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
nightly-labs/openbot#20504 ·
Les mainteneurs répondent en général sous 1 jour