You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Single Sign-On
A SingleSignOn factor signs users in with identity providers, with no other package: Google, Microsoft (any tenant, organisations, personal accounts, or one tenant), GitHub, and any OpenID Connect provider through discovery. Configure them under the new sso config section, and register drivers of your own with Keyring::sso()->extend(). See Single Sign-On, and More Identity Providers for the config of eight more OpenID Connect providers and drivers for Discord, Bitbucket, Facebook, and LinkedIn.
GET /auth/{provider}/redirect (keyring.sso.redirect) sends a guest to the provider, and GET /auth/{provider}/callback (keyring.sso.callback) is the one URL each provider sends users back to, for signing in, for linking and for confirming. They're only registered when sso.providers lists a provider, and answer 404 until the factor is registered. The callback only finishes Keyring's own sign ins, links and confirms, and a guest's draws on the keyring-login-options rate limiter. The login page gets a providers prop with each provider's name, label and url. A provider that can't be built, such as one missing its client_id, one whose name holds more than letters, digits, - and _, or one whose scopes, parameters or token_endpoint_auth_method isn't something it can take, is reported and left off the page rather than failing it. A callback whose request has expired, while someone is signed in, fails straight away rather than as a link, without asking for a fresh verification or logging a refused link: a confirm goes back to the confirm page with expired, even once the confirm itself has run out, and a link back to the page it was started from with enrollment_expired. One whose request this browser doesn't have at all goes back to the confirm page with expired while a confirm is in progress, and home otherwise.
A sign in with a provider goes through the same pipeline as the login form, so rate limits, the policy and risk apply, and a user with a second factor is still asked for it. It counts as a knowledge factor, like the password, and is never offered on the challenge page.
A sign in, or a new link, with a provider whose freshness is reauthenticate counts toward keyring.fresh from its auth_time, which Keyring asks for where the provider takes the claims parameter, so one the provider let straight through on an old session isn't a fresh verification, and one without auth_time never is. With never it never counts. Its session and assurance level still start when the user came back either way. Only a provider opted into round_trip counts from when the user came back, whatever auth_time it sends. Verification has a new authenticatedAt, with Verification::UNKNOWN for a provider that didn't say when, provedAt() gives the earlier of the two, and SessionAssurance::provedSince() is what freshness reads. SignIn::enrolled() takes the Verification adding a method proved.
A link confirms a step-up: the confirm page offers it, with the new GET /confirm/sso/redirect (keyring.sso.confirm) in its challenge as url, which sends the user back to the provider with the link's address as login_hint. A provider whose freshness is reauthenticate is sent max_age=0, with prompt=login where it takes it (not at Google, and in place of max_age at Microsoft), and the confirm needs an auth_time no earlier than when the user was sent there, give or take a minute. One opted into round_trip gets a plain round trip, which counts as much as signing in with it again does. One that's never gets a plain round trip too, which counts toward the session's level, as signing in again would, and never toward keyring.fresh, so it's only offered toward a level, such as after AAL2 lapses. keyring.fresh only asks for what can be proved recently, so a user with a never link and a second factor, and no password, confirms with the second factor alone, and one who can't confirm at all gets enroll-first straight away. The round trip never sets Laravel's auth.password_confirmed_at, and a visit to /confirm of the user's own, where password.confirm sends them, only offers what can be proved recently, so a user still signed in to GitHub doesn't pass password.confirm without typing anything. StepUp::unlessMet() and meets() with both a level and a moment ask for them in turn, the level first, when the account can't freshly prove the level, so a user with a never link and an authenticator app, and no password, isn't sent to enroll. A recovery code isn't offered on a fresh verification that only the link could finish beside it. The callback only confirms the same account, for the user and the confirm that started it, and goes through the confirm page's pipeline, so rate limits and events apply as they do there. IdentityProvider has a new supportsReauthentication(), saying whether the provider can be asked, and freshness(), Keyring::sso()->start() takes a maxAge and a loginHint, AuthorizationRequest keeps when it was made (createdAt), and complete() refuses an identity without a recent enough authTime with the new SsoFailure::StaleAuthentication.
A user held for a new password can confirm with a link too: the hold lets through keyring.sso.confirm, and the provider's callback for a confirm, though not its callback for a new link. A confirm's callback that comes back late, or is used up while the confirm is still in progress, fails as it would without a hold.
A provider's freshness option, a Keyring\Enums\SsoFreshness, says how much its sign ins and confirms count toward keyring.fresh: reauthenticate, round_trip, or never (or false). The defaults are the most secure each driver can give: reauthenticate for oidc, which asks for auth_time with the claims parameter where discovery says it's taken, and for microsoft, which needs the auth_time optional claim added to the app registration (without it no sign in is fresh, and a confirm fails with a reported StaleAuthentication that says what to add), and never for google, github, and drivers built on OAuth2Provider. round_trip is only ever an opt-in. reauthenticate throws an InvalidArgumentException for a provider that can't be asked, such as GitHub. When a link's provider and the one a sign in came through differ, the stricter counts, so renaming or removing a provider never makes a sign in count for more. A link only takes the name of the provider a sign in or a new link of the same account came through once its own is no longer configured, so the stricter keeps counting however many sign ins come through the other. The config's freshness wins over a driver's own freshness(), for drivers of your own too, and Keyring::sso()->freshness() gives the value that counts. A user whose only way in is a never link can't make protected changes, and gets out with a password reset. See Freshness.
Accounts at providers are matched on their issuer and subject, never on the email address. Nobody is signed up or linked by their address, and an account nobody linked gets the same error as a wrong password. Users link accounts from your settings page with POST /user/authenticators/sso, which needs a fresh verification and a verified address, and unlink them like any other authenticator. A link comes with no recovery codes and is never the default.
Every request carries PKCE (S256), a state kept in the browser's session and used once, and for OpenID Connect a nonce. ID tokens are checked for their signature against the provider's published keys, issuer, audience, times and nonce, and a callback naming another issuer (RFC 9207) is refused. Microsoft addresses count as unverified unless the tenant vouches for the domain with xms_edov, and a GitHub address only counts as verified when it's the primary one GitHub has verified.
A completed password reset unlinks every provider linked to the account, before it signs every session out and again after, and an undone email change unlinks the ones linked since. The sso factor key is reserved for the factor.
A user who says no at the provider is sent back with the new sso-cancelled status. Failed sign ins are logged as factor_failed, and refused links as enrollment_refused. Every SsoFailed Keyring catches is reported to the exception handler, apart from a user saying no and a spent or unknown state (SsoFailed::expected()).
Discovery documents and key sets are only cached once they've been checked, and a provider's RSA keys have a 2048-bit floor of their own (SignedToken::SHORTEST_RSA_KEY), apart from passkeys' minimum_rsa_bits. An issuer elsewhere can't name plain HTTP endpoints, nor a token endpoint or key set on a private or local address other than on its own host and port, unless the new private_endpoints option says it may. Microsoft's organizations tenant refuses personal accounts.
token_endpoint_auth_method takes none for a public client, and a driver built on OAuth2Provider adds values of its own with allowedAuthMethods(). scopes leaves out a null or empty string, so an env() can turn one off.
FactorFailed has firstFactor() and afterFirstFactor(), and afterPassword() is now only true after the password. A second factor failing after a sign in with a provider is still logged as second_factor_failed, and its email names the link that was used instead of saying the password was entered.
Laravel's Failed event only takes the username from the request for a factor that asks for one, so an identity provider's callback can't put one there with its query string.
Keyring\Testing\FakeIdentityProvider stands in for a provider in tests, with really signed ID tokens carrying an auth_time (leave it out with withClaims(['auth_time' => null])), and the authenticator factory has an sso() state. It signs the user in again when asked to with prompt=login or max_age, signedInAt() gives them an older session there, and ignoringReauthentication() keeps using it when asked not to. The fake Google only sends auth_time when the claims parameter asks for it, and the fake Microsoft only after withAuthTimeClaim(), as Microsoft only does with its optional claim. withKeyIssuer() changes the issuer its keys name, which the fake Microsoft's do as Microsoft's do. Endpoints are refused when their host resolves inside the network, so host names are looked up with Keyring\Sso\HostResolver, which the fake swaps for HostResolver::fake(). SingleSignOn::credentialId($issuer, $subject) gives the credential ID a link is stored with, for links made by your own code.
A sign in, confirm, or new link with a provider keeps the provider's amr and acr on the session's Verification, as providerAmr and providerAcr, for an app that reports how the user signed in. They're the provider's claim and count toward nothing, not the level, the categories or phishing resistance. At most 10 amr values of a plain form are kept, and an acr up to 255 printable characters, so a provider can't fill the session. See Second Factors and Policies.
A ProviderIdentityAccepted event, with the user, the link, the provider's Identity and the purpose (login, confirm or link), fires when a provider's account is accepted as the user's link. A sign in only fires it once the account matched a link, and before any second factor. Queued, its identity's request has no state, nonce or code verifier, and its claims have no nonce, at_hash or c_hash. See Hearing About Accepted Identities.
A factor of your own that can only start a sign in (answersChallenges() returns false) no longer gets recovery codes with its first authenticator, isn't made the default, can't be made it with PATCH /user/authenticators/{authenticator}, and doesn't count as a second factor that recovery codes are kept for.
Impersonation
Features::impersonation() lets someone sign in as another user and come back, in place of packages such as lab404/laravel-impersonate. Nobody may until Keyring::allowImpersonationWhen() says who may impersonate whom, and Keyring always refuses impersonating yourself, an account its guard wouldn't load, a user who may not sign in, and starting a second one while impersonating. Keyring::allowsImpersonation() asks for a button that only shows when it would work. See Impersonation.
POST /impersonate/{user} (keyring.impersonation.store) starts, behind the new impersonation.middleware, two factors proved in the last 15 minutes by default, and POST or DELETE /impersonate (keyring.impersonation.destroy) stops, answering a stop with nobody being impersonated, a second one from another tab say, as back already: a 409not-impersonating for JSON clients, which the browser package's stopImpersonating() resolves with, and impersonation.return_url for a page. Both answer with a status response (impersonation-started, impersonation-ended) that sends Clear-Site-Data, to impersonation.redirect_url and impersonation.return_url, and have an Inertia visit load that page in full. Keyring::impersonate() and Keyring::stopImpersonating() do the same from a controller of your own, and a refusal throws the new ImpersonationRefused, a 403, answered to JSON clients with the impersonation-refused status whatever the reason, whose reason is the new Keyring\Enums\ImpersonationRefusal: disabled, no_callback (the feature is on but Keyring::allowImpersonationWhen() was never called), both of which also write a warning to the app's log naming what's missing, self, not_allowed, impersonating or unregistered. Keyring::impersonationRefusal() says which, ahead of starting.
The impersonated session is a registered session of its own, on a new session ID, that names the impersonator and their parked session: nothing proved, never remembered, on no device, and ended by itself after impersonation.lifetime (an hour), which is checked when the app boots with the feature on. The user's own Login and Authenticated don't fire, no risk signals are assessed on it, InactiveAccount doesn't count it as the user using their account, and nothing the impersonator proved carries over. Who may impersonate whom is asked again on every request, and a callback that throws there is reported and ends the impersonation, where it's thrown on before starting. Going back takes the impersonator's own session still being good, the impersonator still allowed to sign in, not held for a new password and on the password they had when it started (its hash then, compared in the form Laravel's auth.session compares, whether or not that runs, so any change to it meanwhile, a rehash, a password set or removed, or Keyring's own change with sign_out_others off included, signs the browser out rather than going back), and the browser's session still being the impersonation it started. It restores that session, kept from lapsing while the impersonator was busy though a gap between requests past a level's idle limit still lapses it, and Laravel's auth.session password hash, but at AAL1 at most and with nothing counting as fresh, since a page of the user's could have sent the stop: only as much of what was proved as stays short of AAL2 is kept, the password ahead of anything the impersonator has, so keyring:aal2 and keyring:aal3 ask for the second factor again (the password still counts), and keyring.fresh asks again. Its new record has the level it came back at. A copy of the impersonator's "remember me" cookies that carried their parked session on in another browser is a cookie used twice: when the impersonation ends, the session the copy carried on is ended where it moved to, and RememberMeReused fires and remember_me_reused is logged, as when nobody is impersonating. Under sessions.end_on_lapse, where a session doesn't outlive the level it signed in at, an impersonator whose session signed in above AAL1 is signed out instead, with impersonator_session_ended, as coming back at AAL1 would be that level running out. Otherwise the browser is signed out, as it is when the impersonator's own session ends meanwhile, or the user can no longer be loaded. An impersonated session isn't one of the user's under sessions.max. Their "remember me" cookies are left alone while it lasts. Going back moves their session to a new record on every session driver, as a step-up does, so a copy of the session from while impersonating leads nowhere, and Keyring's "remember me" cookie moves with it. Starting and going back remember the ID they replace, so a request sent before either that finishes after doesn't save the session from before back. Only one request ends an impersonation, however many of the browser's find it over at once: the first to claim its end, in the rate limiter's cache store, whatever ended its record meanwhile. A store that fails lets the request end it anyway, and is reported. The rest are answered as signed out with lost, and log, announce, revoke and move nothing. Sessions::reregister() returns whether the session moved. Signing out while impersonating leaves the user's "remember me" token alone, also when the session registry fails, which changes the impersonator's instead when their parked session couldn't be ended. Starting and going back forget Laravel's url.intended, so a page of the user's can't choose where the impersonator's next confirm or sign in goes.
While impersonating, Keyring refuses password and email changes, authenticator changes, ending sessions and devices, confirming a step-up, an identity provider's callback for a link or a confirm, verifying the email address and sending the verification link again, and starting another impersonation with a 403 and the impersonating status, whatever changes_middleware holds. Step-up middleware answers the same rather than sending the browser to confirm. The new keyring.not-impersonating middleware refuses routes of your own. keyring.enrolled and a password hold let an impersonating browser through.
Keyring::impersonating(), Keyring::impersonator(), and Keyring::impersonation(), what a banner needs, read from the session. Its expiresAt is when the impersonation really ends, capped by sessions.absolute as its record is. The browser package has impersonate(), stopImpersonating(), routes.impersonate(), routes.stopImpersonating(), and the Impersonation type.
The sessions list marks an impersonated session as impersonated, with the impersonator as impersonator, {"name": "..."} with no ID, for the user to end, unless impersonation.show_in_sessions is false. It shows no name, ip or device for it, as they'd be the impersonator's, and its record doesn't keep the impersonator's IP address or browser. Nor does the security log on the user's account: impersonation_started, impersonation_ended, and any other entry written on the user's account while impersonating have no ip or user_agent, while the impersonator's entries keep them.
impersonation_started and impersonation_ended are left out of Keyring::activity(), and are in Keyring::unlistedActivityTypes(), when impersonation.show_in_activity is false. They're still logged. Listing them in security_log.unlisted doesn't hide them, as with Keyring's other types.
impersonation_started and impersonation_ended are logged on both accounts, with why it ended, and the ImpersonationStarted and ImpersonationEnded events fire, each with the impersonated session's handle, which is among the handles its record's RegisteredSessionEnded carries when the browser never comes back. The start is logged before the browser changes hands and before ImpersonationStarted, and a start that can't be logged is refused. The end is logged, and ImpersonationEnded fires once, even when signing out or going back fails after the sessions were ended, and when signing out can't end the impersonator's parked session. Going back that fails, handing the browser back or moving the impersonator's session to a new record, ends the impersonator's session and signs the browser out, and so does a sign in that can't end an impersonation the session still holds. A start that can't be logged takes the user's record back without a RegisteredSessionEnded, and the sweep doesn't announce it later. So does one that's logged but can't hand the browser over, an app's Authenticated listener that throws say, which leaves the impersonator's session as it was and logs the end with the new failed reason, without either event. A refused start is logged as impersonation_refused on the impersonator's account, with the reason, one of ImpersonationRefusal's or not_found for an ID nobody has, or one the database won't look up (an error in SQLSTATE class 22, where any other is thrown on), and the ID asked for. A browser signed out because an impersonation couldn't go back gets SignedOutResponse with the impersonator_session_ended or lost reason, or, when the session middleware finds it on a route in sessions.continue_as_guest, is asked for the page again as a guest. Records an impersonation ends are announced with the new SessionEndReason::ImpersonationEnded.
keyring:install --feature takes impersonation, and its help lists it.
A new migration adds impersonator_id, impersonator_type, and impersonator_session to keyring_sessions. Only an impersonated session writes them. On the database driver, starting without them throws Keyring\Exceptions\MissingMigration, which names them and says to run keyring:install and migrate, asking the database once and then the cache for a few minutes.
Headless Frontends
A JSON request for one of Keyring's pages, one that isn't an Inertia visit, gets the page's name and props as {"page": "...", "props": {...}}, for a frontend Laravel doesn't serve, such as a Nuxt app. Laravel counts an XHR that accepts anything as a JSON request too, so a Blade page that loads one with jQuery now gets JSON (see the upgrade guide). It's sent with the same headers as the page, Referrer-Policy: no-referrer and Cache-Control: no-store on the pages emailed links open included, never throws MissingPage, and isn't noted as the page to go back to. A page you render with a closure through Keyring::page still decides what it answers.
A pages config option. Set it to false when every page is in such a frontend, and a page request that isn't JSON gets a 404.
JSON answers that send the browser to one of Keyring's pages name it as page: challenge and confirm on the challenge response, confirm on the 423 for step-up, login on the 401 for a session Keyring ended, which also gains a redirect to the login page, and the page a status response's redirect goes to, such as login after a password reset.
A JSON request to a sign in or step-up that ran out or used up its code guesses gets a 422 with the reason on the field, as a page visit's redirect flashes it, and the page to start again on as page and redirect. It used to be redirected, and a fetch() that followed the redirect lost the error.
Verifying an email address answers JSON requests with an email-verified status, justNow and the redirect, where it always redirected.
A password_change_except config option, like enrollment_except: route names a user held for a new password can still reach, such as the route a frontend calls on every page to learn who's signed in. It's empty by default, so nothing changes until you list one.
The JSON answer that completes a sign in, the 200authenticated after a password, a challenge, a passkey or an identity provider's callback, and after registering, carries the sign in's "was this you?" alerts as alerts, an empty list when there are none. They're still flashed to keyring.alerts as before, so a page loaded after a JSON sign in shows them too. A confirmation's answer has no alerts. A response of your own finds them in $request->attributes->get('keyring.alerts').
A JSON request that opens an email verification link while signed out, where registration hides who has an account, gets a 401 with the sign-in-to-verify status, its message, page set to login and the login page as redirect, instead of Laravel's bare 401. Like the 401 for a session Keyring ended, it isn't flashed as well, so the login page loaded next doesn't show it twice. Page visits, Inertia's included, are still redirected to the login page with the status flashed. Both answers come from a new SignInToVerifyResponse contract, which Keyring::respondWith can swap like the others.
A guide to headless frontends: Sanctum, CORS, cookies, CSRF, passkeys, emailed links that open the frontend, mapping pages and answers to its routes, and rendering on the server with Nuxt.
Browser Package
@keyringjs/keyring 0.2.0. configureRequests(), for a frontend Laravel doesn't serve, such as a Nuxt application on app.example.com calling Laravel on api.example.com. baseUrl sends every path json() is given there, Keyring's routes included, after the route prefix. Requests to it then send cookies (credentials: 'include') unless told otherwise with credentials, and everything stays same-origin without a baseUrl, so Inertia applications see no change. csrfCookie names a URL such as Sanctum's /sanctum/csrf-cookie to fetch before a request that needs the XSRF-TOKEN cookie when it isn't there, once for requests made together, and throws when the cookie arrives but the page can't read it. fetch replaces the global fetch. An option it doesn't have, such as baseURL, throws. See Frontends on Another Origin.
json() no longer throws when rendering on the server, where there's no document. It sends no XSRF token there.
signInWithProvider(), linkProvider() and confirmWithProvider() send the browser to an identity provider to sign in, to link an account, or to confirm a step-up, routes.ssoRedirect(), routes.ssoCallback() and routes.ssoConfirm() give their paths, and the LoginProps, IdentityProvider, SsoAuthenticator, SsoEnrollment and SsoChallenge types describe what Keyring sends. See Signing In With an Identity Provider.
json('GET', url, body) throws a TypeError before sending anything, rather than leaving fetch() to refuse a GET with a body.
passkeyCredential() and isAbort() are in the main entry point too, so a frontend without Inertia can sign in with a passkey without installing @inertiajs/core. The inertia, vue, and react entry points still export them.
Headless Vue and React bindings, for a frontend that doesn't use Inertia, such as a Nuxt or TanStack Start application: @keyringjs/keyring/vue-headless and @keyringjs/keyring/react-headless. They have useChallenge() and usePasskeyLogin() shaped like the Inertia ones, and a useForm() shaped like Inertia's, all posting with json(), so configureRequests() applies, and holding their own processing state and 422 errors. useForm() sends a get()'s fields in the query string, and keeps a failure with no field errors and nowhere to go, a network failure or timeout included, in error until the next submit or clearErrors(). It sends JSON, so it doesn't upload files, and the Vue one throws for a field named after one of the form's own properties, such as error. A navigate callback gets each answer's page, redirect, status and httpStatus, so the app's router handles the 202 challenge, the 423 for step-up and the page after. Laravel's own 401 for a guest, a body with only a message, comes to it as the login page. Without navigate, an answer that leaves the page shows its message as error. The headless useChallenge() takes the purpose rather than the props, and loads them itself in the browser, again after "try another way", after sending a code, and when an answer names the same page. Neither needs @inertiajs/*. See Headless Vue and React.
@keyringjs/keyring/headless, the framework-free half of those bindings: destination(), request(), fieldErrors(), submitForm(), loadPage(), loadChallenge(), switchTo(), sendCode(), signInWith(), passkeyLogin() and challengeFlow(). See Headless Helpers.
Sessions and Devices
The login page's passkey options, asked for as the page loads, no longer sign the user out when they come back after a quick password sign in. Laravel saves the session and sends its cookie at the end of every request, so the late answer put the browser back in the session from before, signed out, or with no sign in waiting for its second factor. Keyring now binds its own StartSession middleware in place of Laravel's, on by default with sessions.overlapping_requests. It's Laravel's, except that a request sent before its session ID was replaced, or within 10 seconds after, saves no session and sends none of its cookies, the "remember me" ones included, and a "remember me" cookie doesn't sign it in again. Keyring remembers each session ID it replaces, and when, for five minutes, in the rate limiter's store, before it destroys the old session. An ID your app or another package changes, with regenerate() or a sign in of its own, is remembered as that request ends. That covers every route that starts the session: the web group, Sanctum's stateful API and packages that list StartSession. It also covers a second press of a challenge's button, a page still loading during a step-up or sign-out, the sign in, link and confirm an identity provider's callback finishes, and a copy of a cookie driver session that Keyring signs out on its way. A browser still holding a replaced ID after those 10 seconds gets a fresh, empty session, on every session driver. The passkey options route takes the session lock too. A request sent while the one replacing the ID still runs counts as sent alongside, for up to a minute, and the 10 seconds start as its answer leaves; a replacing request that runs longer, or dies, lapses after that minute. A rotation whose registry write fails still gives the session a new ID, and revokes the old record where the registry allows, signing that browser out. An app's own subclass of StartSession is left alone, with a warning in the log; extend Keyring\Http\Middleware\StartSession instead, or use the Keyring\Concerns\SkipsReplacedSessions trait in a subclass of another package's. Keyring also warns when cache.limiter is an array store outside tests, and reports a store that's down at most once a minute per process (per request under PHP-FPM). See Requests That Overlap a Sign In and the upgrade guide.
PUT /user/password, DELETE /user/sessions, DELETE /user/devices and POST /email-changes/{change}/confirm take the session lock. On the database, file and redis session drivers, a stolen copy of the session cookie that signed out the other sessions while the owner changed the password could stay signed in, on the registry record the change kept, while the owner's browser was signed out. Now the two run one after the other, and a change that waited is refused, or a copy that waited is signed out. PUT /user/password, DELETE /user/sessions and DELETE /user/devices are behind a new keyring-session-changes rate limiter, as the last two each leave a revoked registry record until the session would have expired: 6 requests a minute for each session, kept across the new records it moves to, and 30 a minute for the user's sessions together, so signing in again and again doesn't get more guesses at the current password. A request on a registry record that has ended is counted apart, 6 a minute for all of the user's ended records together, as the limiter runs before the session middleware signs it out: an old copy of a cookie driver session sent again doesn't spend the owner's six or the thirty. It's apart from the keyring limiter so another session of the user's, such as someone who signed in with a stolen password, can't use up the six a minute on cheap routes and keep the owner from changing the password or signing everyone else out. See Requests That Overlap a Sign In.
Sessions::rotate() moves the session to a new registry record, and revokes the old one, on every session driver, where it only did on cookie. Keyring calls it on a step-up, a password change, "sign out other sessions", an applied email change, and now on adding a sign-in method too. The session keeps its handle. Only the request that made the change knows the new record, so a stolen copy of the session cookie can't stay on the record a password change keeps as "this session", even with a session ID of its own: one that a request on the old ID saved again after the copy's request destroyed it, with sessions.overlapping_requests off or while the store is down, or one a route calling Laravel's regenerate() gave it. The owner's next change signs such a copy out, and a change from a browser whose record the copy moved on first is refused. A rotation that finds its record already moved on by another request revokes the record it moved to, and one whose session handler fails to destroy the old session revokes the new record, rather than leave a record no browser holds. On the database registry driver every rotation now needs the origin column from 0.3's migration, so run it first: without it a rotation throws the new Keyring\Exceptions\MissingMigration, which names the migration, rather than a bare database error. See the upgrade guide.
Adding a sign-in method with sign_out_others moves the session to a new registry record once, where it did twice. Sessions::signOutOthers() rotates the session before it dispatches SessionsRevoked, so a listener that throws can't leave it on its old record.
POST /logout, or ending the current session from the sessions list, while a request sent alongside rotates the session, follows the session to its new record and ends that too. It used to end only the record the rotation had already revoked, and the browser stayed signed in on the new one.
A password change, an applied email change, and adding or removing a sign-in method sign the other sessions out, when asked, and give this session its new ID and registry record, even when something after the save throws, such as a synchronous PasswordChanged or AuthenticatorAdded listener whose mail can't be sent, something set to run after the commit (an observer with $afterCommit, an event or job dispatched after commit), or a sign-out that fails part way. The change used to stay saved with every session still signed in and this one left on the record a copy of its cookie holds. The failure is still thrown, and a sign-out that then fails too, as one inside a PostgreSQL transaction the failure aborted would, is reported rather than thrown in its place. A password change that fails once its new password is saved still cancels the pending email change, ends the reset links, lifts a hold and stops trusting the user's devices, each tried even when one before it fails, where something run after the commit used to skip them and leave an email change or reset link from before the change working. A save that was rolled back, such as a new sign-in method whose transaction a saved observer aborted, or a password saved again unchanged, signs nobody out and leaves the session as it was, after the commit too. PasswordChanges::change() takes then:, run once the password has changed, after that sign-out and whatever fails after the save.
A session ended because a step-up, password change, "sign out other sessions", applied email change or new sign-in method found that another request holding the session moved its record on first is announced with the new SessionEndReason::Contested (contested), where it was revoked, which reads as an ending from the sessions list. A new SessionContested event carries the user, the ended session and its handle, and it's logged as session_contested (warning), which is one of the default "was this you?" alerts. A stolen copy of the session cookie is one cause. Others are a form sent twice to a route without the session lock, a request that held the lock for longer than its 10 seconds, and a rotation sent alongside a risk step-up Keyring made. A risk step-up is never contested itself: requests from one browser that step up together after its address changes join the record the first of them moved to. Only a record a risk step-up made is joined, which Keyring notes in the rate limiter's store for five minutes, so a record a rotation moved to never is, even when an update of the address or browser in place leaves it looking stepped up, and a copy of the cookie stepped up alongside a password change or "sign out other sessions" can't carry on past it. With the store down, nothing is joined, and the requests alongside carry on until their next request finds the record ended. See A Contested Session.
A sign-out your app does itself also ends the registered session when the app empties the session first, as in $request->session()->invalidate() or flush() followed by Auth::logout() or Auth::logoutCurrentDevice(). Before, the record stayed good until it timed out and no RegisteredSessionEnded went out. On the cookie session driver a copy of the session stayed signed in, and after logoutCurrentDevice() so did a kept copy of the "remember me" cookies. It works on any route Keyring's session middleware runs on.
A browser coming back on "remember me" no longer signs out or forgets the account's other devices to stay under devices.limit. On an account already at the limit, a browser the account hasn't used gets no device and its session is on none. It's announced with the new UnrecordedDeviceSignedIn event, a new_device log entry with no device, and the new_device email without a "this wasn't me" link.
A sign in whose guard login() throws (an app's Login listener, or the remember token save) is now undone like any other failed sign in: the user is left signed out, with no session registered and no "remember me" cookies.
A sign in overtaken by a password reset or change, an email change, or a removed sign-in method is now signed out even when stopping trusting the account's devices fails as it ends.
With sessions.max, a sign in whose limit fails to end a session, on the cache driver or a registry on a sessions.connection of its own, revokes its new record again without a RegisteredSessionEnded, as before, and now keyring:sweep doesn't announce it later either.
Policies and Step-Up
Verification::provedAtIfKnown() gives when the user proved it, or null when that's unknown, where provedAt() gives Verification::UNKNOWN (0). Reading What Was Proved now builds auth_time with it.
continue on the authenticator-added status only comes back once the account can meet what sent the user to enroll. Adding an email code on the way past keyring.enrolled, or an authenticator app on the way to an AAL3 page, used to hand back the page, and following it sent the user straight back to enroll. Now the page stays saved and comes back with the sign-in method that does meet it. When keyring.enrolled stops a route that also asks for keyring:{level}, the page waits for the stricter of the two. Recovery codes don't count toward it. A page saved before the upgrade, with no requirement kept beside it, comes back with the next sign-in method added, as before. It goes by what a confirm could meet (UserKeyring::canConfirm()), as step-up does, so a sign-in method the confirm page can't ask for doesn't count either.
A confirm sets Laravel's auth.password_confirmed_at to the latest moment the user proved one of the factors it added (Verification::provedAt()), not to when it finished, and never moves it back. What it built on, such as the password from signing in, doesn't count.
Security
An authenticator is established once the account has had it for authenticator_changes.established_after, 7 days by default, and a set of recovery codes once that set is as old. Only established keys raise the bar. Signing in counts as a fresh verification, so a stolen copy of a session that had just signed in could add a passkey and lock the owner out: under noDowngrade(), or a phishingResistant(), deviceBound() or aal3() policy with ifEnrolled(), the new key made the owner's password and authenticator app stop working at once. Without those, the copy could add a key and then remove the owner's app. Either way it could replace their recovery codes, and a password reset left all of it in place. A policy with ifEnrolled() that asks for more factors than the owner had, such as factors(3), did the same with a key of a new kind. Now a newer key signs in like any other, and counts when it's used, but only established authenticators decide what an ifEnrolled() policy asks for, so those policies only ask for a key, or a third factor, once the account has an established one. An account with a password and no established second factor, which needs the password to add one, is still asked for its new factor at once, unless that factor was added without the password being checked for it (before the account had one, say), and a fresh verification only asks for a key that can't leave its device when that key is established. A policy without ifEnrolled(), and middleware such as keyring:aal3, take any key that qualifies. Thanks to @octoper for suggesting this approach, after Google's.
Adding a second factor to an account with no established one, such as a password-only account, takes the current password as password when the enrollment begins. A copy of a session that had just signed in could give such an account an authenticator app or passkey its owner didn't have, and the owner was then asked for it at every sign in. A wrong password counts against the password's rate limits and dispatches FactorFailed, and one the limits refuse is answered as at the login form, with Lockout and, at the cap on failures in a row, AccountLocked. Accounts without a password are unchanged. A first password set from a session, with no current one to type, counts as a new sign-in method: it isn't established for 7 days, freezes the account, isn't asked for by an ifEnrolled() policy, and isn't asked for to add a factor until then, so neither it nor a factor added with it can shut out the owner. A reset makes the password established. AuthenticatorChanges::add() takes passwordConfirmed: true for your own code, and throws PasswordRequired without it, needsPassword() says whether it's needed, and EnrollmentRefused can have the reason password.
The password for removing the last second factor is checked under the password's own rate limits, as at a step-up, before the removal's row lock. It was only held to the keyring form limiter, with no count of failures in a row and no FactorFailed. An app that doesn't register the password factor no longer asks for one there.
An account's sign-in methods are frozen while it has an authenticator that isn't established, or a first password set from a session in the last 7 days, and for 7 days after it removes or replaces an established one or an established set of recovery codes that had codes left. While frozen, removing, renaming or replacing an established authenticator (a factor of your own that allows one per user included), and replacing established recovery codes, are refused with a 422 on authenticator. The JSON says why and until when as frozen, and which factors could make the change now as frozen.skip. Removing a newer authenticator always works, and freezes nothing, so the owner can remove one someone else added. Making the first recovery codes, or replacing a set made in the last 7 days, always works too. It's checked in AuthenticatorChanges, under the row lock removals already take, so JSON clients and your own code get it too. remove(), add() and update() take ignoreFreeze: true for your own support tools. See Frozen Sign-In Methods.
While frozen, the owner can still make one change by proving a passkey or security key the account has had for established_after, and since before the session signed in. A factor of your own counts when its phishingResistant() says so, with its challenge() kept for that change. The proof goes in the change's own request, as proof, and is answered for that change alone: POST /user/authenticators/{factor}/proof-options with action (remove, rename or replace), target, and for a rename the new name, gives a challenge kept apart from sign in, step-up and enrollment ones. Its first answer uses it up, claimed in the rate limiter's store, so it can't be answered twice from a copy of the session or by two requests at once, whatever kind of key or factor answers it. A sign in or step-up, even with that key, doesn't count, so a copied session cookie can't make the change. For new recovery codes, or a factor a user has one of, the proof goes with the request that begins them, never the confirm. An established authenticator app counts too with the new authenticator_changes.skip_with_totp option, off by default, and proof.authenticator names which app when there's more than one. Recovery codes, an emailed code and the password never do. A change made this way freezes the account as any other would. See Making a Change With an Established Key.
The authenticator_added and recovery_codes_generated emails say what to do if it wasn't the user: remove the new method, sign out everywhere and change the password. With the new authenticators_url option, your page for sign-in methods, they link there, from APP_URL. SecurityNotice has an ifNotYou() method for that line.
AuthenticatorRemovalRefused has a reason, last_factor or frozen, and so does the authenticator_removal_refused log entry. EnrollmentRefused and enrollment_refused can have the reason frozen.
Linking an identity provider takes the password on the same terms as adding a second factor (linkProvider() takes { password }), a new link freezes the account and an established one can't be unlinked while it's frozen, and a link is never the established second factor those checks look for, nor proves a change.
keyring:import keeps when an imported authenticator app or passkey was first confirmed as when it was added, so it's established from the start. Imported recovery codes go by the app's confirmation too. With Fortify's confirm option off there's no date, so those accounts are frozen for 7 days after the import.
The authenticator factory has an established() state, for a test's authenticator that the user has had a while.
@keyringjs/keyring has a FrozenChanges type for the frozen in a refusal, with skip. frozenChanges(error) reads it, proveWithKey(factor, { action, target, name? }) runs the ceremony for one change and returns its proof, and removeAuthenticator() and renameAuthenticator() take proof. enroll() sends a proof and a password with the beginning only.
SessionFingerprintChanged compares the session's user agent with the request's trimmed to 500 characters, as Keyring stores it. A user agent longer than that whose end named another browser counted as a move, though the session went on storing it as the same browser.
json() only sends the X-XSRF-TOKEN header to the page's own origin or the baseUrl, never to a full URL on another origin. It decides that from the URL as the browser parses it, so a URL that only looks like a path, such as /\evil.test, gets no token either. See the upgrade guide.
Signing in, confirming and verifying an address only go on to an intended URL on one of the app's own origins (the request's, APP_URL's or that of the keyring.domain host), or a path, in the redirect and in the JSON redirect alike. When Laravel stops a guest's form post or HEAD request, it keeps the request's Referer as url.intended, whatever site it names. A HEAD gets past CSRF protection, but the browser only sends it with the session cookie from a page on the same site, such as a sibling subdomain, or when the session cookie is SameSite=None. From such a page, a link could send a user to another site straight after a real sign in. An intended URL on another site, //host, backslash and userinfo tricks included, is now dropped from the session and the user goes to home. The page a confirm hands on to enrollment is checked the same way. Keyring\Support\Url::redirectToIntended() takes the place of redirect()->intended() in a response of your own, and Url::intended() and Url::pullIntended() read the intended URL with the same check. See Where They Go Next.
Keyring now requires Laravel 13.43 or later.
The minimum web-auth/webauthn-lib is 5.3.13 and the minimum symfony/serializer 6.4.51, 7.4.24 or 8.1.12, and composer.json conflicts with older releases of Guzzle, PSR-7, CommonMark, Flysystem, random_compat, and the Symfony HttpFoundation, HttpKernel, Mailer, Mime, Routing and polyfill-intl-idn packages. The lowest-dependencies CI job runs composer audit on what an app installs with Keyring, so a minimum that falls behind a fix fails the build.
Keyring's attestation check only accepts a certificate a key sent when it's a single PEM block with nothing around it.
The keyring and keyring-session-changes limiters are applied with a new keyring.throttle middleware instead of Laravel's throttle, so they count a request only after Keyring's session middleware and the route's other checks (changes_middleware, guest) have let it through. A "remember me" cookie of a session the owner ended can no longer use up the owner's limit with requests that are then signed out. Both limiters count a signed-in user by model and ID.
A successful sign in no longer clears the counts kept under the username as it was typed. It only takes back its own attempt from the name's per-minute count and leaves the name's failures (limits.remember_names_for) where they were, so a name with an account keeps being answered like one without after its owner signs in from a new browser. The right password still signs in behind a refused name. A password reset doesn't clear them either, as before, so after limits.consecutive_elsewhere failures under a name in that time every wrong password under it answers 429. See Typed Username Counts Outlast a Sign In.
An enrollment is tied to the account that began it, and signing in forgets any enrollment or freeze-skip challenge left in the session. One begun by another account fails to confirm with enrollment_expired.
A user held for a new password can't get rid of the hold by changing to a stopgap and straight back. The hold keeps the hash of the password it was placed over, and a change marks it lifted rather than deleting it, keeping it for a year (PasswordHold::KEEP_LIFTED_FOR). Until then PUT /user/password refuses that password with the new password_held message before the action saves it, and a reset back to it puts the hold back in force. A hold placed before the new keyring_password_holds migration keeps the password the account had when the change that lifts it comes. Until that migration has run, holds, password changes and resets, and keyring:prune once it has pruned everything else, throw MissingMigration, which names it. keyring:prune deletes lifted holds after that, and Keyring::cancelPasswordChange() deletes the hold and the password it kept at once. PasswordChanges::change() takes the chosen password as new: for the check.
A password reset signs out every session and unlinks identity providers even when something after the action's save fails, such as cancelling a pending email change or ending the reset links, before the failure is thrown. Marking the new password as established is best effort, in its own transaction. A reset the action refused, or one that failed before the action's write returned, signs nobody out unless the stored password changed.