Files
webmail/lib/offline/evicted-secrets.ts
T
Linus Rath a9e33ec2d6 fix: stop a page wiping another account's plugin secrets by naming it in the desktop app
A wipe by name took any username and server with no session behind it. It
now needs a sealed cookie the account got while it was signed in, since a
dropped account has no session cookie left. The old wipe test asserted that
a name alone was enough, which is the behaviour being removed.
2026-11-04 03:15:35 +01:00

25 lines
1.2 KiB
TypeScript

/**
* Plugin secrets of an account the app dropped, in the desktop app, where they sit
* on this device's own server. The account has no session cookie left to ask with, so
* the route takes who it was, from what was written down at the time, with the proof
* the account got while it was signed in. On an instance they aren't the device's to
* remove, and nothing is written down.
*/
import { apiFetch } from '@/lib/browser-navigation';
import { IS_DESKTOP_BUILD } from '@/lib/desktop/flag';
import { dropEvictedOwner, readEvictedOwners } from './state';
const BUDGET_MS = 3_000;
/** `account` null: everyone's. */
export async function forgetEvictedSecrets(account: string | null): Promise<void> {
if (!IS_DESKTOP_BUILD) return;
const owners = Object.entries(readEvictedOwners()).filter(([id]) => account === null || id === account);
await Promise.all(owners.map(async ([id, owner]) => {
const query = new URLSearchParams({ all: 'true', username: owner.username, server: owner.serverUrl });
const response = await apiFetch(`/api/plugin-secrets?${query}`, { method: 'DELETE', signal: AbortSignal.timeout(BUDGET_MS) }).catch(() => null);
if (response?.ok) dropEvictedOwner(id);
}));
}