Repository navigation
fix(magic-link): pin the landing page and bind confirm to a fragment code - #614
Merged
Merged
Conversation
…o confirm A requested redirectUri no longer passes on its origin alone. With magic_link_redirect_uris empty, only the /verify-magiclink page on frontend_url or a configured origin is accepted. The link now carries a code in its fragment next to the token in its query. Verify describes the link and never consumes it, and confirm requires the code, so a token leaked through a query string cannot complete a sign-in, even for the attempt that requested the link. Refs #594
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 #594. Part of #603.
What changes
Redirect pinning
A requested
redirectUriis no longer accepted on its origin alone. Withmagic_link_redirect_urisempty, the only accepted value is<origin>/verify-magiclinkforfrontend_urlor a configured origin, matched as an exact string (no query of its own). Oncemagic_link_redirect_urisis set, it is the whole allowlist, as before.The default is
/verify-magiclinkbecause that is the path the API already uses when noredirectUriis sent. Every bundled client (the JS SDK framework packages, the OpenID provider UI, RoxTarget web and mobile) already lands there, so they need no config change. A tenant with a second landing page lists it inmagic_link_redirect_uris.A second value bound to the email
The link is now
<target>?token=<token>#code=<code>. The code is 32 random bytes, stored as a SHA-256 hash in the newmagic_link_tokens.code_hashcolumn. The storedredirect_urldrops the fragment.GET /magic-link/verify/:tokennever consumes the link. It always answers409 confirmation_required, with a newsameDeviceboolean that a client can use to confirm without prompting.POST /magic-link/verify/:token/confirmrequires{ "code": "..." }. The comparison is constant time. A wrong code spends the link, and a link without acode_hash(mailed before this release) is refused.A fragment never reaches a server, a
Refereror an access log, and most analytics leave it out. So a landing page that leaks its query string leaks only the token, which can no longer sign anyone in.This covers the same-device path as well. In the scenario in the issue, the attacker requests the link themselves, so they hold the requesting attempt's ephemeral token, and the old same-device consume on
GETwould have accepted a leaked token from them. Binding only the cross-device confirm would have left that path open.Two alternatives were rejected:
409, where the first open wins. It races with the leak, and mail scanners that run JavaScript would claim the code and break links for real users.GET. The server adapter builds that request in a dedicated handler that drops the query and body, so every adapter would have needed a change. The confirmPOSTis a manifest passthrough that forwards the JSON body in every adapter. The 409 body is also forwarded verbatim, so adapters need no change.Contract change
This affects these routes:
GET /magic-link/verify/:token(no longer consumes, newsameDevicefield),POST /magic-link/verify/:token/confirm(now needs a body), and theredirectUriaccepted byPOST /magic-link. The adapter manifest is unchanged.The break: a client that confirms with an empty body, or that relies on
GETto consume the link, can no longer complete a magic link sign-in once the API is upgraded. Same-device sign-in now shows the confirm screen and then fails with400.Release order, with no lockstep:
codefrom the fragment, send it on confirm, and confirm without prompting whensameDeviceis true. This is safe against older APIs, which ignore the confirm body and still answer200on a same-deviceGET.External delivery callers that build their own URL from
delivery.tokenmust switch todelivery.magicLinkUrl, which now carries the code.Ripple sites:
seamless-auth-js:packages/client/src/client/createSeamlessAuthClient.ts(confirmMagicLinksends{}),packages/client/src/flows/magicLink.ts(readConfirmation,confirmMagicLinkSignIn,finishMagicLinkSignIn), and each framework's verify screen.roxtarget-mobile:src/auth/magicLink.tsandapp/verify-magiclink.tsx.roxtarget-webuses the SDK screens.seamless-auth-server, Go, Python and Rust adapters: no code change. The confirm passthrough forwards the body, and 409 bodies pass through verbatim.Checks
npm run typecheck,npm run lint,npm run format:check,npm run test:run(3452 passed) andnpm run coverage(lines 99.28%, branches 95.82%) all pass.npm run generate:apihas been run. The migration has not been run against a real Postgres here.