Skip to content

Commit 2bcf4e8

Browse files
committed
docs(auth): a spent refresh token with the digest key derives its family's live one
The reviewers noted that derived successors chain, so the security docs now say so. Also rewraps the comments this change left long.
1 parent 0bbd51c commit 2bcf4e8

5 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎apps/auth-service/src/oidc/tests/tokens.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ async fn code_replay_revokes_its_refresh_family() {
235235

236236
/// The same refresh token, refreshed on two replicas at once: a public client's
237237
/// rotates once, and both refreshes answer with that one successor. Presented
238-
/// after the reuse window, the old token is a replay, which revokes the family. A confidential client's serves both and
239-
/// stays valid.
238+
/// after the reuse window, the old token is a replay, which revokes the family.
239+
/// A confidential client's serves both and stays valid.
240240
#[tokio::test]
241241
#[ignore = "requires TEST_DATABASE_URL"]
242242
async fn concurrent_refreshes_across_replicas() {

‎crates/database/src/repositories/tokens/mod.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ pub const REFRESH_REUSE_SECONDS: f64 = 10.0;
5858
/// What redeeming a refresh token does to it, set by the client's kind.
5959
///
6060
/// Rotation detects a stolen bearer token: whichever of the thief and the client
61-
/// redeems second replays a consumed token and revokes the family. A confidential
62-
/// client's token is useless without its secret, so it needs no rotation
63-
/// (RFC 9700 §4.14), and its refresh becomes a read.
61+
/// redeems second, after the reuse window or once the successor is used, replays
62+
/// a consumed token and revokes the family. A confidential client's token is
63+
/// useless without its secret, so it needs no rotation (RFC 9700 §4.14), and its
64+
/// refresh becomes a read.
6465
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6566
pub enum RefreshRedemption {
6667
/// Marks the token consumed. The caller adds its replacement to the family

‎docs/dev/architecture/oidc.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ HMAC of the replaced token's secret, under a key derived from the token digest
192192
key and keyed by the successor's ID (`TokenDigestKeys::successor`). A retry
193193
presents the replaced token, so auth derives the successor again and checks it
194194
against the stored digest. The database holds nothing usable, not even sealed:
195-
deriving a successor takes both the key and the token it replaced, and auth
196-
does it for a retry only within the window.
195+
deriving a successor takes both the key and the token it replaced. Successors
196+
form a chain, though. Anyone with the key, the successor IDs from a database
197+
read and any earlier token of a family, however old, can derive its live token.
198+
So a spent token is only harmless while the key stays secret.
197199

198200
A family whose client no longer allows refresh, its audience or its scopes is
199201
revoked on its next use (`policy_rejected`). A refresh may narrow the scopes,

‎docs/dev/security/threat-model.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ own. It builds on the [security boundaries](boundaries.md); the
7979
| Threat | Mitigation |
8080
| --- | --- |
8181
| Rewriting or deleting history | The runtime role cannot change sealed events or checkpoints. Through the schema owner, changes break the hash chain or the signed checkpoints, and `audit verify` names the first position that no longer matches ([audit history](audit-history.md)). Auth's own verification, at least every six hours, raises an alert that notifies every administrator. |
82-
| Reading secrets from a dump | Signing keys are sealed under a key the database never holds. Cookies, client secrets, codes, refresh tokens and emailed links' tokens are stored only as digests ([boundaries](boundaries.md#secrets-and-keys)). |
82+
| Reading secrets from a dump | Signing keys are sealed under a key the database never holds. Cookies, client secrets, codes, refresh tokens and emailed links' tokens are stored only as digests ([boundaries](boundaries.md#secrets-and-keys)). A dump with the token digest key and any spent refresh token of a public client's grant derives the grant's live token ([refresh tokens](../architecture/oidc.md#refresh-families)). |
8383
| A bug in auth bypassing a way-in rule | Database triggers hold the recovery rules a way in depends on, for every writer ([database backstops](account-recovery.md#database-backstops)). |
8484

8585
Beyond these, database access is trusted: it can bind any passkey to any account

‎packages/auth/src/login.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export class Login {
200200
/**
201201
* Signs users in with `client`, as `options` say. A public client, which has no
202202
* secret, throws a `TypeError`: its refresh token rotates, so a copy of the
203-
* session cookie refreshing more than a few seconds after another would revoke it. Invalid options throw one too.
203+
* session cookie refreshing more than a few seconds after another would revoke
204+
* it. Invalid options throw one too.
204205
*/
205206
constructor(client: Client, options: LoginOptions) {
206207
const { scopes = [], afterLogin = '/', afterLogout, mount = '/auth' } = options;

0 commit comments

Comments
 (0)