Repository navigation
Description
Area
apps/server
Steps to reproduce
- Run T3 Code server (
0.1.11, Desktop-bundled backend listening on127.0.0.1:3773) behind Traefik with TLS termination (for example:https://t3.example.com-> Traefik -> plain HTTP upstream / tunnel ->127.0.0.1:3773). - From a remote T3 Code client on Windows, connect to the environment using
https://t3.example.com/. - Observe the HTTP requests and WebSocket upgrade to
/ws.
Expected behavior
The /ws upgrade request succeeds (101 Switching Protocols) and the remote client establishes a WebSocket connection, matching the behavior of normal HTTPS requests through the same reverse proxy.
Actual behavior
HTTP endpoints succeed, but the WebSocket upgrade fails with 401 and the client displays could not establish a websocket connection:
GET /.well-known/t3/environment->200POST /api/auth/websocket-ticket/rpc->200GET /ws->401(rejected by T3 Code server withenvironment.dpop.failure_code = "url_mismatch")
Root cause
When terminating TLS for a WebSocket upgrade, Traefik forwards X-Forwarded-Proto: wss (while forwarding X-Forwarded-Proto: https for regular HTTP requests).
However, apps/server/src/requestUrl.ts only checks for the exact string "https":
export const requestUrl = (request: HttpServerRequest.HttpServerRequest): Option.Option<URL> =>
HttpServerRequest.toURL(
request.headers["x-forwarded-proto"] === "https" && request.protocol !== "https"
? request.modify({ protocol: "https" })
: request,
);When X-Forwarded-Proto is "wss", requestUrl() falls back to the upstream hop's http protocol and reconstructs http://t3.example.com/ws instead of https://t3.example.com/ws. checkRequestDpopProof() in apps/server/src/auth/dpop.ts then verifies the client's DPoP htu claim (signed for https://t3.example.com/ws) against http://t3.example.com/ws, failing with url_mismatch.
Related PRs
- chore(deps): upgrade Effect to 4.1.2 and alchemy to beta.85 #26833 introduced
apps/server/src/requestUrl.tsto restoreX-Forwarded-Protohandling behind TLS-terminating proxies, but only checked"https". - fix(server): websocket tickets name the route they open #24554 added DPoP proof verification on
/wsRPC upgrades, which explains why minting the ticket at/api/auth/websocket-ticket/rpcsucceeds (200) while the subsequent/wsupgrade fails (401). - feat(server): a server behind a reverse proxy can advertise its https address #33559 tests reverse-proxied origins with a stub proxy that always sends
X-Forwarded-Proto: https, so thewsscase is not covered there either.
Impact
Blocks work completely
Version or commit
0.1.11 (still present on main @ ad1b1f9)
Environment
- Server: macOS 27.2.1, T3 Code (Beta) Desktop 0.1.11 (Node v22.23.2)
- Client: Windows T3 Code client connecting to
https://t3.example.com/ - Reverse proxy: Traefik terminating TLS in front of a plain HTTP upstream to
127.0.0.1:3773
Logs or stack traces
Server trace (server.trace.ndjson, repeated 30 times across connection attempts):
{"name":"dpop.checkRequestDpopProof","status":null,"attributes":{"environment.dpop.failure_code":"url_mismatch"}}Captured headers arriving at 127.0.0.1:3773 for a GET /ws upgrade sent through Traefik over HTTPS:
Host: t3.example.com
X-Forwarded-Proto: wss
After overriding X-Forwarded-Proto to https on /ws in Traefik (no other changes on client or server), the same Windows client immediately connected successfully.
Workaround
Configure a Traefik headers middleware on the /ws route to rewrite X-Forwarded-Proto to https:
http:
middlewares:
t3-ws-proto:
headers:
customRequestHeaders:
X-Forwarded-Proto: "https"
Activity