Skip to content

fix(server): WebSocket DPoP proofs verify behind proxies that forward wss - #40729

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-40725
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-40725

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Behind a TLS-terminating proxy like Traefik, remote clients could not open the WebSocket connection. Traefik sends X-Forwarded-Proto: wss on the /ws upgrade, and the server only treated https as secure. So it checked the client's DPoP proof, signed for https://, against an http:// URL and rejected it with 401. requestUrl now treats wss as secure as well.

Fixes #40725

Reproduction on main

Commit 11224f6 (origin/main). Ran T3CODE_DEV_SEED=0 node src/bin.ts serve --mode web --host 127.0.0.1 --port 38773 --base-dir <scratch> from apps/server. In front of it ran a Node proxy that imitates Traefik's TLS termination: it rewrites Host to t3.example.com, sends X-Forwarded-Proto: https on normal HTTP requests and wss (or https, as a control) on the WebSocket upgrade. A client driver made a P-256 DPoP key, exchanged a pairing token at POST /oauth/token with a DPoP proof (htu https://t3.example.com/oauth/token), got POST /api/auth/websocket-ticket/rpc, then sent GET /ws?orchestrationProtocol=2&wsTicket=..&dpop=<proof for https://t3.example.com/ws>. With X-Forwarded-Proto: wss: descriptor 200, token 200, ticket 200, /ws 401 {code:auth_invalid, reason:invalid_credential, dpopFailureReason:request_mismatch}, and the server trace recorded environment.dpop.failure_code=url_mismatch. Same flow with X-Forwarded-Proto: https on a fresh pairing token: /ws 101 Switching Protocols. Unit check: HttpServerRequest.fromWeb with x-forwarded-proto wss gives requestUrl http://t3.example.com/ws, while https gives https://. Failing test pushed on factory/repro-40725 (9487506): the wss case fails on main and the https case passes. Accepting 'wss' in requestUrl makes both pass; that fix was discarded and is not on the branch.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • vp test run src/auth/EnvironmentAuth.test.ts -t "TLS proxy forwards" (before fix): 1 failed (wss), 1 passed (https)
  • vp test run src/auth/EnvironmentAuth.test.ts (after fix): 31 passed
  • vp run check:changed: format, lint, knip, typecheck (3 packages) and tests (2 files, 33 tests) all pass

Not in this change

  • requestUrl does not handle comma-separated X-Forwarded-Proto values from proxy chains (e.g. 'https,http') or the standard Forwarded header.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 22, 2026 07:40
Reproduces #40725: X-Forwarded-Proto: wss on the /ws upgrade makes the
server verify the proof against http:// and reject it with url_mismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… wss

Traefik sends X-Forwarded-Proto: wss on WebSocket upgrades. requestUrl only
treated https as secure, so /ws was rebuilt as http:// and the client's DPoP
proof for https:// was rejected with url_mismatch. Treat wss as secure too.

Fixes #40725

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 11224f6 · PR result: 47d6884 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

requestUrl now treats forwarded wss like https when constructing a request URL. A new test covers DPoP-authenticated RPC socket upgrades behind a TLS proxy for both forwarded protocol values.

Changes: Proxy protocol handling

Layer / File(s) Summary
Secure forwarded URL and DPoP test
apps/server/src/requestUrl.ts, apps/server/src/auth/EnvironmentAuth.test.ts
requestUrl changes a non-HTTPS request to HTTPS when x-forwarded-proto is https or wss. The new test checks that socket upgrades authenticate for both values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • pingdotgg/t3code#35824: Changes requestUrl to use the forwarded host and derived protocol when building the request URL.
Merge Risk: Minimal · up to 47d68

Requests forwarded with X-Forwarded-Proto wss are now treated as secure, so WebSocket DPoP proofs for https URLs should match behind TLS-terminating proxies. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the server's WebSocket DPoP verification now works behind proxies that forward wss. The change in requestUrl treats wss as secure, which matches the title. The title…
Description check Passed The description follows the template well. It states the problem with expected behavior and a reproduction on main. It explains the change, links issue #40725, and reports the tests and checks run. It…
Linked Issues check Passed Issue #40725 requires that a /ws upgrade behind a TLS-terminating proxy succeeds when the proxy sends X-Forwarded-Proto: wss. The root cause is that requestUrl() in apps/server/src/requestUrl.ts only …
Out of Scope Changes check Passed All changes are connected to issue #40725. The requestUrl.ts change adds wss to the forwarded-protocol check and restructures the function body to read the header once. The EnvironmentAuth.test.ts cha…
Full details: Title check

Explanation

The title names the main change: the server's WebSocket DPoP verification now works behind proxies that forward wss. The change in requestUrl treats wss as secure, which matches the title. The title uses conventional commit format and is a single sentence of 10 words, though it is slightly long.

Full details: Description check

Explanation

The description follows the template well. It states the problem with expected behavior and a reproduction on main. It explains the change, links issue #40725, and reports the tests and checks run. It lists what is out of scope. The Scope section links the issue but does not restate that it is a bug fix, which is acceptable. The Evidence section says real-app before/after capture is still pending and that this section must be filled before merge. The template asks for a note on what could not be checked, and the description mostly covers that. The description meets the required structure and content, so it passes.

Full details: Linked Issues check

Explanation

Issue #40725 requires that a /ws upgrade behind a TLS-terminating proxy succeeds when the proxy sends X-Forwarded-Proto: wss. The root cause is that requestUrl() in apps/server/src/requestUrl.ts only treated the exact value "https" as secure. At the reviewed head, requestUrl() uses SECURE_FORWARDED_PROTOS = {"https", "wss"}. When the header is in that set and request.protocol is not "https", it rewrites the protocol to https before HttpServerRequest.toURL. The DPoP htu check in checkRequestDpopProof() therefore compares against https://t3.example.com/ws, which matches the client proof. The change adds a regression test in apps/server/src/auth/EnvironmentAuth.test.ts for the wss and https cases. The https behavior is unchanged. The PR description states that the real-app before and after evidence is pending. That evidence is verification, not a coding requirement, so it does not affect this verdict. The issue's middleware workaround is not required.

Full details: Out of Scope Changes check

Explanation

All changes are connected to issue #40725. The requestUrl.ts change adds wss to the forwarded-protocol check and restructures the function body to read the header once. The EnvironmentAuth.test.ts change adds the wss/https regression test for DPoP-authenticated RPC socket upgrades behind TLS proxies. The PR description lists comma-separated X-Forwarded-Proto values and the Forwarded header as excluded. The diff does not change them, so no unrelated change is present.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 11224f6 and 47d6884.

Files selected for processing: 2

  • apps/server/src/auth/EnvironmentAuth.test.ts
  • apps/server/src/requestUrl.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

This branch has not been deployed

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

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WebSocket DPoP validation fails behind Traefik when X-Forwarded-Proto is wss

1 participant