Skip to content

v0.3.0

Choose a tag to compare

@entity entity released this 21 Nov 15:08
· 50 commits to main since this release
v0.3.0
eafb9ac

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 rotate on the cookie session 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 applies Keyring::allowSignInWhen() and the session's timeouts, and it changes nothing.
  • A conformance check that the session registry keeps origin when 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, or null when it revoked nothing, and revokeAll() and revokeDevice() 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 the SessionsRevoked event still give a count.
  • The conformance suite checks that the configured registry returns the records it revoked.
  • A RegisteredSessionEnded event for every registered session that ends, whoever ends it and wherever: signing out, the app's own Auth::logout() or Auth::logoutCurrentDevice() (announced as logged_out unless the app gives a reason of its own with Sessions::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 the database driver 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 EveryoneSignedOut event when keyring:sign-out --all or the registry's revokeEveryone() 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 its inner() the driver. See the upgrade guide.
  • A conformance check that signing out announces the session that ended, which fails when a SessionRegistry is bound in the container without the wrapper.
  • A driver that fails after revoking some of a user's records throws a PartialRevocation with the ones it revoked, so they're still announced. The cache driver does this when the store fails part way through signing out everywhere, and keeps a revocation whose copy into the record fails. On the cache driver 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 the database driver 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 a sessions.connection of its own, it behaves as the cache driver 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 and Sessions, 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 as idle or expired, and announces again any ended session whose event was lost, so every ended session is announced at least once on the database driver. Turn it on with sessions.sweep_every, and Keyring schedules it before the prune, on one server and never overlapping. One run announces again, and ends, at most sessions.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:prune keeps 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 --all marks the sessions it ends for its EveryoneSignedOut, 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 dispatches EveryoneSignedOut again, up to a day later, the latest of any lost ones, which settles the rest. Its at is 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 RememberMeReused after the sweep ended its session and the prune ran.
  • RememberMeReused now 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 idle or expired, in SessionEnded and the security log, as it would be had nothing revoked it first. It used to say revoked. 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. PartialRevocation no longer repeats the failure's message.
  • On the cache driver, 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 a database cache 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_guest lists 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. The signed-out status is flashed and no intended URL is saved. JSON requests still get a 401.
  • A sign-out your app does itself with Auth::logout() or Auth::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 the cookie session driver, a copy of the session stayed signed in, and after logoutCurrentDevice(), 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 with acr_values and max_age. It takes an Assurance level, a moment the user must have verified since, or both, and gives the same answer as the keyring and keyring.fresh middleware. 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 with prompt=none. It takes unlessMet()'s arguments and returns true where unlessMet() returns null, and leaves no confirm attempt or page to come back to in the session.
  • keyring:{level} gives a guest Laravel's usual AuthenticationException even when the session still holds what the last user proved, as keyring.fresh already did. A session keeps that when the guard can no longer load its user, say because the account was deleted, and on a route without auth, the guest used to get through on it.
  • The docs explain how to read what a session proved, for claims like amr, acr, and auth_time.
  • SessionAssurance::level() and countingToward() take a timestamp, to count only what was proved since then with each level still on its own clock, so claims built for max_age don'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 as continue on the authenticator-added status. Users held for a new password are redirected there by password-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 own Keyring\Login\Detours and override put() to keep other pages out, such as prompt=none authorize requests.

Logging and Emails

  • A queued listener for FactorChallenged or FactorVerified now runs for an unsaved authenticator, such as the password's. It has nothing stored, so the job failed with a ModelNotFoundException. 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_type and authenticatable_id set, so owner() finds the user, and user() looks them up again when they aren't loaded. Before, owner() ran a query Postgres refuses.
  • security_log.unlisted lists entry types that Keyring::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

  • StepUp makes the decisions for the keyring and keyring.fresh middleware, and its constructor also takes a DeviceManager. What keyring.fresh asks for is StepUp::freshRequirement(), no longer the middleware's own requirement(). See the upgrade guide.

Browser Package

  • @keyringjs/keyring 0.1.1. confirmEnrollment() and enroll() include continue in their return type, for the page the user was going to before they were sent to enroll.

Security

  • A queued listener for SessionResumed or RememberMeReused no longer puts the session's registry ID on the queue. That ID is the value of the "remember me" cookie, so for SessionResumed it was a live one. Queued, the session's record now has a blank id and no replacedBy or origin, and both events always carry the session's handle to 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.
  • AuthenticatorRemoved now 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.