Account SecurityProtected Changes

Protected Changes

On this page

Introduction

Whoever controls the email address and password controls the account, so Keyring's flows for changing them check who's asking, tell the owner, and can be undone. Turn each one on in config/keyring.php:

PHP
'features' => [    Features::resetPasswords(),    Features::updatePasswords(),    Features::emailChanges(),    Features::emailVerification(),],

With updatePasswords() or emailChanges() on, that attribute is protected. It changes only through Keyring's flow.

Protected Attributes

Features::updatePasswords() protects password, and Features::emailChanges() protects email. List others in the protected option:

PHP
'protected' => ['phone'],

With the HasKeyring trait on the user model, changing a protected attribute outside Keyring's flows throws a Keyring\Exceptions\ProtectedAttributeException:

PHP
$user->update(['email' => 'new@example.com']); // throws

That includes your own profile forms. Take email out of them when emailChanges() is on. Creating a user with these attributes is fine.

Note

The check runs on Eloquent's updating event, so query builder updates and saveQuietly() skip it.

Bypassing Protection

For trusted admin tooling, such as a support agent fixing an address, wrap the change in Keyring::withoutProtection() with a reason:

PHP
use Keyring\Facades\Keyring; Keyring::withoutProtection(    fn () => $user->update(['email' => 'new@example.com']),    reason: 'Support ticket 42',);

Each use dispatches Keyring\Events\ProtectionBypassed and logs a protection_bypassed entry against the signed-in user who made the change, not the user being changed.

Changing the Email Address

Whoever controls an address can reset the password, so the new address always has to confirm. The old address can revert the change while it's pending, and for a while after, and it stays reserved meanwhile. You set the timings (email_changes.confirmable_for and email_changes.revertable_for), the validation, the emails and the pages.

Requesting a Change

Send email to POST /user/email. The request needs a fresh verification. Your ValidateEmailChange action (published to app/Actions/Keyring/ValidateEmailChange.php) checks the address and returns it. Add your own rules there, such as a required company domain. Don't check whether the address is taken there. Keyring does that without revealing the answer.

The response is always the email-change-requested status response, so it never reveals whether the address has an account. Keyring then:

  1. Cancels any change the user already has waiting.
  2. Stores a pending change with hashed, single-use tokens, valid for email_changes.confirmable_for (24 hours by default).
  3. Emails the new address a link to confirm.
  4. Emails the current address a link to revert, and one to confirm when that's needed.

If the new address belongs to another account, everything the user sees is the same, and the email to the new address says someone tried to use it. That email has no link, so that change can never be confirmed.

Keyring sends these emails after the response, with defer(), so timing doesn't reveal which case it was.

A MustVerifyEmail user with an unverified address gets the verify_email_to_change message. Each request emails two addresses, so an account can ask five times an hour (limits.notices every limits.notices_per). After that, it gets a 429. No address is emailed more often than that, whichever accounts ask.

Confirming

The new address must confirm. The current address must confirm too, unless this session proved a possession factor (not a recovery code) that the account has had for email_changes.established_after (7 days by default), and since before this session signed in. A factor added recently doesn't count, and neither does one from another account. So whoever got into the account can't add a factor and use it to skip the check.

The change applies once every confirmation is in. Keyring checks again that the address is unchanged and the new one is still free, and cancels the change if either has moved. Applying it sets email_verified_at when the model has that attribute loaded, and stops trusting the user's devices.

It also signs out the account's other sessions and changes the "remember me" token. Set email_changes.sign_out_others to false to keep them. The browser that confirmed keeps its session, under a new ID, only if it's signed in as this account. With the email_changed and email_change_reverted security emails on, both addresses are told.

Mail scanners open links on their own, so the emailed links open a page with a button, and only the button changes anything:

  • GET /email-changes/{change}/confirm/{token} and .../revert/{token} show the email-change page, with action (confirm or revert), url and token. They change nothing.
  • A POST to url, with token in the body, makes the change.

The token stays out of the acting request's URL, so it isn't logged twice. Post it as a form field:

Blade
<form method="POST" action="{{ $url }}">    @csrf    <input type="hidden" name="token" value="{{ $token }}">    <button>{{ $action === 'confirm' ? 'Confirm the change' : 'Undo the change' }}</button></form>

With Inertia, post { token } to url. A missing, wrong, used or expired token gets the email-change-invalid status. A link for a change that doesn't exist is a 404, and LinkRefused records it with the reason unknown.

Keyring builds these links from APP_URL, never the Host header, and they work when the user is signed out. After confirming, the user goes to home if signed in, or to the login page. The status is email-changed once the change applies, email-change-confirmed while it waits for the other address, or email-change-invalid.

