54d245d5cf0f

L11/COR-008: rollback in-memory entries if persistEntries fails in addEntry

time
2026-05-16 05:26 UTC · 5 months ago
machine
koh2
parent
bd387b3b4237
1 file src/background/vault.ts+11 −2
src/background/vault.ts+11 −2
@@ -1465,8 +1465,17 @@14651465     passwordChangedAt: sanitized.password ? now : undefined,14661466   };14671467 1468-  entries.push(nextEntry);1469-  await persistEntries();1468+  // Clone-and-replace so a failed persist rolls back the in-memory state1469+  // (COR-008). Without this, a quota-full or storage error leaves the1470+  // module-level `entries` ahead of what's actually on disk.1471+  const rollback = entries;1472+  entries = [...entries, nextEntry];1473+  try {1474+    await persistEntries();1475+  } catch (err) {1476+    entries = rollback;1477+    throw err;1478+  }14701479 14711480   // Fire-and-forget breach check (only for login entries if breach monitoring is enabled or not set)14721481   if (settings.breachMonitoring !== false && nextEntry.type === "login" && nextEntry.password) {

view file