René's URL Explorer Experiment


Title: Fix origin check with default ports and X-Forwarded-Port by harshbhx · Pull Request #8059 · coder/code-server · GitHub

Open Graph Title: Fix origin check with default ports and X-Forwarded-Port by harshbhx · Pull Request #8059 · coder/code-server

X Title: Fix origin check with default ports and X-Forwarded-Port by harshbhx · Pull Request #8059 · coder/code-server

Description: 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: Origin Proxy config Host code-server sees Result today https://example.com X-Forwarded-Host $host:$server_port example.com:443 ❌ rejected https://example.com:8080 X-Forwarded-Host $host + X-Forwarded-Port $server_port example.com ❌ rejected 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 Default ports are normalized. hostMatchesOrigin() parses the host and treats the origin protocol's default port the same as no port. example.com:443 matches https://example.com, but example.com:80 does not (that's a different origin). X-Forwarded-Port fills in a missing port. When the host comes from X-Forwarded-Host and has no port, the first value of X-Forwarded-Port is appended. A port already in the host wins, and non-numeric values are ignored. No other leniency. A host without a port still doesn't match an origin on :8080, and different ports are still rejected. 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 File Change src/node/http.ts New hostMatchesOrigin() (exact match with default-port normalization) replaces the string comparison. New addForwardedPort(). getHost() gets an optional withForwardedPort flag, used only by authenticateOrigin test/unit/node/http.test.ts New origin cases (default ports, wrong-protocol default port, missing port, IPv6). New x-forwarded-port block, plus a test that getHost() still returns the host without the port Before / After Origin: https://example.com X-Forwarded-Host: example.com:443 before: 403 host "example.com:443" does not match origin "example.com" after: allowed Origin: https://example.com:8080 X-Forwarded-Host: example.com X-Forwarded-Port: 8080 before: 403 host "example.com" does not match origin "example.com:8080" after: allowed Origin: https://example.com:8080 X-Forwarded-Host: example.com (no X-Forwarded-Port) before: 403 after: 403 (unchanged, no port is assumed) How to test ./test/node_modules/.bin/jest --forceExit --coverage=false test/unit/node/http.test.ts Optionally, put code-server behind nginx on a non-default port with: proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; The workbench websocket should connect instead of closing with 1006. Testing done http.test.ts: 127/127 passing. The shared origin cases each run against Host, X-Forwarded-Host and three Forwarded header variants Against main, 15 of the new tests fail (default-port and X-Forwarded-Port cases) Against a looser "ignore the port when the host has none" version, 10 fail, so the stricter behaviour is pinned down too Full unit suite: 409/409 passing prettier --check, eslint and tsc --noEmit clean Not tested behind a real nginx proxy Notes for reviewers trusted-origins matching is unchanged and still runs before this check. Only the first value of a comma-separated X-Forwarded-Port is used, the same way X-Forwarded-Host is handled. Browsers can't set X-Forwarded-Port on a websocket handshake, and the hostname still has to match exactly, so the header can't be used to let a different site through.

Open Graph Description: 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 ex...

X Description: 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 ex...

