Skip to content

fix(auth): tighten sign-in "next" redirect to path-only targets - #151

Open
bintest000001-ux wants to merge 1 commit into
zeemscript:mainfrom
bintest000001-ux:fix/signin-next-open-redirect
Open

bintest000001-ux wants to merge 1 commit into
zeemscript:mainfrom
bintest000001-ux:fix/signin-next-open-redirect

Conversation

@bintest000001-ux

Copy link
Copy Markdown

Fixes #68.

What changed

ContributorLogin accepted any next value starting with /, so //example.com (protocol-relative) and /\example.com passed the check and made the sign-in page a possible open redirect.

  • Added src/lib/redirect.ts with safeRedirectTarget(): only same-origin, path-only values are accepted — a single leading / not followed by / or \, and no scheme. Anything else falls back to /explore. The existing /login loop guard is preserved.
  • Wired it into src/pages/auth.tsx (dest calculation).
  • Added src/lib/redirect.test.ts unit tests covering /issue/1 (allowed) and //example.com, /\example.com, https://example.com, javascript:alert(1), /login... (rejected), using Node's native test runner.
  • New test:unit script, run in CI before the build.

Verification

  • npm run test:unit — 7/7 pass
  • npm run build (tsc + vite) — passes

🤖 Generated with Claude Code

Only accept a single leading "/" not followed by "/" or "\" and no scheme
in the sign-in redirect target; anything else falls back to /explore so the
page cannot be used as an open redirect. Adds a unit-tested validator
(node:test) and a test:unit script wired into CI.

Fixes zeemscript#68.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

Tighten validation of the sign-in "next" redirect

1 participant