Skip to content

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

Open

Description

@eli-yip

Area

apps/server

Steps to reproduce

  1. Run T3 Code server (0.1.11, Desktop-bundled backend listening on 127.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).
  2. From a remote T3 Code client on Windows, connect to the environment using https://t3.example.com/.
  3. 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 -> 200
  • POST /api/auth/websocket-ticket/rpc -> 200
  • GET /ws -> 401 (rejected by T3 Code server with environment.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

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

  1. added
    bugSomething is broken or behaving incorrectly.
    needs-triageIssue needs maintainer review and initial categorization.
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions