Skip to content

fix(security): validate redirect parameter to prevent open redirect - #253

Open
ZacLou wants to merge 1 commit into
NovaCoreLabs1:mainfrom
ZacLou:fix-open-redirect
Open

fix(security): validate redirect parameter to prevent open redirect#253
ZacLou wants to merge 1 commit into
NovaCoreLabs1:mainfrom
ZacLou:fix-open-redirect

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown

Fixes #234

Problem

Both login entry points forwarded the user to whatever ?redirect= contains, with no validation. Next.js router.push with an absolute http(s) URL performs a full browser navigation to that origin, and //evil.com bypasses naive checks.

Fix

  • Added sanitizeRedirect helper in frontend/lib/utils.ts that accepts only same-origin, single-/ prefixed paths and rejects absolute URLs, protocol-relative URLs, and javascript:/data: payloads.
  • Applied sanitizeRedirect in all three redirect consumers: use-login.ts, useLoginUser.ts, and admin/sso/login/page.tsx.
  • Added frontend/lib/utils.test.ts with unit tests covering: /dashboard accepted, https://evil.com rejected, //evil.com rejected, javascript: rejected, /dashboard accepted.

Note on 2FA tempToken

The issue description also mentions tempToken being passed in the URL query string. This PR focuses on the open-redirect fix; the tempToken hardening can be addressed in a follow-up if needed.

Adds a sanitizeRedirect helper that accepts only same-origin,
single-/ prefixed paths and rejects absolute URLs, protocol-relative
URLs, and javascript: / data: payloads.

Modified files:
- frontend/lib/utils.ts — added sanitizeRedirect helper
- frontend/lib/utils.test.ts — unit tests for the helper
- frontend/hooks/use-login.ts — uses sanitizeRedirect
- frontend/lib/react-query/hooks/auth/useLoginUser.ts — uses sanitizeRedirect
- frontend/app/admin/sso/login/page.tsx — uses sanitizeRedirect

Fixes NovaCoreLabs1#234
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.

Login redirect parameter is an open redirect: router.push trusts unvalidated query input

1 participant