fix(api): validate OAuth redirect + require non-empty state#24
Merged
ralyodio merged 1 commit intoJul 2, 2026
Merged
Conversation
…leak / login CSRF)
Two bugs in the CoinPay OAuth flow (services/api/src/index.ts):
1. Open redirect / session-token exfiltration (HIGH). The 'redirect' query
param was stored and, after login, the fresh session token was appended to
it (`${redirect}#token=${sess}`) and the browser redirected there — with
no validation. ?redirect=https://evil.com leaks the victim's session token
to an attacker host. Add safeRedirect() (new redirect.ts) that only honors
same-origin absolute URLs or site-relative paths; everything else falls back
to the safe default.
2. OAuth state CSRF (MEDIUM). The callback checked `state !== cookie`, but a
missing cookie AND missing state param both read as undefined, so
`undefined !== undefined` is false and the check was bypassed. Require a
non-empty state that matches the cookie.
Adds redirect.test.ts (same-origin allowed; external / protocol-relative /
javascript: / cross-scheme rejected). Logic verified standalone.
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
Two bugs in the CoinPay OAuth flow (
services/api/src/index.ts), see #23:redirectquery param was stored and, after login, the session token was appended to it and the browser redirected there — unvalidated.?redirect=https://evil.comleaks the victim's session token.state !== cookiepasses when both areundefined(missing cookie + missing state param).Fix
safeRedirect()(newredirect.ts) — only same-origin absolute URLs or site-relative paths are honored; external / protocol-relative /javascript:/ cross-scheme fall back to the default.statematching the cookie.Tests
redirect.test.ts(same-origin allowed; external,//evil.com,javascript:, cross-scheme, empty all rejected). Verified standalone.Fixes #23.