[DEV-3703] Improve login redirect safety#2087
Conversation
🦋 Changeset detectedLatest commit: 65bf436 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR aims to harden the post-login redirect flow in the Next.js website by validating redirect targets and preventing unsafe redirections outside the app / outside expected locale scopes.
Changes:
- Added
canRedirectToUrlhelper to validate redirect paths against an allowlist. - Updated the login page to validate the decoded
redirectquery param before callingrouter.replace, with a locale fallback. - Added a changeset entry for the patch release.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| apps/nextjs-website/src/helpers/navigation.helpers.ts | Introduces canRedirectToUrl to validate redirect targets. |
| apps/nextjs-website/src/app/[locale]/auth/login/page.tsx | Uses canRedirectToUrl to gate post-auth redirects and adds locale fallback. |
| .changeset/petite-animals-bake.md | Records the change as a patch release for nextjs-website. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…n-redirect-safety
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Jira Pull Request LinkThis Pull Request refers to the following Jira issue DEV-3703 |
This pull request improves the login redirect logic to enhance security and prevent unsafe URL redirection. The main change is the introduction of a strict validation function for redirect URLs, ensuring users can only be redirected to safe, locale-specific paths within the application.
List of Changes
Login redirect security improvements:
canRedirectToUrlhelper innavigation.helpers.tsthat validates redirect paths to prevent open redirects and restricts redirects to root or supported locale paths only.page.tsxto usecanRedirectToUrlbefore performing a redirect after authentication, falling back to/if the redirect is invalid.canRedirectToUrlhelper in the login page component.Helper improvements:
SUPPORTED_LOCALESto support locale-based redirect validation inauth.helpers.ts.Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: