Skip to content

Proxy domains when the host includes a port - #8129

Open
adityajai119 wants to merge 1 commit into
coder:mainfrom
adityajai119:fix/domain-proxy-host-port
Open

adityajai119 wants to merge 1 commit into
coder:mainfrom
adityajai119:fix/domain-proxy-host-port

Conversation

@adityajai119

Copy link
Copy Markdown
Contributor

Fixes #8128

Since #6225 (4.14.0), maybeProxy() matches the host from getHost(), which keeps the port, against a proxy domain pattern anchored at the end, such as ^(\d+)\.example\.com$. Before that it dropped the port from the host first, and getCookieDomain() still does. So with --proxy-domain example.com, a request to 3000.example.com:8080, or one forwarded with X-Forwarded-Host: 3000.example.com:443, is not proxied and code-server serves itself instead. #7194 ran into this and worked around it by adding the port to the proxy domain.

This lets the pattern match an optional :port at the end of the host. Proxy domains that already include a port, such as example.com:12345, keep matching as before.

Testing, on Windows 11 with Node 24.22.1:

  • New test in test/unit/node/proxy.test.ts: with --proxy-domain=example.com, a request with the host <port>.example.com and one with <port>.example.com:8443 both reach the app. On main the second one fails (500 from code-server's own routes instead of the proxied 200), and it passes with this change.
  • test/unit/node/proxy.test.ts: 21 passed. test/unit/node/http.test.ts: 138 passed.
  • npx tsc --noEmit -p tsconfig.json, ESLint and Prettier on the changed files.

AI-assisted: drafted with an AI coding agent; the tests above were run locally.

@adityajai119
adityajai119 requested a review from a team as a code owner November 13, 2026 04:55

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

None yet

1 participant