fix(security): validate redirect parameter to prevent open redirect - #253
Open
ZacLou wants to merge 1 commit into
Open
fix(security): validate redirect parameter to prevent open redirect#253ZacLou wants to merge 1 commit into
ZacLou wants to merge 1 commit into
Conversation
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
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.
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
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.