Skip to content

fix(examples): stop sign-in redirecting shoppers to other sites - #641

Merged
field123 merged 1 commit into
mainfrom
fix/open-redirect-after-sign-in
Sep 30, 2026
Merged

field123 merged 1 commit into
mainfrom
fix/open-redirect-after-sign-in

Conversation

@field123

Copy link
Copy Markdown
Collaborator

Closes #640.

What was wrong

After sign-in, the example storefronts redirected shoppers to whatever returnUrl the login link carried. A link such as /login?returnUrl=https://attacker.example showed the real login page, then sent the shopper to another site straight after a real sign-in. That is an open redirect, a common way to make phishing look legitimate.

What changed

Each affected example gets a small safeReturnPath(returnUrl, fallback) in src/lib/return-url.ts. Its sign-in action now uses it. The function returns returnUrl only if it is a path on the same site. Anything else goes to the example's home page.

It also rejects values that start with / but still leave the site, such as //attacker.example and /.//attacker.example. In the second case, the URL parser resolves the dot segment into //attacker.example.

This fixes 12 redirects in 11 examples: core (password and OIDC sign-in), algolia, analytics-integration, commerce-essentials, next-account-checkout, payments, payments-paypal-express, pdf-viewer, recommendations, shopper-accounts-authentication and simple. The guard matches the one already in examples/commerce-extensions-saved-list, which was reviewed and fuzz-tested in #539.

How it was checked

  • 15 unit tests per example, in the 9 examples that have vitest. They cover same-site paths, empty values, and 13 known ways to leave the site. All pass.
  • tsc --noEmit is clean in 10 of the 11 examples. next-account-checkout has 4 type errors, and main has the same 4. None are in the changed files.
  • Not driven in a browser. Doing so needs a store and a signed-in shopper for each example.

…n-in

The sign-in actions redirected to whatever returnUrl the query string
carried, so a link to /login?returnUrl=https://attacker.example sent a
shopper off site straight after a real sign-in. Each example now falls
back to its home page unless returnUrl is a path on the same origin,
including after dot segments resolve (/.//host becomes //host).

Closes #640

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
commerce-essentials Ready Ready Preview Sep 30, 2026 2:07pm UTC
composable-frontend-core Ready Ready Preview Sep 30, 2026 2:07pm UTC
composable-frontend-simple Error Error Sep 30, 2026 2:07pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
composable-frontend-algolia Ignored Ignored Sep 30, 2026 2:07pm UTC
composable-frontend-docs Ignored Ignored Preview Sep 30, 2026 2:07pm UTC
composable-frontend-subscriptions Ignored Ignored Preview Sep 30, 2026 2:07pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2f4b93b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
vercel Bot deployed to Preview – commerce-essentials September 30, 2026 14:06 Active
@vercel
vercel Bot had a problem deploying to Preview – commerce-essentials September 30, 2026 14:08 Failure
@field123
field123 merged commit 930f7d8 into main Sep 30, 2026
9 of 11 checks passed
@field123
field123 deleted the fix/open-redirect-after-sign-in branch September 30, 2026 14:09

This branch had an error being deployed

2 failed and 1 active deployments
Preview – commerce-essentials — 2f4b93b8 Deployed Sep 30, 2026 by vercel[bot] via run-e2e-tests #2075
Preview – composable-frontend-core — 2f4b93b8 Deployed Sep 30, 2026 by vercel[bot]
Preview – composable-frontend-simple — 2f4b93b8 Deployed Sep 30, 2026 by vercel[bot]
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.

Sign-in redirects shoppers to any site named in returnUrl

1 participant