fix(sharing): invitations need a fresh proof and end with sign out everywhere

Offering access to the record took a live session alone, and an
invitation outlives the session that sent it: whoever held a stolen
session could invite their own account and keep a way into the record
after the owner signed everything out. POST /api/account/grants now takes
the recent-proof gate at every level (a sign-in or re-proof within five
minutes on the browser, with the second factor on an account that has one;
a step-up elevation on a token, which no shipped client uses here), and
the invite form opens the re-proof dialog and sends again.

Sign out everywhere now withdraws every invitation the account offered
that nobody has accepted. Accepted grants are left standing on purpose:
each is a person the owner chose, often a carer who still needs the
record, and a sign-out button must not quietly cut them off. The response
lists them as grantsKept and the sessions card shows each with a one-click
End access.
This commit is contained in:
Marc-André Bombeck committed 2026-09-26 22:34:21 +02:00
1 parent a4d27c618e
commit a294d7f684
22 files changed
+585 -65

No files matched your search

+19
View File
@@ -575,6 +575,15 @@ export type CurrentCredential =
* and the web offers to keep them because a link already handed to a
* doctor is often wanted. The caller's own credential is spared either way.
*
* `everything` also withdraws every record-sharing invitation this account
* offered that nobody has accepted yet. An invitation outlives the session
* that sent it, so one offered from a stolen session would be waiting for
* the thief's own account to accept it. Accepted grants are NOT ended here:
* they are a person the owner chose (a partner, a carer), usually still
* wanted, and ending them silently would cut a carer off without anyone
* deciding to. The route lists them in its answer instead, and the web
* offers to end each one with a click.
*
* Returns what was removed, so the surface and the audit row can say what
* happened.
*/
@@ -586,6 +595,7 @@ export interface SignOutResult {
accessTokensRevoked: number;
connectorsRevoked: number;
shareLinksRevoked: number;
pendingInvitesRevoked: number;
}
export async function destroyOtherSessions(
@@ -655,6 +665,7 @@ export async function destroyOtherSessions(
accessTokensRevoked: access.count,
connectorsRevoked: 0,
shareLinksRevoked: 0,
pendingInvitesRevoked: 0,
};
}
@@ -680,11 +691,19 @@ export async function destroyOtherSessions(
where: { userId, revokedAt: null },
data: { revokedAt },
});
// Offered by this account and not accepted yet: `acceptedAt` null, not
// already ended. Stamped rather than deleted, so the consent record still
// shows the invitation and who withdrew it.
const invites = await tx.accountGrant.updateMany({
where: { grantorId: userId, acceptedAt: null, revokedAt: null },
data: { revokedAt, revokedBy: "GRANTOR" },
});
return {
sessionsRevoked: deleted.count,
accessTokensRevoked: access.count + tokens.count,
connectorsRevoked: connectors.count,
shareLinksRevoked: links.count,
pendingInvitesRevoked: invites.count,
};
});
}