Skip to content

fix(magic-link): pin the landing page and bind confirm to a fragment code - #614

Merged
Bccorb merged 2 commits into
mainfrom
fix/magic-link-confirm-binding
Nov 23, 2026
Merged

Bccorb merged 2 commits into
mainfrom
fix/magic-link-confirm-binding

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #594. Part of #603.

What changes

Redirect pinning

A requested redirectUri is no longer accepted on its origin alone. With magic_link_redirect_uris empty, the only accepted value is <origin>/verify-magiclink for frontend_url or a configured origin, matched as an exact string (no query of its own). Once magic_link_redirect_uris is set, it is the whole allowlist, as before.

The default is /verify-magiclink because that is the path the API already uses when no redirectUri is 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 in magic_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 new magic_link_tokens.code_hash column. The stored redirect_url drops the fragment.

  • GET /magic-link/verify/:token never consumes the link. It always answers 409 confirmation_required, with a new sameDevice boolean that a client can use to confirm without prompting.
  • POST /magic-link/verify/:token/confirm requires { "code": "..." }. The comparison is constant time. A wrong code spends the link, and a link without a code_hash (mailed before this release) is refused.

A fragment never reaches a server, a Referer or 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 GET would have accepted a leaked token from them. Binding only the cross-device confirm would have left that path open.

Two alternatives were rejected:

  • A code returned in the first 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.
  • Carrying the code on the 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 confirm POST is 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, new sameDevice field), POST /magic-link/verify/:token/confirm (now needs a body), and the redirectUri accepted by POST /magic-link. The adapter manifest is unchanged.

The break: a client that confirms with an empty body, or that relies on GET to 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 with 400.

Release order, with no lockstep:

  1. Clients read code from the fragment, send it on confirm, and confirm without prompting when sameDevice is true. This is safe against older APIs, which ignore the confirm body and still answer 200 on a same-device GET.
  2. Then this API.

External delivery callers that build their own URL from delivery.token must switch to delivery.magicLinkUrl, which now carries the code.

Ripple sites:

  • seamless-auth-js: packages/client/src/client/createSeamlessAuthClient.ts (confirmMagicLink sends {}), packages/client/src/flows/magicLink.ts (readConfirmation, confirmMagicLinkSignIn, finishMagicLinkSignIn), and each framework's verify screen.
  • roxtarget-mobile: src/auth/magicLink.ts and app/verify-magiclink.tsx. roxtarget-web uses 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) and npm run coverage (lines 99.28%, branches 95.82%) all pass. npm run generate:api has been run. The migration has not been run against a real Postgres here.

…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
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.

fix(magic-link): pin the landing path by default and bind confirm to a user action

1 participant