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

Đang mở
#5,196 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@brenelz đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #559 của @brenelz — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
nginx, node.js, typescript
Lĩnh vực
documentation, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

  1. allowsServerFunctionRequest admits Sec-Fetch-Site: same-origin right away (server.ts#L4158). Safari sends Fetch Metadata only since 16.4 (MDN), so a request from an older Safari falls through to the Origin check (L4179-L4188). The comment there names this case: "No fetch metadata (older WebKit), so Origin decided."
  2. csrf: true is the default (L700). With no csrf.origin set, Origin is compared with new URL(request.url).origin (L4140-L4141).
  3. Behind the proxy, request.url is http://…. The plugin's Node bridge takes the scheme only from req.socket.encrypted (http.ts#L28-L33), and the emitted node.js entry 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 trust X-Forwarded-Proto.
  4. Origin: https://example.com doesn't match http://example.com, so the gate answers 403 (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 404 before 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 get 403, unless the app sets csrf: { origin: 'https://example.com' } or the server builds request.url from a trusted X-Forwarded-Proto.
  • Optionally, give the emitted node.js entry a trusted-proxy option, like srvx's trustProxy: 'loopback', so that request.url carries the public scheme.

Co-Authored-By: Claude Opus 5.5

Ngôn ngữ chính
TypeScript
Star
37k
Fork
1.2k
Merge trung bình
8 giờ 43 phút
Pull request đã merge (30 ngày)
365

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid

Tất cả issue của solidjs/solid

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.