Skip to content

[DEV-3703] Improve login redirect safety#2087

Merged
marcobottaro merged 17 commits intomainfrom
DEV-3703-improve-login-redirect-safety
Mar 5, 2026
Merged

[DEV-3703] Improve login redirect safety#2087
marcobottaro merged 17 commits intomainfrom
DEV-3703-improve-login-redirect-safety

Conversation

@Sebastiano-Bertolin
Copy link
Copy Markdown
Collaborator

@Sebastiano-Bertolin Sebastiano-Bertolin commented Mar 3, 2026

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:

  • Added a new canRedirectToUrl helper in navigation.helpers.ts that validates redirect paths to prevent open redirects and restricts redirects to root or supported locale paths only.
  • Updated the login page logic in page.tsx to use canRedirectToUrl before performing a redirect after authentication, falling back to / if the redirect is invalid.
  • Imported the new canRedirectToUrl helper in the login page component.

Helper improvements:

  • Added import for SUPPORTED_LOCALES to support locale-based redirect validation in auth.helpers.ts.

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Chore (nothing changes by a user perspective)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 65bf436

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nextjs-website Patch

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 canRedirectToUrl helper to validate redirect paths against an allowlist.
  • Updated the login page to validate the decoded redirect query param before calling router.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.

@marcobottaro marcobottaro self-requested a review March 5, 2026 08:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Jira Pull Request Link

This Pull Request refers to the following Jira issue DEV-3703

@marcobottaro marcobottaro merged commit c1e7565 into main Mar 5, 2026
14 checks passed
@marcobottaro marcobottaro deleted the DEV-3703-improve-login-redirect-safety branch March 5, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants