Files
cinny/src/app/state/recentStickers.ts
T
jaredandClaude Opus 4.8 726cefb5ab fix(privacy): wipe plaintext/PII localStorage caches on logout (SEC-1/2)
Several localStorage caches held decrypted message content or user PII and
survived a normal logout, leaving residue on a shared device (the search
index was already wiped; these were not):

- cinny_scheduled_messages_v1 - decrypted IContent.body of pending sends
- cinny_recent_searches_v1     - search query text
- cinny_recent_forward_targets_v1 - recent forward contact/room graph
- cinny_recent_gifs_v1 / cinny_recent_stickers_v1 - media the user sent
- navToActivePath<userId>       - per-space last-visited room paths
- (plus the translation cache added earlier)

Add a clear function per module and a single auditable clearPlaintextCaches()
aggregator, called from both logout paths (logoutClient + the server-forced
SessionLoggedOut handler) alongside the existing session/search-index wipes.
Unit-tested.

Deliberately NOT cleared (documented in the aggregator): unsent composer
drafts and the presence status message (preserved by product decision N98);
SDK sync/crypto store + io.lotus.* account data (reminders/bookmarks/notes),
already wiped by mx.clearStores(); low-sensitivity UI/metadata residue.

The forward-targets/gifs/stickers/nav-path additions and the accurate
"not covered" documentation address findings from two review passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 16:56:08 -04:00

64 lines
2.0 KiB
TypeScript

import { atom } from 'jotai';
import { atomWithStorage, createJSONStorage } from 'jotai/utils';
export type RecentSticker = {
/** mxc:// url of the sticker image. */
url: string;
shortcode: string;
body?: string;
};
const STORAGE_KEY = 'cinny_recent_stickers_v1';
const MAX_RECENT_STICKERS = 16;
// getOnInit reads localStorage synchronously so the Recent group is present on the
// first render of the sticker picker (no flash of the empty default).
const internalAtom = atomWithStorage<RecentSticker[]>(
STORAGE_KEY,
[],
createJSONStorage(() => localStorage),
{ getOnInit: true },
);
/**
* Global atom: the most recently sent stickers, newest first, deduped by url,
* capped at MAX_RECENT_STICKERS. Backed by localStorage (device-local
* convenience), mirroring `recentGifsAtom`.
*/
export const recentStickersAtom = atom(
(get): RecentSticker[] => get(internalAtom),
(_get, set, updater: RecentSticker[] | ((prev: RecentSticker[]) => RecentSticker[])) => {
set(internalAtom, (prev) => {
const prevList = Array.isArray(prev) ? prev : [];
return typeof updater === 'function' ? updater(prevList) : updater;
});
},
);
/**
* Prepend a sticker: ignores an empty url, de-dupes by url (moving an existing
* entry to the front), and caps the list at `max`. Pure — returns a new array.
*/
export const addRecentSticker = (
prev: RecentSticker[],
sticker: RecentSticker,
max = MAX_RECENT_STICKERS,
): RecentSticker[] => {
if (!sticker.url) return prev;
const withoutDupe = prev.filter((s) => s.url !== sticker.url);
return [sticker, ...withoutDupe].slice(0, max);
};
/**
* Wipe persisted recent stickers. Called on logout — these are stickers the
* user sent (mxc + label text) and must not surface under "Recent" to the next
* person on a shared device.
*/
export const clearRecentStickers = (): void => {
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
/* localStorage unavailable — nothing to clear */
}
};