Reverting

The current address can revert while the change is pending, and for email_changes.revertable_for (7 days by default) after it applies. Reverting:

  • Puts the old address back, even when a later change moved it away, and cancels any later email changes.
  • Removes each authenticator added within email_changes.established_after before the change was requested, or since the session that asked for it signed in, dispatching AuthenticatorRemoved for each. Identity provider links from that window go too. Recovery codes go as well once nothing recoverable is left.
  • Signs out every session, and changes the "remember me" token.

These removals aren't held back by frozen sign-in methods, and they don't start a new freeze. The user then goes to the forgot password page (or the login page, when resets are off), with email-change-reverted. Reverting doesn't change the password.

Warning

The undo asks for nothing but the link, so whoever can read the old mailbox can press it. That's how an owner whose session was taken over gets back in. It's also how someone who can read that mailbox can undo a change the owner made, and remove a second factor the owner added in the same window. Keyring can't tell these apart. A factor older than email_changes.established_after, and added before the session that asked signed in, survives an undo.

If your users are more likely to lose their mailbox than to have their session taken over, shorten revertable_for and established_after. If it's the other way round, lengthen them.

The Old Address Is Reserved

While a change can still be reverted, nobody else can take the address it replaced. Otherwise someone could register a new account with it, and the revert would have nowhere to go.

Lookalikes are held too: an address that differs only in case, accents, letter width or invisible characters. MySQL's and MariaDB's default collations treat those as the same, so the unique index would refuse the revert. Another account asking for a reserved address gets the same "address in use" email as for any taken address.

Your own code that creates users or changes addresses, such as an admin screen or an import, should add the Keyring\Rules\UnreservedAddress rule next to Rule::unique():

PHP
'email' => ['required', 'string', 'email', 'max:255', Rule::unique(User::class), new UnreservedAddress],

With HasKeyring, saving a reserved address any other way throws Keyring\Exceptions\ReservedAddressException, even inside Keyring::withoutProtection(). Query builder inserts aren't caught. To check an address yourself, call app(Keyring\Changes\ReservedAddresses::class)->has($address).

Checking and Cancelling

GET /user/email returns the pending change, if there is one:

JSON
{  "pending": {    "email": "new@example.com",    "confirmed": false,    "needsCurrentConfirmation": true,    "expiresAt": "2026-11-09T13:00:00+00:00"  }}

confirmed says whether the new address has confirmed. DELETE /user/email cancels the change and answers email-change-cancelled. A password reset, a password change or signing out everywhere else also cancels it. Whatever cancels it, the old address's "this wasn't me" link keeps working until the change would have expired.

A change that can no longer apply, because an address has moved or the new one is taken, is cancelled when its confirmation tries to apply it. Its revert link stops working at once.

Changing the Password

PUT /user/password needs a fresh verification. A user with a password also sends their current one. Keyring checks both, then passes the request to your UpdateUserPassword action (published to app/Actions/Keyring/UpdateUserPassword.php), which validates and saves the new password.

Field
current_password Required when the user has a password. Keyring checks it itself with the Keyring\Rules\CurrentPassword rule, whatever your action does (OWASP ASVS 5.0.0, 6.2.3). A passkey or code proves who's signed in, not that they know the password.
password, password_confirmation The new password, checked against the password rules by the published action.
sign_out_others Optional boolean, true by default.

CurrentPassword works like Laravel's current_password rule, except that a password too long for the stored hash fails like a wrong one. With bcrypt, that's more than 72 bytes. Use the rule wherever your code asks for the current password:

PHP
use Keyring\Rules\CurrentPassword; $request->validate(['current_password' => ['required', 'string', new CurrentPassword($request->user())]]);

A user with no password, such as one who only uses passkeys, can set one with just a fresh verification, and so can whoever holds a copy of their session. A first password set through PasswordChanges::change() isn't established for 7 days. Until then it freezes sign-in methods, an ifEnrolled() policy doesn't ask for it, and it doesn't count when adding a second factor. A password reset makes it established at once. A first password your own code sets some other way is established from the start.

Your action may change only the password attribute. It must save a new password or throw a ValidationException. If it returns without saving, Keyring throws a LogicException.

The action runs while holding the user's row. The save goes ahead only if the session is still signed in and the stored password is still the one current_password was checked against. A change that a reset, or another session, overtook is refused.