Opengraph URL: https://github.com/coder/code-server/pull/8059

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8b9cf937-04b3-bd25-5fd8-4403b8256554
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAC36:1D4BD6:5411DA:760418:6B0445A8
html-safe-noncefb1485cbd2fb149961f349af9d37206f2da2d1660e893c0389340ebd5cc3a508
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzM2OjFENEJENjo1NDExREE6NzYwNDE4OjZCMDQ0NUE4IiwidmlzaXRvcl9pZCI6Ijg4Mzg2MjE3ODU4NzM0NjY3OTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb5d5841f7a999e9fe8979e20cb39c06c4eae8e6a35bb75dfc98b052b5a91d46f
hovercard-subject-tagpull_request:4879669652
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/coder/code-server/pull/8059/files
twitter:imagehttps://avatars.githubusercontent.com/u/155092207?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/155092207?s=400&v=4
og:image:altFixes #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 ex...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noned4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/coder/code-server git https://github.com/coder/code-server.git
octolytics-dimension-user_id95932066
octolytics-dimension-user_logincoder
octolytics-dimension-repository_id172953845
octolytics-dimension-repository_nwocoder/code-server
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id172953845
octolytics-dimension-repository_network_root_nwocoder/code-server
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/coder/code-server/pull/8059/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fcode-server%2Fpull%2F8059%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fcode-server%2Fpull%2F8059%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=coder%2Fcode-server
Reloadhttps://github.com/coder/code-server/pull/8059/files
Reloadhttps://github.com/coder/code-server/pull/8059/files
Reloadhttps://github.com/coder/code-server/pull/8059/files
coderhttps://github.com/coder
code-serverhttps://github.com/coder/code-server
Codehttps://github.com/coder/code-server
Issues147 (147)https://github.com/coder/code-server/issues
Pull requests15 (15)https://github.com/coder/code-server/pulls
Discussionshttps://github.com/coder/code-server/discussions
Actionshttps://github.com/coder/code-server/actions
Projectshttps://github.com/coder/code-server/projects
Security and quality3 (3)https://github.com/coder/code-server/security
Insightshttps://github.com/coder/code-server/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fcoder%2Fcode-server%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fcoder%2Fcode-server%2Fissues%2Fnew%2Fchoose
code-asherhttps://github.com/code-asher
coder:mainhttps://github.com/coder/code-server/tree/main
harshbhx:fix/6166-origin-ignore-porthttps://github.com/harshbhx/code-server/tree/fix/6166-origin-ignore-port
Conversation 5 https://github.com/coder/code-server/pull/8059
Commits 1 https://github.com/coder/code-server/pull/8059/commits
Checks 13 https://github.com/coder/code-server/pull/8059/checks
Files changed https://github.com/coder/code-server/pull/8059/files
Please reload this pagehttps://github.com/coder/code-server/pull/8059/files
Fix origin check with default ports and X-Forwarded-Port https://github.com/coder/code-server/pull/8059/files#top
Show all changes 1 commit https://github.com/coder/code-server/pull/8059/files
7e16bbf Normalize default ports and use X-Forwarded-Port in the origin check harshbhx Oct 15, 2026 https://github.com/coder/code-server/pull/8059/commits/7e16bbf939435fe954560dcc0678a4765961e691
Clear filters https://github.com/coder/code-server/pull/8059/files
Please reload this pagehttps://github.com/coder/code-server/pull/8059/files
Please reload this pagehttps://github.com/coder/code-server/pull/8059/files
http.ts https://github.com/coder/code-server/pull/8059/files#diff-75505c590327def24759159fb14d6c70549921bcd413b5a8e0268849b5f5840c
http.test.ts https://github.com/coder/code-server/pull/8059/files#diff-f368e916a5f91c47b514ad3c62befe3561f9392c0f500f8fef49f2e516afe6d7
https://github.com/coder/code-server/blob/main/.github/CODEOWNERS#L1
src/node/http.tshttps://github.com/coder/code-server/pull/8059/files#diff-75505c590327def24759159fb14d6c70549921bcd413b5a8e0268849b5f5840c
View file https://github.com/harshbhx/code-server/blob/7e16bbf939435fe954560dcc0678a4765961e691/src/node/http.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/coder/code-server/pull/8059/{{ revealButtonHref }}
https://github.com/coder/code-server/pull/8059/files#diff-75505c590327def24759159fb14d6c70549921bcd413b5a8e0268849b5f5840c
https://github.com/coder/code-server/pull/8059/files#diff-75505c590327def24759159fb14d6c70549921bcd413b5a8e0268849b5f5840c
code-asherhttps://github.com/code-asher
Oct 27, 2026https://github.com/coder/code-server/pull/8059/files#r4383990635
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/coder/code-server/pull/8059/files
https://github.com/coder/code-server/pull/8059/files#diff-75505c590327def24759159fb14d6c70549921bcd413b5a8e0268849b5f5840c
https://github.com/coder/code-server/pull/8059/files#diff-75505c590327def24759159fb14d6c70549921bcd413b5a8e0268849b5f5840c
https://github.com/coder/code-server/blob/main/.github/CODEOWNERS#L1
test/unit/node/http.test.tshttps://github.com/coder/code-server/pull/8059/files#diff-f368e916a5f91c47b514ad3c62befe3561f9392c0f500f8fef49f2e516afe6d7
View file https://github.com/harshbhx/code-server/blob/7e16bbf939435fe954560dcc0678a4765961e691/test/unit/node/http.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/coder/code-server/pull/8059/{{ revealButtonHref }}
https://github.com/coder/code-server/pull/8059/files#diff-f368e916a5f91c47b514ad3c62befe3561f9392c0f500f8fef49f2e516afe6d7
https://github.com/coder/code-server/pull/8059/files#diff-f368e916a5f91c47b514ad3c62befe3561f9392c0f500f8fef49f2e516afe6d7
https://github.com/coder/code-server/pull/8059/files#diff-f368e916a5f91c47b514ad3c62befe3561f9392c0f500f8fef49f2e516afe6d7
https://github.com/coder/code-server/pull/8059/files#diff-f368e916a5f91c47b514ad3c62befe3561f9392c0f500f8fef49f2e516afe6d7
Please reload this pagehttps://github.com/coder/code-server/pull/8059/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.