fix(auth): reconcile step-up elevations with main at v1.32.0

Renumber the elevation migration from 0260 to 0267 — main claimed 0260
for an unrelated table while this branch sat unmerged, and 0266 is now
the highest committed number.

Two loose ends the merge itself did not touch: the schema comment on
StepUpElevation.method still called it "audit/telemetry only, never an
authorisation input" — the exact claim the fresh-factor fix (a prior
commit on this branch) made false, since the method is now precisely
what decides whether an elevation reaches the destructive MFA routes.
Reworded to match. And pruneExpiredStepUpElevations in step-up.ts was
dead code: the actual sweep runs in cleanup-handlers.ts against the
worker Prisma client for reasons that function could never satisfy
against the request-scoped one. Removed rather than left to drift.
This commit is contained in:
Marc-André Bombeck committed 2026-07-23 09:16:03 +02:00
1 parent 8119cc6c82
commit a2fc6ea243
3 files changed
+11 -18

No files matched your search

+6 -3
View File
@@ -3257,8 +3257,11 @@ model StepUpElevation {
// HMAC-SHA256 (`hashToken`) of the raw `hle_<64 hex>` secret. Unique so a
// redemption is a single indexed lookup and a collision cannot alias two rows.
tokenHash String @unique @map("token_hash")
// Which factor was re-proved: "password" or "passkey". Audit/telemetry only —
// never an authorisation input.
// Which factor was re-proved: "password", "totp", "webauthn", or "passkey".
// This IS an authorisation input, not telemetry — see `FRESH_FACTOR_METHODS`
// in `@/lib/auth/step-up`. Only totp / webauthn / passkey satisfy a
// fresh-factor gate; password reaches what a plain cookie session reaches
// and stops there.
method String
expiresAt DateTime @map("expires_at")
consumedAt DateTime? @map("consumed_at")
@@ -3270,7 +3273,7 @@ model StepUpElevation {
@@index([userId])
@@index([apiTokenId])
@@index([expiresAt])
// NOTE: migration 0260 additionally creates a PARTIAL unique index —
// NOTE: migration 0267 additionally creates a PARTIAL unique index —
// `(api_token_id) WHERE consumed_at IS NULL` — so at most one elevation per
// token is ever redeemable. Prisma cannot express a partial index, and a
// plain `@@unique([apiTokenId])` would be wrong: it would also forbid minting
+5 -15
View File
@@ -328,18 +328,8 @@ export async function revokeStepUpElevations(userId: string): Promise<void> {
await prisma.stepUpElevation.deleteMany({ where: { userId } });
}
/**
* Delete every elevation whose window has closed.
*
* Runs on the queue, not on a request. The earlier fire-and-forget sweep on the
* mint path was a cross-tenant unbounded DELETE competing with the request for a
* pool connection, and recurring work belongs on pg-boss. An expired row is
* already unredeemable — the predicate in `claimStepUpElevation` refuses it — so
* this is hygiene, not enforcement, and a missed run breaks nothing.
*/
export async function pruneExpiredStepUpElevations(): Promise<number> {
const { count } = await prisma.stepUpElevation.deleteMany({
where: { expiresAt: { lt: new Date() } },
});
return count;
}
// The expired-elevation sweep runs on the pg-boss queue against the WORKER
// Prisma client, not this module's request-scoped one — see
// `handleStepUpElevationCleanup` in `@/lib/jobs/reminder/cleanup-handlers`.
// A copy of the predicate here would be unreachable and only invite drift
// between the two, so it does not exist.