> ## Documentation Index
> Fetch the complete documentation index at: https://docs.theauth.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Persistent sessions threat model

> Assets, threats, mitigations and residual risks of the opt-in "keep me signed in" feature.

Scope: the opt-in [persistent sessions](https://docs.theauth.dev/persistent-sessions.md) feature (`auth.session.persistent`), which sits next to cookie sessions.

## Assets

| Asset | Held where | Notes |
| - | - | - |
| Remember token | `HttpOnly`, `SameSite=Lax` cookie, or a native client's secure storage | A device id plus a random or derived verifier. The database keeps only SHA-256 of the verifier, for the current and past generations. |
| Refreshed session token | Session cookie | Signed with the session secret like any session token. Its nonce is derived from the remember secret. |
| `persistent.secret` | Your secret store and every instance | Derives successor tokens, signs the intent cookie and keys the per user security stamp. |
| Intent cookie | Browser, 10 minutes | Signed and not a credential. It says that one sign-in flow asked to be remembered. |
| Device rows | Database | User agent, client IP address, label and times. Anonymizing or deleting a user erases them. |

## Threats and mitigations

| Threat | Mitigation | Limit |
| - | - | - |
| Database read | Only verifier hashes are stored. | Device rows expose user agent, IP address and label. |
| Cookie theft | The token rotates on every refresh. Devices have an idle timeout and an absolute lifetime counted from the original sign-in. Users and your server can revoke a device. | Until it rotates or ends, a stolen remember cookie can mint a session. Tokens are not bound to an IP address or a device key. |
| Replay of an old token | A token older than the previous one, or a previous one whose successor was used, revokes the device and its session, writes `session.reuse_detected` and calls `onReuse`. | See the grace window and lost response items below. |
| Parallel refreshes | One conditional update per rotation, so instances agree on a single successor. Requests inside the grace window get identical cookies without any plain text token being stored. | A thief inside the window looks like a second tab. |
| CSRF on refresh | `POST` only, with a required trusted `Origin` or `Referer`, or `Sec-Fetch-Site: same-origin`. | Origins you list as trusted may refresh. |
| Planted remember cookie on sign-in | Routes that answer with a token in JSON set the remember cookie on `POST` only for JSON requests that name no untrusted origin, on `GET` only for requests from a trusted source, for One Tap after its double submit check, or, for a link opened from email, on a choice the same browser made earlier. | Anyone who can write cookies for your domain, such as a hostile sibling subdomain, is outside what cookies can defend against. |
| Planted or stale intent | The intent cookie is bound to the flow that set it and dropped when another sign-in starts. | |
| Account switching on a shared browser | A new sign-in ends the previously remembered device, and a refresh never changes the user of a live session. | |
| Interception in transit | With an `https` base URL, refresh over plain http is refused. | A trusted proxy is believed about the original protocol. |
| Session fixation | Remember tokens are minted by the server for a session it issued. Each refresh creates a new session id and revokes the old session. | |
| Quiet privilege gain | A refreshed session keeps the original methods, authentication time and sign-in time. It is never elevated or counted as fresh. | A refresh does not repeat the second factor. |
| Access after the account changes | Sign-out, revocation, password change and reset, TOTP removal, ban, forced password change, deletion and SCIM deprovisioning end devices. Every rotation or replay rechecks the user and runs `check`. A changed password hash or TOTP enrolment is also noticed at the next refresh. | See revocations outside theAuth below. |
| Sign-out racing a refresh | The device is revoked before its session. A refresh that loses the race fails its conditional update, or sees the revocation on its final read and revokes the session it made. | |
| Forced sign-out by guessing | Ending a device needs a token from its history, a session of its owner or server side access. A wrong verifier revokes nothing, and the refresh route is rate limited. | Whoever holds any past token of a device can end it. That is the intended response to theft. |
| Outage turned into mass sign-out | Storage errors and `check` errors answer `refresh_unavailable` and revoke nothing. | Users cannot refresh until the dependency returns. |
| Secret compromise | The secret alone yields no session: stored hashes cannot be reversed, and derivation also needs a presented token. `previousSecrets` allows rotation without downtime. | The secret together with any past token of a device lets an attacker compute later tokens derived under it. Replace the secret without keeping the old one and revoke the remembered devices. |

## Residual risks

* A token stolen and replayed within the grace window (30 seconds by default) gets the same successor.
* The lost response rule allows one extra rotation from the previous token after the grace window when the successor was never used. A thief who replays it before the real client returns gets one session. The real client's next refresh then trips reuse detection.
* Revocations made outside theAuth, such as deleting session rows with SQL, do not end the device. Use `theauth.persistentSessions`.
* Rows left from a period when the feature was turned off are not kept up to date. [Empty the tables](https://docs.theauth.dev/persistent-sessions-upgrade.md#turn-it-off-again) before turning it back on.
* Cross-site scripting on your origin can call the refresh route from the victim's browser, even though it cannot read the `HttpOnly` cookies.

## Operating it

Keep the secret out of source control, never log cookie values, set `trustedProxy` correctly so rate limits and transport checks see real values, and alert on `session.reuse_detected`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.