Afterwards, Keyring regenerates the session ID and moves the session to a new registry record, so a copy of the old session is signed out. It cancels any pending email change, ends outstanding reset links, and stops trusting devices, this one included. It also clears the account's sign-in limits, so a password refused after too many wrong guesses works again. With sign_out_others, every other session is signed out and the "remember me" token changes. The response is the password-updated status response.

Warning

Your action's validation and hashing run inside that transaction, while the row is locked. If your code calls PasswordChanges::change(), don't wrap it in a transaction. Pass then: for work that must run after the change, and new: with the password the user chose, so a password a hold was placed over is refused.

Requiring a Password Change

Keyring never expires passwords. When there's evidence that a password is known to someone else, it can hold the user until they choose another, as NIST SP 800-63B-4 asks (Sec. 3.1.1.2). It places the hold itself when the BreachedPassword signal finds a breached password. For anything else, place it from your own code or a risk response:

PHP
use Keyring\Facades\Keyring; Keyring::requirePasswordChange($user, 'Reported phished on 12 November.'); Keyring::requiresPasswordChange($user);   // true until the password changesKeyring::cancelPasswordChange($user);     // the evidence was wrong

requirePasswordChange() returns false and does nothing for a user without a password, since holding them would lock them out. Then tell Keyring where your change-password form is:

PHP
// config/keyring.php'password_change_url' => '/settings/password',

While a user is held:

  • They can still sign in, but on signed-in requests in the web group they're sent to password_change_url with the change-password status. JSON requests get a 403 with that status and the URL as redirect. Without password_change_url, every page is a plain 403, so set it before you turn holds on.
  • Only the change-password page, PUT /user/password, the confirm page and the identity provider sign-in it offers, signing out, and email verification get through. Anything else is held, linking an identity provider included, unless you name its route in password_change_except.
  • Unnamed routes are always held. Name only routes that are safe while the password is compromised, such as read-only endpoints a headless frontend calls.
  • password_change_url gets past keyring.enrolled while they're held, so a user without a second factor isn't sent back and forth between it and the enrollment page. Once the hold ends, the page asks for a second factor again. Serve only the change-password page at that path. Routes in password_change_except don't get past keyring.enrolled.
  • The hold ends when the password changes through PUT /user/password or a password reset. The new password must differ from the current one. PUT /user/password refuses the current password for everyone.
  • A reset to the same password goes through like any other, but leaves the hold in place, so the form doesn't reveal that the guess was right.
  • The hold remembers the password it was placed over. Changing back to that password through PUT /user/password is refused with the password_held message, for a year after the hold is lifted (PasswordHold::KEEP_LIFTED_FOR, 365 days). A password reset to it goes through, puts the hold back in force, and dispatches PasswordChangeRequired again.
  • Keyring::cancelPasswordChange() deletes the hold at once.
  • The hold lives in the keyring_password_holds table, so signing out and back in changes nothing. A hold placed during a request applies to that session straight away, and other sessions find out within a minute.

The optional reason is kept on the row, and Keyring\Changes\PasswordHolds::reason($user) returns it. Keyring dispatches Keyring\Events\PasswordChangeRequired with user and reason when a hold is placed. It doesn't email the user, so listen for the event if you want to.

If your app doesn't use Features::updatePasswords(), Keyring never sees the new password. Call Keyring::cancelPasswordChange($user) after you save one yourself, or held users stay held until a reset. Check that the password is new first, since that call doesn't.

For holds placed before the password-holds migration, see the upgrade notes in UPGRADE.md.

Warning

Naming keyring.* in password_change_except lets whoever has the password add sign-in methods, change the email address, and sign out sessions. A passkey added during the hold keeps working after the password changes. Name specific read-only routes instead.

Carrying On Afterwards

Keyring remembers the page a held user was heading for, and after they change their password, password-updated redirects there (JSON callers get it as redirect). The rules match after enrolling: the page must be one the browser navigated to, on your origin, for the same user, within an hour. The change-password page and pages opened from emailed links are never remembered.

The Keyring\Http\Middleware\RequirePasswordChange middleware does the check. It sits in the web group after the session middleware. If sessions.middleware is off, add keyring.password wherever you add keyring.session.

Password Rules

