Repository navigation
Conversation
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.
Summary
The /auth callback reflects the attacker-controlled state query parameter into its 302 Location header without validation. A crafted state containing path separators turns the intended same-origin redirect into a scheme-relative redirect to an external origin, i.e. an open redirect. This PR rejects any state that is not a valid nonce before it is used.
The problem
CallbackHandler in handlers/auth.go builds its redirect directly from state:
A legitimate state is always a random alphanumeric nonce. generateStateNonce in handlers/login.go strips everything outside [a-zA-Z0-9]:
So any state containing
/,\,., or percent-encoded separators is, by construction, a value vouch never issued. CallbackHandler doesn't check this, so such a value flows straight into Location.With state=..%2f..%2f%5Cevil.example.com, the path-cleaning collapses the .. segments but keeps the backslash, producing:
Location: /\evil.example.com/?code=...&state=..%2f..%2f%5Cevil.example.com
Browsers treat the backslash as a path separator and resolve /\evil.example.com/ as scheme-relative, navigating to https://evil.example.com/ and carrying the original query string along.
Impact
An unauthenticated attacker can craft a link to the trusted vouch domain that redirects the victim's browser to an attacker-chosen origin, with the original callback query string attached. This is an open-redirect / phishing-amplification primitive: the link's apparent origin is the trusted vouch host.
Severity is likely a medium, not an authentication bypass. The attacker cannot redeem any leaked code: redemption requires the client secret, which is server-side, and vouch's /auth/{state}/ exchange is gated on the state nonce stored in the victim's session cookie. No JWT is minted for the attacker and /validate is unaffected.