fix(auth): end connected assistants, tokens and share links on sign-out everywhere

"Sign out everywhere" ended web sessions and device logins but left every
credential that works without signing in: a connected AI assistant kept its
OAuth connection and minted the next access token from it, a connector or
ingest token kept working, and a clinician share link kept opening the
record. A password change revoked the tokens but not the assistant's
connection or the share links. Anything a stolen session had minted
outlived the remedy.

- Sign out everywhere now ends every other sign-in, every AI-assistant
  connection, every programmatic token except the caller's own, and every
  clinician share link. Share links are revoked by default; the web offers
  a checkbox to keep them (keepShareLinks=1), and a client that sends
  nothing, such as the shipped app, gets the safe default.
- A password change and an admin password reset also end AI-assistant
  connections, share links and step-up elevations.
- Turning on the first second factor (TOTP or a security key) ends every
  other sign-in, as a password change does. Adding a further factor does
  not.

destroyOtherSessions takes an explicit reach ("sign-ins" or "everything")
so each caller says how far it goes.
This commit is contained in:
Marc-André Bombeck committed 2026-09-26 20:06:36 +02:00
1 parent 0fc83cb0a1
commit 92c5b0a60d
23 files changed
+658 -66

No files matched your search

@@ -16,6 +16,7 @@ import { ChevronDown, Loader2, MonitorSmartphone } from "lucide-react";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardActions } from "@/components/settings/_card-actions";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { Checkbox } from "@/components/ui/checkbox";
import { ConfirmButton } from "@/components/ui/confirm-button";
import { EmptyState } from "@/components/ui/empty-state";
import { QueryErrorRow } from "@/components/ui/query-error-row";
@@ -43,6 +44,11 @@ export function SecuritySessionsCard({
const fmt = useFormatters();
const queryClient = useQueryClient();
const [status, setStatus] = useState<string | null>(null);
// "Everywhere" also ends clinician share links unless the person keeps
// them. Revoking is the default: this is often pressed after losing a
// device or a session, and a link made by whoever held it opens the record
// without signing in.
const [endShareLinks, setEndShareLinks] = useState(true);
// Collapsed by default — the list opens only when the user asks for it, so
// the security surface stays calm and skimmable on first paint. UI-only
// state; nothing is persisted across reloads.
@@ -69,7 +75,11 @@ export function SecuritySessionsCard({
const revokeOthers = useMutation({
mutationFn: () =>
apiDelete<{ sessionsRevoked: number }>("/api/auth/me/sessions"),
apiDelete<{ sessionsRevoked: number }>(
endShareLinks
? "/api/auth/me/sessions"
: "/api/auth/me/sessions?keepShareLinks=1",
),
onSuccess: (res) => {
setStatus(
t("settings.security.signOutEverywhereDone", {
@@ -85,7 +95,6 @@ export function SecuritySessionsCard({
});
const sessions = data?.sessions ?? [];
const hasOthers = sessions.some((s) => !s.isCurrent);
return (
<SettingsCard data-slot="settings-security-sessions-card">
@@ -185,7 +194,7 @@ export function SecuritySessionsCard({
</ul>
)}
{hasOthers && (
{data && (
<SettingsCardActions>
<ConfirmButton
slot="sign-out-everywhere"
@@ -196,6 +205,19 @@ export function SecuritySessionsCard({
confirmLabel={t("settings.security.signOutEverywhere")}
onConfirm={() => revokeOthers.mutate()}
pending={revokeOthers.isPending}
extra={
<label className="flex items-start gap-2 text-sm">
<Checkbox
data-testid="sign-out-everywhere-share-links"
checked={endShareLinks}
onCheckedChange={(next) => setEndShareLinks(next === true)}
className="mt-0.5"
/>
<span>
{t("settings.security.signOutEverywhereShareLinks")}
</span>
</label>
}
/>
</SettingsCardActions>
)}
+6
View File
@@ -52,6 +52,8 @@ interface ConfirmCopy {
pending?: boolean;
/** `data-slot` for tests and the design guards. */
slot?: string;
/** A control that belongs with the question, such as an opt-out checkbox. */
extra?: ReactNode;
}
function ConfirmBody({
@@ -61,6 +63,7 @@ function ConfirmBody({
onConfirm,
pending = false,
slot,
extra,
}: ConfirmCopy) {
const { t } = useTranslations();
@@ -70,6 +73,7 @@ function ConfirmBody({
<AlertDialogTitle>{title}</AlertDialogTitle>
<AlertDialogDescription>{body}</AlertDialogDescription>
</AlertDialogHeader>
{extra}
<AlertDialogFooter>
<AlertDialogCancel>{t("common.cancel")}</AlertDialogCancel>
<AlertDialogAction
@@ -102,6 +106,7 @@ export function ConfirmButton({
icon,
ariaLabel,
slot,
extra,
}: ConfirmCopy & {
/** The control's own label, before the dialog opens. */
label: string;
@@ -143,6 +148,7 @@ export function ConfirmButton({
onConfirm={onConfirm}
pending={pending}
slot={slot}
extra={extra}
/>
</AlertDialog>
);