Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Fix: purge plaintext IndexedDB snapshots when a deck is encrypted (review H1)

nyblnet4192c444a478
diff --git a/slides/src/autosave.ts b/slides/src/autosave.ts
index fa8f8db0..e8c854ff 100644
--- a/slides/src/autosave.ts
+++ b/slides/src/autosave.ts
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento/Suite authors
// Local auto-save + lightweight version history, backed by IndexedDB.
//
// Two concerns, one store:
@@ -84,6 +86,14 @@ export async function clearRecovery(docId: string): Promise<void> {
await tx(RECOVERY, 'readwrite', (s) => s.delete(docId))
}
+/** Delete every version-history snapshot for a docId. Used when a deck is
+ * encrypted: the plaintext snapshots written before encryption was enabled must
+ * not linger in IndexedDB (they'd defeat the encryption the user just turned on). */
+export async function clearVersions(docId: string): Promise<void> {
+ const all = await listVersions(docId)
+ await Promise.all(all.map((v) => tx(VERSIONS, 'readwrite', (s) => s.delete(v.id!))))
+}
+
export async function addVersion(doc: BentoDoc): Promise<void> {
await tx(VERSIONS, 'readwrite', (s) =>
s.add({ docId: doc.docId, at: Date.now(), title: doc.title, json: JSON.stringify(doc) } as Snapshot))
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 6f3001a8..c59ffbda 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento/Suite authors
// Editor shell: topbar, slide sidebar, canvas, properties panel, keyboard
// shortcuts, save & present wiring.
@@ -16,7 +18,7 @@ import { SlideCanvas } from './canvas'
import { PropsPanel } from './panels'
import { startPresentation } from '../present'
import { hasFileHandle, isEncryptionActive, saveFile, serializeAuto, serializeFile, setEncryptionPassword, writeUpdatedFile, writeUpdatedFileAs } from '../save'
-import { addVersion, clearRecovery, docContentKey, getRecovery, listVersions, pruneOld, putRecovery, type Snapshot } from '../autosave'
+import { addVersion, clearRecovery, clearVersions, docContentKey, getRecovery, listVersions, pruneOld, putRecovery, type Snapshot } from '../autosave'
import { insertElements, insertSlides, parseClip, serializeElements, serializeSlides } from './clipboard'
import { refreshScreensIfGranted } from '../screens'
import { ICONS } from '../icons'
@@ -489,6 +491,13 @@ export class Editor {
const pass = await this.promptPassword()
if (pass === null) return
setEncryptionPassword(pass)
+ // Purge any plaintext snapshots already written to IndexedDB before encryption
+ // was enabled — otherwise up to MAX_VERSIONS version snapshots + a recovery copy
+ // (full plaintext JSON, incl. collab keys) would linger ~30 days, defeating the
+ // encryption the user just turned on.
+ const docId = this.store.doc.docId
+ await clearRecovery(docId)
+ await clearVersions(docId)
this.toast(t('Encrypted — remember this password; it cannot be recovered'))
void this.save(true)
}