fix(examples): stop sign-in redirecting shoppers to other sites - #641
Merged
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
|
vercel
Bot
had a problem deploying
to
Preview – commerce-essentials
September 30, 2026 14:08
Failure
This branch had an error being deployed
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.
Closes #640.
What was wrong
After sign-in, the example storefronts redirected shoppers to whatever
returnUrlthe login link carried. A link such as/login?returnUrl=https://attacker.exampleshowed 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)insrc/lib/return-url.ts. Its sign-in action now uses it. The function returnsreturnUrlonly 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.exampleand/.//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-authenticationandsimple. The guard matches the one already inexamples/commerce-extensions-saved-list, which was reviewed and fuzz-tested in #539.How it was checked
tsc --noEmitis clean in 10 of the 11 examples.next-account-checkouthas 4 type errors, andmainhas the same 4. None are in the changed files.