fix(auth): constrain GitHub OAuth return paths - #664
Merged
IvGolovach merged 1 commit intoJun 4, 2026
Conversation
Validation * Validation tier: Tier 3 - auth redirect safety affects security-sensitive runtime behavior. * git diff --check: PASS * git diff --cached --check: PASS * bun x vitest run __tests__/api/githubAuthReturnTo.test.ts: PASS * bun x eslint src/app/api/auth/github/route.ts src/app/api/auth/github/callback/route.ts src/lib/auth/returnTo.ts __tests__/api/githubAuthReturnTo.test.ts: PASS * Ledger: not applicable - not required for selected validation tier/change family. * Version: not applicable - not required for selected validation tier/change family. * Not run: bun x tsc --noEmit --pretty false - project-wide check is blocked by unrelated existing frontend errors outside this diff. Rollback * git revert HEAD
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
returnTovalues before they are stored in the OAuth state cookie.new URL(...)so only same-origin relative app paths are used.Why
The OAuth start route accepted a raw
returnToquery parameter and the callback later concatenated it with the site base URL. Values such as@evil.test/path, absolute URLs, protocol-relative URLs, backslashes, or encoded variants could produce unsafe redirect targets or confusing userinfo-style URLs. OAuth redirects should only return users to safe relative paths inside the app.Diff scope
packages/frontend/src/lib/auth/returnTo.ts: adds a shared sanitizer with a safe/leaderboardfallback.packages/frontend/src/app/api/auth/github/route.ts: stores only sanitizedreturnTovalues in the state cookie.packages/frontend/src/app/api/auth/github/callback/route.ts: sanitizes again at callback time and redirects vianew URL(returnTo, baseUrl).packages/frontend/__tests__/api/githubAuthReturnTo.test.ts: adds route-level regression coverage for safe relative paths and unsafe external/userinfo/backslash/encoded inputs.Branch integrity
maina86e688d620939d2c973c6d5625baa815ea223d7origin/main:0 behind / 1 aheada86e688d620939d2c973c6d5625baa815ea223d7Commit integrity
ac9bbd6 fix(auth): constrain GitHub OAuth return pathsDiff hygiene
git diff --name-status origin/main...HEAD:A packages/frontend/__tests__/api/githubAuthReturnTo.test.ts,M packages/frontend/src/app/api/auth/github/callback/route.ts,M packages/frontend/src/app/api/auth/github/route.ts,A packages/frontend/src/lib/auth/returnTo.tsgit diff --check origin/main...HEAD: PASS, no outputValidation mode and proof
bun x vitest run __tests__/api/githubAuthReturnTo.test.ts: PASS, 15 testsbun x eslint src/app/api/auth/github/route.ts src/app/api/auth/github/callback/route.ts src/lib/auth/returnTo.ts __tests__/api/githubAuthReturnTo.test.ts: PASSCI context confirmation
Runtime safety
/leaderboard.Migration notes
Not applicable — no DB migration changed.
Documentation integrity
Not applicable — no docs, commands, or user-facing option names changed.
Rollback plan
Rollback: revert this PR.
DB downgrade: not applicable.
Data repair: not applicable.
Operational caveats: none known.
Known residual risks
Summary by cubic
Sanitized GitHub OAuth
returnTovalues to prevent open redirects. Only same‑origin relative paths are allowed; unsafe inputs fall back to/leaderboard.sanitizeAuthReturnTowith a safe/leaderboarddefault inpackages/frontend/src/lib/auth/returnTo.ts.returnTo; callback re-sanitizes and redirects vianew URL(returnTo, baseUrl).packages/frontend/__tests__/api/githubAuthReturnTo.test.ts.Written for commit ac9bbd6. Summary will update on new commits.