Skip to content

Validate the state query parameter in the /auth callback (fix open redirect) - #619

Open
flipsed wants to merge 2 commits into
vouch:masterfrom
assetnote:state-query-parameter-validation
Open

flipsed wants to merge 2 commits into
vouch:masterfrom
assetnote:state-query-parameter-validation

Conversation

@flipsed

@flipsed flipsed commented Nov 26, 2026 •

Copy link
Copy Markdown

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:

queryState := r.URL.Query().Get("state")
// ...
authStateURL := fmt.Sprintf("%s/auth/%s/?%s", cfg.Cfg.DocumentRoot, queryState, r.URL.RawQuery)
responses.Redirect302(w, r, authStateURL)

A legitimate state is always a random alphanumeric nonce. generateStateNonce in handlers/login.go strips everything outside [a-zA-Z0-9]:

state = regExJustAlphaNum.ReplaceAllString(state, "")

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant