Skip to content

fix: validate next redirect param to prevent open redirect vulnerability (#827) - #853

Merged
jakharmonika364 merged 2 commits into
Coder-s-OG-s:mainfrom
namann5:fix/827-open-redirect
Aug 1, 2026
Merged

fix: validate next redirect param to prevent open redirect vulnerability (#827)#853
jakharmonika364 merged 2 commits into
Coder-s-OG-s:mainfrom
namann5:fix/827-open-redirect

Conversation

@namann5

@namann5 namann5 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #827 — the OAuth callback handler used the
ext\ query parameter directly as the redirect path without validation, enabling an open redirect attack.

Vulnerability

An attacker could craft a URL like \https://coders-ogs.xyz/api/auth/callback?code=<valid_code>&next=https://evil.com/phishing\ to silently redirect users to an attacker-controlled domain after OAuth completes.

Fix

Validate that
ext\ is a safe relative path:

  • Reject paths that don't start with /\
  • Reject protocol-relative URLs (//evil.com)
  • Reject URLs containing ://\
  • Fall back to /dashboard\ for unsafe values

Changes

  • \src/app/api/auth/callback/route.ts: Validate
    ext\ param before using it as the redirect path

Closes #827

@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@namann5 is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel.

A member of the Team first needs to authorize it.

@jakharmonika364 jakharmonika364 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good defensive check, and it matches the issue's suggested fix.

One thing worth knowing before treating this as fixing a live "critical" vuln: url.pathname = next (both before and after this PR) can't actually produce a cross-origin redirect - I tested it against Next.js's actual NextURL implementation, which delegates straight to the WHATWG URL.pathnam setter, and that setter is spec-confined to path parsing, so it can never re-introduce a scheme/host. next=https://evil.com ends up as coders-ogs.xyz/https://evil.com, not a redirect off-site. Still worth merging as defense-in-depth (protects us if this ever gets refactored to redirect(next) or url.href = next), but the severity in #827 is overstated for the current code.

Could you add a couple of unit tests for the new branch (next=https://evil.com, next=//evil.com, next=/settings) since there's no test file for this route yet?

@jakharmonika364 jakharmonika364 added the Needs author reply Author need to reply label Jul 31, 2026
@namann5

namann5 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@jakharmonika364 thanks for the detail on NextURL — good to know the current code can't actually redirect off-site. Agreed it's defense-in-depth; I've kept the validation as-is.

Added the requested unit tests in 691ee27 (new src/app/api/auth/callback/route.test.ts, 3 tests):

ext=/settings → redirects to /settings

ext=https://evil.com/phishing → falls back to /dashboard

ext=//evil.com/phishing → falls back to /dashboard
All pass, lint clean.

@jakharmonika364 jakharmonika364 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@jakharmonika364 jakharmonika364 added level:advanced Advanced level difficulty quality:clean Clean, well-structured contribution type:bug Bug fix gssoc:approved Approved by GSSOC admin SSoC26 Hard ECSoC26 ECSoC26-L2 Medium good-pr and removed Needs author reply Author need to reply labels Aug 1, 2026
@jakharmonika364
jakharmonika364 merged commit 7570a4d into Coder-s-OG-s:main Aug 1, 2026
2 of 3 checks passed
@ecsoc-sentinel ecsoc-sentinel Bot added ECSoC26-L2 Medium and removed ECSoC26-L2 Medium labels Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ECSoC26-L2 Medium ECSoC26 good-pr gssoc:approved Approved by GSSOC admin Hard level:advanced Advanced level difficulty quality:clean Clean, well-structured contribution SSoC26 type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRITICAL: Open Redirect in OAuth callback allows session hijacking

2 participants