| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The origin check compared the host header to the origin's host as plain strings, so `example.com:443` did not match `https://example.com`, and a proxy forwarding `$host` (no port) together with X-Forwarded-Port failed on any non-default port. Default ports (80 for http, 443 for https) are now treated as no port, and when X-Forwarded-Host has no port the port from X-Forwarded-Port is used. Everything else is still an exact match. getHost() is unchanged for the domain proxy. Fixes coder#6166
|
Hi @code-asher, this implements the approach you agreed to in #6166: default ports are treated as no port, and X-Forwarded-Port fills in the port when X-Forwarded-Host has none. All checks are green. Could you take a look when you have a moment? Thanks! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #6166
Summary
The origin check now treats a default port (:443 for https, :80 for http) as no port, and uses X-Forwarded-Port when X-Forwarded-Host has no port. Everything else is still an exact match. This is the approach agreed in the issue discussion.
Problem
authenticateOrigin compares the forwarded host to the origin's host as plain strings (src/node/http.ts#L406). Two reverse-proxy setups fail that comparison even though the request is same-origin, and the websocket then closes with 1006:
In the second case nginx's $host drops the port and sends it separately in X-Forwarded-Port, but code-server never reads that header. This is the standard config @smerschjohann suggested in the issue, so it should just work.
Solution
The host is parsed with a non-special URL scheme (host://…), which keeps the port exactly as written (special schemes drop default ports) and handles bracketed IPv6 such as [::1]:8080.
X-Forwarded-Port is only applied for the origin check (getHost(req, true)). getHost(req) is unchanged because the domain proxy matches its result against an anchored regex (code-{{port}}.example.com), and an appended port would break that.
I didn't use X-Forwarded-Port with the Host or Forwarded headers, to keep the change to what was discussed. Forwarded can already carry the port in host=.
Changes
Before / After
How to test
Testing done
Notes for reviewers