Repository navigation
feat(email-code): add an opt-in sign-in link and make the code easier for mail apps to find - #160
Merged
Merged
Conversation
…y signs in the browser that started
entity
approved these changes
Dec 3, 2026
entity
left a comment
Member
There was a problem hiding this comment.
Looks good to me! Left a few comments, none of them blocking :)
…email with sign-in links on
…in button can't be used
…o nested pages render
… the one-button pages right
…arted, not on the link's page
…d the link's host
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.
Summary
Two changes to the email code factor:
The code where mail apps look for it. The
verification_codeemail's first line is nowYour verification code is 48291374: one run of digits beside the word "code", in the HTML and plain-text parts, in place of the code on a line of its own in groups of four. Mail apps that offer to copy a code or fill it in guess from this. None of them promise to, so the docs call it a heuristic and pair it withautocomplete="one-time-code"andinputmode="numeric"on the code field. The subject staysYour verification code: mail providers and apps log subjects, and those logs outlive the code.An opt-in "Sign in" button beside the code, for users who would rather click than type:
It's off by default, and only sign-in emails carry it. Step-up and enrollment emails carry the code alone.
How the link stays safe
Emailed sign-in links have three well-known problems: mail scanners open them, people open them on another device, and a button that signs in wherever it's pressed lets someone with the password get the owner to approve the attacker's sign-in. The design handles each one:
GET /login/challenge/email-code/linkonly renders thesign-in-linkpage. A scanner that follows it signs nobody in and uses nothing up.POST /login/challenge/email-code/link, which isChallengeController::verifyfor the email code factor. So it has the code's own pipeline, throttling, guess limit, single use, events and log entries, and the CSRF check and session lock of any challenge.expiresAtisnull), so the page asks for a new code instead of offering a button that would fail and use up a guess.APP_KEYtogether with the attempt's ID and expiry, plus a marker so no other value Keyring encrypts can pass for one. Nothing about the link is stored: the code's own record decides whether it still works. It works once, for as long as the code and the attempt do, and using the link or typing the code uses up both. It staysCategory::Address, never a factor.404untilwithLink()is on. The page is sent with the headers of Keyring's other emailed-link pages (Referrer-Policy: no-referrer, no caching, a full Inertia page load after posting). A token Keyring didn't make is logged aslink_refusedwithlinksign_in_link.API
EmailCode::withLink(bool $link = true): staticandEmailCode::sendsLinks(): bool.sign-in-linkpage with the propscode,sameBrowser,urlandexpiresAt.codeandurlare only set whensameBrowseris true, andexpiresAtisnullonce the link has ended.keyring.login.linkandkeyring.login.link.store, and theRequireSignInLinksmiddleware that guards both.VerificationCodetakes an optionalurl. It's only passed when there is a link, so an app's own notification isn't handednull.CodeFactor::deliverFor($attempt, $authenticator, $code)is a new hook for sending something that needs the attempt. By default it callsdeliver().EmailCodeonly skipsdeliver()for a sign-in email that carries a link.Upgrading
Your verification code is:should translateYour verification code is :codeinstead. The subject string is unchanged.EmailCodesubclass that overridesdeliver()and turns onwithLink()should overridedeliverFor()too.sign-in-linkpage. The docs have a Vue example, and a Nuxt one for headless frontends.routes/keyring.phpinto their own routes need both new routes, with their names and theRequireSignInLinksmiddleware, before turning the link on.All of these are in
UPGRADE.mdandCHANGELOG.md.Docs
factors.md: Signing In From the Email (including which host the link is built on,APP_URLorlinkRootUsing(), and what that means forwwwor tenant subdomains), and code detection.quick-start.md: a row for the sign-in link. Writing a Code Factor: thedeliverFor()hook.frontend.md: the page,one-time-codeandinputmode.headless.md,sign-in-flow.md,security.mdandsecurity-log-and-emails.md.owasp-asvs.md: rows 6.3.6, 6.5.1, 6.5.5, 6.6.2, 6.6.3, 6.6.4 and 14.2.1, and the NIST AAL2 row.Tests
404with links off.link_refusedfor garbled, foreign and incomplete tokens.deliver()is still used without a link and skipped with one, and an app's ownverification_codenotification without a$urlis still sent and its code signs in.Locally:
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.