Keyring\Support\PasswordRules::for($user) returns the validation rules, which follow OWASP ASVS 5.0.0 (section 6.2). Standards lists them one by one. In short:

  • A password must be at least min_with_mfa characters (8) with a second factor, and min_without_mfa (15) without one. A second factor here is an authenticator that could meet AAL2, not a recovery code or email code. Removing the last one takes the password again, so Keyring checks its length then (see Removing Authenticators). Neither minimum can go below 8.
  • max is 128 characters, but only a hasher that reads a whole password, such as argon2id, reaches it. Bcrypt ignores anything past 72 bytes, so with bcrypt Keyring refuses longer passwords. Set HASH_DRIVER=argon2id to accept every password up to max. See Passwords.
  • There are no composition rules. Any characters are accepted, including spaces, punctuation and emoji.
  • Breached passwords are refused in production by default. Laravel lets a password through when Have I Been Pwned can't be reached, unless you set passwords.refuse_unchecked.
  • The most common passwords are always refused, whatever their case, from a list that ships with Keyring (SecLists, MIT licensed; see resources/passwords/README.md).
  • Passwords built from context-specific words are refused, and the confirmed rule applies.

Keyring converts each password to Unicode's NFC form before it measures, hashes or checks it, as NIST SP 800-63B-4 recommends (Sec. 3.1.1.2). The same "é" can be one code point on one keyboard and two on another. Keyring's routes normalise input for you. If your code sets a password, such as in a seeder, normalise it first:

PHP
$user->password = Hash::make(PasswordRules::normalize($password));

Calling PasswordRules::for() with no user applies the stricter, no-MFA minimum, which registration uses. Pass the name and email yourself, as the published CreateNewUser does.

Context-Specific Words

A password that's only the name of your application or company is easy to guess. OWASP ASVS 5.0.0 (6.1.2) asks you to keep a list of such words, and 6.2.11 asks you to refuse passwords built from them. Put them in passwords.context:

PHP
'passwords' => [    'context' => ['Acme', 'Acme Rockets', 'Roadrunner', 'Wile E'],],

Include your products, systems, projects, departments and roles. Keyring adds these itself:

Source From
Your application's name app.name
The words you list passwords.context
The user's name Their name, or the context argument at registration
Their email username What's before the @ in their username and email attributes
Their organisation The first label of their email domain, such as megacorp in megacorp.example. Skipped for public providers such as Gmail and Outlook.

A password is refused when, with its digits, spaces and punctuation removed, it is one of these words, or several run together. So acme2026!, acmeacmeacme and Grace.Hopper.1906 (for a user named Grace Hopper) are refused. A longer passphrase that contains a word still passes, such as acme sells the best anvils.

The matching is forgiving in two ways. Case doesn't matter, and each value also counts word by word, so Acme Rockets counts as acme and rockets. Lookalike characters count as the letters they stand in for, so k3yr1ng counts as keyring. Words under four characters don't count, since they turn up by chance. Your application's name, and any listed entry as a whole, count from three characters.

The published actions take their rules from the app/Actions/Keyring/PasswordValidationRules.php trait. To add to them, pass a callback that receives the Password rule, already sized for the user:

PHP
use Illuminate\Validation\Rules\Password; protected function passwordRules((Authenticatable&Model)|null $user = null, array $context = []): array{    // Administrators need 20 characters, second factor or not.    return PasswordRules::for($user, fn (Password $rule) => $user?->is_admin ? $rule->rules(['min:20']) : $rule, $context);}

Ask for more length rather than particular kinds of character. Rules such as mixedCase() or symbols() take the application out of OWASP ASVS 5.0.0 (6.2.5), which wants any composition accepted.

Resetting the Password

Send email to POST /forgot-password. If the address has an account, Keyring sends a reset link. The answer is always the reset-link-sent status response, and the email goes out after the response.

The email is Laravel's ResetPassword notification, sent through your user model's sendPasswordResetNotification(). Keyring builds its link from APP_URL, unless you've already set ResetPassword::createUrlUsing(). The reset page is sent with Referrer-Policy: no-referrer, so the token in its URL doesn't leak through the referrer.

POST /reset-password takes token, email, password and password_confirmation. A bad token, or an address with no account, gets the same error on email. Once the token is accepted, your ResetUserPassword action (published to app/Actions/Keyring/ResetUserPassword.php) checks the rules and saves the password. It may only change the password, and it must save or throw. Then Keyring:

  • Revokes every session and changes the "remember me" token.
  • Cancels any pending email change, and lifts any risk lock.
  • Unlinks every identity provider on the account, dispatching AuthenticatorRemoved for each, since each stood in for the password. Second factors stay.
  • Clears the account's sign-in lockouts. A password or passkey refused at the cap works again, but second factors keep theirs.
  • Dispatches Keyring\Events\PasswordReset and Laravel's Illuminate\Auth\Events\PasswordReset, then redirects to the login page with password-reset. It never signs the user in.

A finished reset also proves the address: where registration hides who has an account, it marks the address verified, and it makes a first password set from a session established. Once the new password is saved, the sessions are signed out and the identity providers unlinked even if a later step fails. Each step is still tried, and then the failure is thrown.

A reset uses Laravel's password broker, so two settings in config/auth.php matter:

PHP
'passwords' => [    'users' => [        'provider' => 'users',        'table' => 'password_reset_tokens',        'expire' => 60,        'throttle' => 60,    ],],

throttle is the number of seconds an account waits between reset links. It's the only limit on how often one account is mailed. Keyring's own limit on POST /forgot-password is per sender, so many senders can still ask about one account. Keep throttle at 60, the Laravel default. The conformance suite fails when it's missing or zero.

expire is how many minutes a link works for. NIST SP 800-63B-4 (Sec. 4.2.1.2) asks for 24 hours at most, and Keyring doesn't cap it, so don't raise it past 1440.

A reset link stops working once the password changes through Keyring, the email address changes, or the user is deleted. A reset works while an account is locked, and it lifts the lock, so a lock can't keep the owner out for good.

Email Verification

With Features::emailVerification() on, Keyring provides Laravel's verification routes, plus the verify-email page that asks the user to check their inbox and the email-verification page that the emailed link opens. Links are built from APP_URL and signed over the path only, with keyring.signed:relative (Laravel's signed middleware, with refused links logged), so a forged Host header can't redirect them.

