Allow WebSocket origins behind Host-rewriting reverse proxies - #22
Merged
Conversation
The 0.4.0 browser-origin boundary rejects WebSocket upgrades whose Origin host differs from the request host. Reverse proxies that terminate TLS and forward to an internal address rewrite the Host header, so browsers connecting through them were stuck at "Browser disconnected from bridge". Add HERDR_GUI_ALLOWED_ORIGINS / --allowed-origins: a comma-separated list of extra browser origins allowed to open the WebSocket. The same-host rule and all other rejections are unchanged, and forwarded headers are deliberately not trusted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The browser-origin boundary introduced in #18 (released in 0.4.0) accepts WebSocket upgrades only when the request
Originhost matches the request host. Deployments behind reverse proxies that terminate TLS and forward to an internal address rewrite theHostheader, so legitimate browsers are rejected with 403 and the UI sits at "Browser disconnected from bridge". This is a 0.4.0 regression for proxied deployments: HTTP works, the page loads, but the bridge WebSocket never connects.Changes
HERDR_GUI_ALLOWED_ORIGINSenv var /--allowed-originsflag: a comma-separated list of extra browser origins allowed to open the WebSocket. Entries are full origins (scheme://host[:port]); entries without a scheme match bothhttpandhttpson that host.X-Forwarded-Hostetc.) are deliberately not trusted, since browser-supplied requests can set them.Hostheader when possible.Verification
bun run precommit(format, lint, typecheck, 560 tests) green, including new allowlist casesHostand the allowlisted browser origin upgrades (101); an unlisted origin is still rejected (403)Host+ public origin → 403forbidden websocket originwithout the allowlist