Skip to content

Harden OAuth callback against CSRF/open-redirect and token-in-URL exposure #9

Closed

Description

@chonilius

Problem

src/app/auth/callback/CallbackClient.tsx handles the return leg of the GitHub OAuth redirect described in the README ("Connect GitHub button redirects to backend's OAuth endpoint"). OAuth callback handlers are a classic CSRF/open-redirect surface: if this client component reads a token or redirect target from URL query parameters without validating a state parameter round-trip, or if it trusts a redirect_to/next query param to send the user onward after login without an allowlist, it's vulnerable to an attacker crafting a link that completes a victim's real OAuth login but then redirects them to an attacker-controlled page (open redirect) or, worse, if state isn't verified, allows a CSRF login fixation where an attacker's OAuth session gets bound to a victim's browser.

Why this is hard

  • You need to actually read CallbackClient.tsx and trace exactly what it does with the URL (query params consumed, what's passed to login() in AuthContext, whether state is checked at all) since none of this is documented, and OAuth state validation might be entirely delegated to the backend (in which case the frontend's job is just to relay it correctly) or might be missing on both ends.
  • Testing this requires constructing realistic malicious callback URLs (missing state, mismatched state, absolute-URL redirect targets, javascript: URIs in a redirect param if one exists) and confirming the app rejects them — this is adversarial testing, not just a code read.
  • If redirect_to support exists (common pattern: "log in, then return to the bounty you were viewing"), it needs a strict allowlist (relative paths only, no protocol-relative //evil.com URLs, which are a frequently-missed open-redirect bypass) — you'll need to check whether Next.js's redirect()/router.push() usage here is vulnerable to protocol-relative URL tricks.
  • The token handoff itself: does the backend put the JWT in the callback URL as a query param (visible in browser history, referrer headers, server logs — bad) or in a way CallbackClient.tsx retrieves more safely? If it's in the URL, that's a separate hardening item to flag/fix (strip it from history via history.replaceState at minimum, and note as a cross-repo issue if the backend should be doing this differently, e.g. a one-time code exchange instead).

Scope

  • Audit CallbackClient.tsx for state parameter validation; add it if missing (client-side check, with backend coordination noted if the state must be verified server-side, i.e. issued and checked by mergefi-backend).
  • Add strict allowlisting for any post-login redirect target (relative-only, reject protocol-relative and absolute URLs).
  • If the JWT arrives via URL query param, strip it from browser history immediately after reading it and flag the pattern as a cross-repo hardening item in the PR description.
  • Add tests for malformed/malicious callback URLs.

Acceptance criteria

  • A callback URL with a missing/mismatched state is rejected with a clear error, not silently logged in.
  • A callback URL with redirect_to=//evil.com or redirect_to=https://evil.com does not redirect off-site.
  • No JWT persists in browser history after the callback completes.

Activity

  1. added
    very hard
    security
    bug
    on Jul 15, 2026
  2. added
    GrantFox OSS
    Maybe Rewarded
    Official Campaign | FWC26
    on Jul 15, 2026
  3. added
    Stellar Wave
    on Aug 25, 2026
  4. thelight08 commented on Aug 25, 2026

    @thelight08

    @thelight08 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I'd be glad to handle this issue. I'll keep the implementation concise, maintainable, and well-documented.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @thelight08 to this issue.

  5. devgodfreytem commented on Aug 25, 2026

    @devgodfreytem
    Contributor

    @devgodfreytem has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello maintainer, i would love to work on this issue.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @devgodfreytem to this issue.

  6. drips-wave commented on Aug 25, 2026

    @drips-wave

    Congratulations, @devgodfreytem! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @devgodfreytem: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  7. drips-wave commented on Aug 25, 2026

    @drips-wave

    This issue has been completed by @devgodfreytem as part of the Stellar Wave Program's 8th Wave 🥳

    😎 @devgodfreytem: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  8. removed
    Stellar Wave
    on Oct 15, 2026
  9. added
    Stellar Wave
    on Oct 15, 2026
  10. removed
    Stellar Wave
    on Oct 15, 2026
  11. added
    Stellar Wave
    on Oct 15, 2026
  12. removed
    Stellar Wave
    on Oct 15, 2026
  13. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26Stellar Wavebugsecurityvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions