Repository navigation
v0.3.0
Sessions and Devices
- A session keeps its handle when it moves to a new record: when "remember me" carries it on, when a risk response asks it to verify again, and with
rotateon thecookiesession driver. Each record names the one the session started on (origin), and the handle comes from that. Sessions that started before the upgrade keep the handles they had. Needs a new migration, see the upgrade guide. Sessions::stillSignedIn($user, $handle), for code that knows a session by its handle to ask whether the user is still signed in on it. It appliesKeyring::allowSignInWhen()and the session's timeouts, and it changes nothing.- A conformance check that the session registry keeps
originwhen a session moves, so a missing migration or a custom driver that drops it is caught in your tests. - The session registry says which records it revoked.
revoke()returns the record it revoked, ornullwhen it revoked nothing, andrevokeAll()andrevokeDevice()return the records they revoked instead of a count. Custom registry drivers need to return them too: see the upgrade guide.Sessions::signOutEverywhere(),Sessions::revokeDevice()and theSessionsRevokedevent still give a count. - The conformance suite checks that the configured registry returns the records it revoked.
- A
RegisteredSessionEndedevent for every registered session that ends, whoever ends it and wherever: signing out, the app's ownAuth::logout()orAuth::logoutCurrentDevice()(announced aslogged_outunless the app gives a reason of its own withSessions::because()), signing out everywhere, ending a session or a device, the device and session limits, a deleted user, a risk response, a password change or reset, an email change or its undo, and the session middleware finding a session idle, expired, used twice or kept out. It names the session by its handle, with the handle under each previous app key too, and says why it ended (Keyring\Enums\SessionEndReason). It never carries the registry ID. On thedatabasedriver it goes out once the transaction it was revoked in commits, and not at all if that's rolled back. A listener that throws is reported and doesn't stop the sign-out. See Hearing About Ended Sessions. - An
EveryoneSignedOutevent whenkeyring:sign-out --allor the registry'srevokeEveryone()ends every user's sessions at once. - Every registry driver, a custom one included, is wrapped in
AnnouncingSessionRegistry, which dispatches those events from what the driver returns.app(SessionRegistry::class)returns the wrapper, and itsinner()the driver. See the upgrade guide. - A conformance check that signing out announces the session that ended, which fails when a
SessionRegistryis bound in the container without the wrapper. - A driver that fails after revoking some of a user's records throws a
PartialRevocationwith the ones it revoked, so they're still announced. Thecachedriver does this when the store fails part way through signing out everywhere, and keeps a revocation whose copy into the record fails. On thecachedriver only, what a synchronous listener wrote on the user's connection is kept too, when Keyring's row lock is the outermost transaction: inside one of the app's own, the failure still rolls it back unless the app catches it. A database failure, deadlocks and lost connections included, always rolls it back. On thedatabasedriver with the registry on the user's connection, the failure rolls back the whole change, a sign in's new record included. With the registry on asessions.connectionof its own, it behaves as thecachedriver does. On either driver, signing out everywhere still cycles the remember token, stops trusting devices and cancels a pending email change before the failure is thrown, signing a device out still cycles the remember token, and signing out everywhere else still gives this session a new ID. - Registry IDs are marked
#[\SensitiveParameter]on the contract, both drivers andSessions, so they stay out of reported stack traces. keyring:sweep, which ends sessions that timed out with no request to end them and announces them asidleorexpired, and announces again any ended session whose event was lost, so every ended session is announced at least once on thedatabasedriver. Turn it on withsessions.sweep_every, and Keyring schedules it before the prune, on one server and never overlapping. One run announces again, and ends, at mostsessions.sweep_limit(1000) sessions each. A listener that throws is tried again five minutes later, then at doubling intervals for a day. Needs a new migration, see the upgrade guide.- Once the new migration has run,
keyring:prunekeeps sessions a sweep still has to end or announce, whether or not one is scheduled. An expired session nobody ended stays up to a day longer before the prune removes it, and so does one the sweep ended for timing out, so its browser is still told why. keyring:sign-out --allmarks the sessions it ends for itsEveryoneSignedOut, so the sweep never announces them one by one, and counts them announced once the event has gone out. If it didn't, the sweep dispatchesEveryoneSignedOutagain, up to a day later, the latest of any lost ones, which settles the rest. Itsatis a cut-off on sign-in time, never "end everything now".- With the migration run, a record "remember me" moved a session to stays until it expires, so a used cookie still raises
RememberMeReusedafter the sweep ended its session and the prune ran. RememberMeReusednow also fires when the session a used cookie was carried on to has timed out since, so a sweep ending that session doesn't hide the reuse. The used record is revoked then, so the same cookie is reported once.- A browser that comes back after its session was revoked once it had timed out, by the sweep or by signing out everywhere, is signed out as
idleorexpired, inSessionEndedand the security log, as it would be had nothing revoked it first. It used to sayrevoked. One the sweep ended keeps saying so until a day after its expiry. One signed out everywhere says so until the prune removes its record, a day at most. - The database registry driver rethrows a failed query without its bindings, so record IDs, which are what "remember me" cookies hold, stay out of exception messages, logs and error trackers.
PartialRevocationno longer repeats the failure's message. - On the
cachedriver, revoking a record and moving it with "remember me" take turns under the owner's lock (on a store with locks), so a sign-out that lands mid-move is never lost without an event. A revocation that can't have the lock within five seconds goes ahead without it. On adatabasecache store, a failed cache query is rethrown without the cache keys it named, which hold record IDs. - Signing out signs the browser out even when the session registry fails to revoke its record. The failure is still thrown, but the next request is a guest, where it used to be registered as a new session.
sessions.continue_as_guestlists routes that also serve guests. A page visit to one whose session has ended is signed out and asked for again as a guest, rather than sent to log in, whatever the reason it ended. Thesigned-outstatus is flashed and no intended URL is saved. JSON requests still get a401.- A sign-out your app does itself with
Auth::logout()orAuth::logoutCurrentDevice(), on Keyring's guard in a request with a session, now ends the registered session too, with its "remember me" cookie and what the session proved. Before, the record stayed good until it timed out. On thecookiesession driver, a copy of the session stayed signed in, and afterlogoutCurrentDevice(), so did a copy of its "remember me" cookies.
Policies and Step-Up
StepUp::unlessMet()to ask for step-up from a controller, for an integration that reads what to ask for from the request, such as an OpenID Connect provider withacr_valuesandmax_age. It takes anAssurancelevel, a moment the user must have verified since, or both, and gives the same answer as thekeyringandkeyring.freshmiddleware. Asking for nothing, or for a moment more than a few seconds in the future, throws.StepUp::meets()to ask the same thing without starting a step-up, for a request that mustn't show the user anything, such as one withprompt=none. It takesunlessMet()'s arguments and returnstruewhereunlessMet()returnsnull, and leaves no confirm attempt or page to come back to in the session.keyring:{level}gives a guest Laravel's usualAuthenticationExceptioneven when the session still holds what the last user proved, askeyring.freshalready did. A session keeps that when the guard can no longer load its user, say because the account was deleted, and on a route withoutauth, the guest used to get through on it.- The docs explain how to read what a session proved, for claims like
amr,acr, andauth_time. SessionAssurance::level()andcountingToward()take a timestamp, to count only what was proved since then with each level still on its own clock, so claims built formax_agedon't report a level that lapsed.- Users sent to enroll by
keyring.enrolled, by step-up, or by the confirm page with nothing to confirm with now get the page they were going to back ascontinueon theauthenticator-addedstatus. Users held for a new password are redirected there bypassword-updated. Only top-level navigations and Inertia visits are remembered, and only on the app's own origin, for the same user, within an hour. Bind your ownKeyring\Login\Detoursand overrideput()to keep other pages out, such asprompt=noneauthorize requests.
Logging and Emails
- A queued listener for
FactorChallengedorFactorVerifiednow runs for an unsaved authenticator, such as the password's. It has nothing stored, so the job failed with aModelNotFoundException. It's now queued as it is, without the user loaded with it, and a stored authenticator is still queued by its ID. - An unsaved authenticator, such as the password's, now has its user's
authenticatable_typeandauthenticatable_idset, soowner()finds the user, anduser()looks them up again when they aren't loaded. Before,owner()ran a query Postgres refuses. security_log.unlistedlists entry types thatKeyring::activity()leaves out, for entries a package writes about a user that aren't something the user did, such as a token issued to another app's server. They're still the user's entries: alerts, the log channel and a force delete treat them as before.Keyring::unlistedActivityTypes()gives the same types for an activity query of your own. Keyring's own types are never left out.
Extending
StepUpmakes the decisions for thekeyringandkeyring.freshmiddleware, and its constructor also takes aDeviceManager. Whatkeyring.freshasks for isStepUp::freshRequirement(), no longer the middleware's ownrequirement(). See the upgrade guide.
Browser Package
@keyringjs/keyring0.1.1.confirmEnrollment()andenroll()includecontinuein their return type, for the page the user was going to before they were sent to enroll.
Security
- A queued listener for
SessionResumedorRememberMeReusedno longer puts the session's registry ID on the queue. That ID is the value of the "remember me" cookie, so forSessionResumedit was a live one. Queued, the session's record now has a blankidand noreplacedByororigin, and both events always carry the session'shandleto go by instead, the same one the sessions list shows. Listeners in the request see the record as before. - Queueing a listener for an event that carries a sign in or step-up (
Authenticated,Confirmed,FactorChallenged,FactorVerified,VerificationRefused) no longer puts the user's password hash and remember token on the queue. The attempt is queued as the plain data it keeps in the session and looks its user up again when asked. Jobs queued by 0.2 still restore, and drop the user they had cached. AuthenticatorRemovednow queues the user by ID like every other event, and the removed authenticator without its secret.
Restart your queue workers with the deploy. See the upgrade guide for session events still on the queue, and for the old jobs in failed_jobs and Horizon.