fix(auth): read the client-facing host, not x-forwarded-host - #74
Merged
Conversation
The per-host redirect_uri landed but had no effect in production: every host still resolved to APP_BASE_URL. requestHost preferred x-forwarded-host. Railway sets that to the canonical service domain rather than the domain the client asked for, so a request to pit.moshcode.sh arrived carrying moshcoding.up.railway.app. That is not on the allowlist, so it fell back -- exactly as designed, just fed the wrong input. `host` is the client-facing name here, which the www -> apex redirect in middleware.ts already depends on and which works on all twelve domains this service answers on. So try `host` first and keep x-forwarded-host as a second candidate for proxies that behave the other way. Trying both is safe because the allowlist, not header precedence, is the security boundary: an attacker forging either header can only select among hostnames we already serve and have already registered with the IdP, and both still fall back to APP_BASE_URL when neither matches. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
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.
Follow-up to #73, which shipped but had no effect in production — every host still resolved to
APP_BASE_URL:Cause
requestHostpreferredx-forwarded-host. Railway sets that to the canonical service domain, not the requested one — so a request topit.moshcode.sharrived carryingmoshcoding.up.railway.app, which isn't allowlisted, so it fell back. The allowlist worked exactly as designed; it was just fed the wrong input.hostis the client-facing name on this platform. Proof: thewww→ apex redirect inmiddleware.ts:26readsreq.headers.get("host")and works on every domain the service answers on:Fix
requestHosts()returns both candidates,hostfirst.resolveOrigin()takes a list and picks the first allowlisted one.Keeping
x-forwarded-hostas a second candidate covers proxies that behave the other way round. Trying both is safe because the allowlist is the security boundary, not header precedence — forging either header only lets an attacker select among hostnames we already serve and have already registered with the IdP, and neither matching still falls back toAPP_BASE_URL.Verification
bun test tests/→ 65 pass, 0 fail (3 new, including the exact Railway header shape that caused this)tsc --noEmit→ cleanbun run build→ clean🤖 Generated with Claude Code