/** * PB-26-203: the session-key escrow is only as trustworthy as the boundary * around chrome.storage.session. This initializer positively establishes * trusted-only access on both storage areas before any session restore runs. * Where the browser cannot prove that state, the caller must disable the * escrow (fail closed) instead of trusting an unproven boundary. */ export type StorageHardening = { localHardened: boolean; sessionHardened: boolean; sessionEscrowAvailable: boolean; }; type AccessLevelArea = { setAccessLevel?: (options: { accessLevel: "TRUSTED_CONTEXTS" }) => Promise; }; async function setTrustedContexts(area: unknown): Promise { const typed = area as AccessLevelArea | undefined; if (typeof typed?.setAccessLevel !== "function") return false; try { await typed.setAccessLevel({ accessLevel: "TRUSTED_CONTEXTS" }); return true; } catch { // Optional browser hardening must never prevent the extension from // starting; the message policy remains the primary security boundary. return false; } } export async function hardenExtensionStorage(): Promise { const localHardened = await setTrustedContexts(chrome.storage?.local); const session = chrome.storage?.session; // No session area (older Firefox): no escrow exists to protect, so there // is nothing to harden — but escrow is still reported unavailable. const sessionHardened = session ? await setTrustedContexts(session) : false; return { localHardened, sessionHardened, sessionEscrowAvailable: sessionHardened }; }