Blank the consumed refresh token in the fallback marker write
When the rotation or revocation the provider's answer called for cannot be committed, the fallback write now clears refresh_token_encrypted as well as stamping the marker, so the end of the 60 s backoff cannot replay the consumed token. Tests (live Postgres, trigger-refused revoke) assert no replayable token and no second provider call. Docs: the marker is a best-effort write on a second connection after rollback, the skew cap, the blanking write's residual. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9c7d980165
commit
f2f1dabc06
3 changed files with 27 additions and 9 deletions
|
|
@ -867,10 +867,11 @@ export class PostgresStore implements HeimdallStore {
|
|||
if (decision?.kind === "rotate" || decision?.kind === "revoke") {
|
||||
// The provider answered and may have consumed the refresh token, and the rotation or the revoke its answer
|
||||
// called for (a rotating provider's missing refresh token) could not be committed: the rollback took the
|
||||
// answer with it. Leave the marker in a transaction of its own, so the next caller does not
|
||||
// present the old token. Best effort: if this write fails too, the original error is the one that matters.
|
||||
// answer with it. In a transaction of its own, blank the consumed token and leave the marker, so no later
|
||||
// caller, after the backoff either, presents it again. Best effort: if this write fails too, the original
|
||||
// error is the one that matters, and the residual is named in docs/service-contract.md.
|
||||
await client
|
||||
.query("UPDATE linked_identities SET refresh_failed_at = $2 WHERE id = $1", [id, decision.updatedAt])
|
||||
.query("UPDATE linked_identities SET refresh_token_encrypted = NULL, refresh_failed_at = $2 WHERE id = $1", [id, decision.updatedAt])
|
||||
.catch(() => undefined);
|
||||
}
|
||||
throw error;
|
||||
|
|
|
|||
Loading…
Reference in a new issue