mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
fix(auth): sign out the other devices, lose a refresh to a revocation, key the replay cache by authority
"Sign out everywhere" revoked every other refresh token and nothing else. A native login is two rows, and the Bearer check consults only the paired access token, so the other phones kept working until that token expired, up to a day on the default policy. The route also handed destroyOtherSessions a session-kind credential for a Bearer caller, whose session.id is the ApiToken row id; the exception matched nothing and the calling phone revoked its own refresh token. destroyOtherSessions now finds the paired access tokens through the refresh rows and revokes them inside the same transaction, reporting the count, and the route names a Bearer caller by its access-token hash. Programmatic tokens are untouched. rotateRefreshToken marked the consumed row under usedAt: null alone, so a revocation landing between the read and the write was overtaken and a pair minted after the family ended stayed live. The guard now includes revokedAt: null; on a lost race the minted pair is retired and the reason distinguishes a revoked family from a double consume. withIdempotency consulted the grant only at replay time, and only for its existence; a narrow-scoped token was checked only on the delegated arm. Both move into the cell key: a delegated cell carries the grant's id, level and scope fingerprint, a narrow token's cells carry the token, and a request with no live grant neither reads nor claims a cell. Cookie and wildcard own-record cells are keyed byte-for-byte as before. Tests: integration for the paired access tokens (cookie and Bearer caller), a deterministic revoke-mid-rotation race against Postgres, unit coverage for the new cell keys, and the structural guard moved to the new invariant.
This commit is contained in:
1 parent
a262cf7bb1
commit
076c2f9c5d
9 files changed
+659
-105
No files matched your search
@@ -3108,23 +3108,33 @@ describe("(h) the guardian route set is frozen", () => {
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
describe("(i) delegated replay is re-authorized", () => {
|
||||
it("checks the current grant before returning a cached delegated body", () => {
|
||||
const replay = functionSource(
|
||||
"lib/idempotency.ts",
|
||||
"canReplayDelegatedResponse",
|
||||
);
|
||||
expect(replay.length).toBeGreaterThan(0);
|
||||
expect(replay).toContain("findActiveGrant");
|
||||
expect(replay).toContain("grantorId: recordUserId");
|
||||
expect(replay).toContain("granteeId: actorUserId");
|
||||
// v1.38.11 — the grant is no longer consulted at replay time; it is folded
|
||||
// into the cell key BEFORE any cell is read or claimed (`delegatedGrantFacet`),
|
||||
// so a replaced or narrowed grant cannot reach a cell filled under the wider
|
||||
// one. The invariant this pins moved accordingly: the grant lookup names the
|
||||
// right pair, it happens before `findCached`, and a missing grant leaves the
|
||||
// wrapper without touching a cell.
|
||||
it("resolves the current grant into the cell key before any cell is read", () => {
|
||||
const facet = functionSource("lib/idempotency.ts", "delegatedGrantFacet");
|
||||
expect(facet.length).toBeGreaterThan(0);
|
||||
expect(facet).toContain("findActiveGrant");
|
||||
expect(facet).toContain("grantorId: recordUserId");
|
||||
expect(facet).toContain("granteeId: actorUserId");
|
||||
expect(facet).toContain("grant.id");
|
||||
expect(facet).toContain("grant.access");
|
||||
expect(facet).toContain("scopeJson");
|
||||
|
||||
const wrapper = functionSource("lib/idempotency.ts", "withIdempotency");
|
||||
expect(wrapper.length).toBeGreaterThan(0);
|
||||
expect(wrapper).toContain("claimedRecord === undefined");
|
||||
const authorization = wrapper.indexOf("canReplayDelegatedResponse");
|
||||
const authorization = wrapper.indexOf("delegatedGrantFacet(");
|
||||
const noGrant = wrapper.indexOf("grantFacet === null");
|
||||
const cacheRead = wrapper.indexOf("findCached(ctx)");
|
||||
const replayReturn = wrapper.indexOf("return cached.response");
|
||||
expect(authorization).toBeGreaterThan(-1);
|
||||
expect(replayReturn).toBeGreaterThan(authorization);
|
||||
expect(noGrant).toBeGreaterThan(authorization);
|
||||
expect(cacheRead).toBeGreaterThan(noGrant);
|
||||
expect(replayReturn).toBeGreaterThan(cacheRead);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user