Laravel verifies an address as soon as the link opens. Keyring doesn't. The link opens a page with a button, and only the button changes anything, so a mail scanner that fetches the link verifies nothing.

  • GET /email/verify/{id}/{hash} renders email-verification with email, url, expires and signature. It changes nothing.
  • A POST to url, with expires and signature in the body, verifies the address:
Blade
<form method="POST" action="{{ $url }}">    @csrf    <input type="hidden" name="expires" value="{{ $expires }}">    <input type="hidden" name="signature" value="{{ $signature }}">    <button>Verify {{ $email }}</button></form>

Both steps need the user signed in as the account the link was sent to. Anyone else gets a 403. A signed-out browser is sent to log in and then back to the link. The link expires after auth.verification.expire (60 minutes by default), or when the account's address changes. After verifying, users go to home with ?verified=1.

With registration that doesn't reveal who has an account, which is the default, a new user opens the link signed out and signs in. Signing in from that browser verifies the address, and it takes the link and the password together. You only need these pages if you set registration.reveal_taken.

Routes

Method URI Name Middleware
POST /user/email keyring.email.store auth, changes_middleware, limited
GET /user/email keyring.email.show auth
DELETE /user/email keyring.email.destroy auth
GET /email-changes/{change}/confirm/{token} keyring.email.confirm limited by keyring-pages
POST /email-changes/{change}/confirm keyring.email.confirm.store limited, session lock
GET /email-changes/{change}/revert/{token} keyring.email.revert limited by keyring-pages
POST /email-changes/{change}/revert keyring.email.revert.store limited
PUT /user/password user-password.update auth, changes_middleware, keyring-session-changes limiter, session lock
GET /forgot-password password.request guest
POST /forgot-password password.email guest, limited
GET /reset-password/{token} password.reset guest
POST /reset-password password.update guest, limited
GET /email/verify verification.notice auth
GET /email/verify/{id}/{hash} verification.verify signed, limited by keyring-pages
POST /email/verify/{id}/{hash} verification.verify.store auth, signature in the body, limited
POST /email/verification-notification verification.send auth, limited

"Limited" means the keyring rate limiter, 6 a minute. The GET routes for emailed links use keyring-pages, 60 a minute per IP address, so opening a link doesn't use up the tries its button gets. The email routes need Features::emailChanges(), the password route Features::updatePasswords(), the reset routes Features::resetPasswords(), and the verification routes Features::emailVerification().

Five of these refuse anyone impersonating the user: POST and DELETE /user/email, PUT /user/password, and the verification store and send routes. GET /user/email, GET /email/verify, and the POSTs for emailed links aren't refused.

Events

These are in Keyring\Events:

Event Properties
EmailChangeRequested user, change
EmailChanged user, change
EmailChangeReverted user, change
PasswordChanged user
PasswordReset user
PasswordChangeRequired user, reason
ProtectionBypassed reason
LinkRefused link, reason, user. Dispatched for an email change link with a wrong or ended token, a reset with a token that wasn't the one sent, or a signed link that didn't check out.

change is a Keyring\Models\PendingChange. Its tokens, addresses and previous value are hidden from serialisation, and its addresses are encrypted at rest.

Keyring also dispatches Laravel's Illuminate\Auth\Events\PasswordReset alongside its own PasswordReset, so listeners for either work.