Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

slides: a sealed deck's content stays out of IndexedDB (K3) (#785)

nyblnet5ad704157ab5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aede2813..55638cf7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2573,6 +2573,11 @@ jobs:
# neutral <title> and filename, no preview, and no plaintext; the
# unsealed control shows the same checks can see a leak.
run: node scripts/test-sealed-boot.mjs
+ - name: A sealed slides deck keeps its content out of IndexedDB in Chromium
+ # The autosave and ⌘S checkpoints write no recovery copy or version for
+ # a deck sealed by identity; the password menu stays keyed to the
+ # password; the unsealed control shows the scan sees a leak.
+ run: node scripts/test-slides-sealed-guards-browser.mjs
- name: Exercise the packaged documents in Chromium
# Real UI and serialization, offline; delayed mock writes expose save races.
run: |
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index 6fbd5d3e..5bdab317 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -11201,6 +11201,33 @@ Rigs: `tests/recovery.rs`, where each of these mutations turns a test red: the
old pepper labels, losing O→0 when reading a code, and skipping the range
check. Also `tests/secret_linux.rs` via `keyring-rig.sh`.
+
+## 2026-10-18 — slides: a sealed document never offers or keeps an unsealed snapshot
+
+Slides' plaintext-to-disk guards (the autosave's recovery copy and versions, the
+⌘S checkpoint, the recovery-off notice) use kernel's `isBodySealed()`, a password
+OR the identity seal. The password menu items stay on `isEncryptionActive()`,
+because they are about the password.
+
+When a document boots sealed, any recovery copy or versions stored for ITS docId
+by an earlier unsealed session are deleted, and no Restore banner or version
+history is offered. Another document's snapshots are untouched.
+
+Two consequences, both following from the rule:
+
+- **A sealed copy can delete the original's unsaved recovery.** "Save a copy…"
+ keeps the docId. If a password is set on the copy, the copy and the unsealed
+ original share a docId, so opening the sealed copy deletes the original's
+ recovery copy and versions in that browser, including unsaved work it was
+ holding. The original FILE is untouched.
+- **A player file does not purge.** A read-only player never builds the editor,
+ so it never offers or writes a snapshot. A leftover unsealed snapshot for its
+ docId stays until the deck is opened in the editor. Security accepted this as
+ a stated residual.
+
+Guard: `scripts/test-slides-sealed-guards-browser.mjs`.
+
+
## 2026-10-18 — bento/connect on Android (Bento ID): the agent's two keys, the routine session, and host-stamped consent
The Android agent core (phase-1 plan A1). It isn't wired to any page yet: the
diff --git a/scripts/test-slides-recovery-off-browser.mjs b/scripts/test-slides-recovery-off-browser.mjs
index c2f9a74f..ba84930d 100644
--- a/scripts/test-slides-recovery-off-browser.mjs
+++ b/scripts/test-slides-recovery-off-browser.mjs
@@ -99,13 +99,13 @@ console.log('\na host that keeps it (the control)\n')
ok(r.first.sets >= 1 && r.second.notices === 0 && r.first.text !== NOTICE, `no recovery-off message (${r.second.notices})`)
}
-console.log('\nnever for an encrypted deck\n')
+console.log('\nnever for a sealed deck (a password or the identity seal)\n')
{
const src = readFileSync(new URL('../slides/src/editor/editor.ts', import.meta.url), 'utf8')
const fn = src.slice(src.indexOf('private noticeRecoveryOff('), src.indexOf('private noticeRecoveryOff(') + 700)
ok(/onRecoveryOff\(\(docId\) => this\.noticeRecoveryOff\(docId\)\)/.test(src), 'the editor listens to the kernel\'s onRecoveryOff')
- ok(/if \(docId !== this\.store\.doc\.docId \|\| isEncryptionActive\(\) \|\| this\.recoveryOffSaid\.has\(docId\)\) return/.test(fn),
- 'the notice refuses an encrypted deck, another deck, and a second telling')
+ ok(/if \(docId !== this\.store\.doc\.docId \|\| isBodySealed\(\) \|\| this\.recoveryOffSaid\.has\(docId\)\) return/.test(fn),
+ 'the notice refuses a sealed deck, another deck, and a second telling')
}
console.log(`\n${checks - failures}/${checks} checks passed`)
diff --git a/scripts/test-slides-sealed-guards-browser.mjs b/scripts/test-slides-sealed-guards-browser.mjs
new file mode 100644
index 00000000..fc5ecde5
--- /dev/null
+++ b/scripts/test-slides-sealed-guards-browser.mjs
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// A sealed deck's content never reaches IndexedDB, and it never offers or keeps an unsealed snapshot.
+//
+// npm run build:sealtest --prefix slides && node scripts/test-slides-sealed-guards-browser.mjs
+//
+// WHAT THIS PROVES, on slides' build:sealtest shell through the shared helper
+// (scripts/lib/sealed-boot.mjs). A deck's body can be sealed by a password OR
+// by the identity seal; kernel's isBodySealed() covers both. Slides' guards on
+// plaintext-to-disk — the autosave's recovery copy and version checkpoint, the
+// ⌘S checkpoint, the "recovery is off" notice — used isEncryptionActive(), the
+// password alone, so an identity-sealed deck's edits were written in plaintext
+// to bento-slides-autosave (measured: recovery AND versions). Now:
+// 1. sealed: after an edit and past the autosave debounce, and again after a
+// ⌘S, no IndexedDB record carries the deck's content; the saved file is a
+// sealed envelope with a neutral <title>, no preview and no content;
+// 2. the password items stay keyed to the PASSWORD: a deck sealed by
+// identity, with no password, offers "Encrypt with password…", never
+// "Change password…" or "Remove password";
+// 3. control, the same shell unsealed: the same edit DOES reach IndexedDB,
+// so the scan can see a leak.
+// 4. a sealed document never offers or keeps an unsealed snapshot: after an
+// unsealed session leaves one (recovery + version) for its docId, a
+// sealed boot on the same storage shows no Restore banner, lists nothing
+// in version history, and deletes it; another document's snapshot
+// survives; control: an unsealed reboot DOES offer it back.
+// Mutations (each rebuilt, build exit checked): the autosave guard on
+// isEncryptionActive() → 1 red; the ⌘S checkpoint guard on it → the ⌘S row
+// red; the sealed boot skipping the delete → 4's delete row red; no sealed
+// branch at boot (the banner offered) → 4's banner and delete rows red.
+import { openSealed, savedFile, scanIndexedDB } from './lib/sealed-boot.mjs'
+const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright')
+
+let checks = 0
+let failures = 0
+function ok(cond, msg) {
+ checks++
+ if (!cond) { failures++; console.log(` FAIL ${msg}`) } else console.log(` ok ${msg}`)
+}
+const MARK = 'ZZSEALEDGUARD' + Date.now()
+
+// an edit: the marker into the title and the first text box, then past the
+// 2.5s autosave debounce
+async function edit(page) {
+ await page.evaluate((m) => {
+ const d = structuredClone(window.bento.doc)
+ d.title = m
+ const el = d.slides?.[0]?.elements?.find((e) => e.type === 'text')
+ if (el) el.html = `<p>${m}</p>`
+ window.bento.loadDoc(JSON.stringify(d))
+ }, MARK)
+ await page.waitForTimeout(4000)
+}
+async function saveMenu(page) {
+ await page.locator('.ed-split-caret').click()
+ const items = await page.locator('.ed-save-menu').innerText()
+ await page.keyboard.press('Escape')
+ await page.mouse.click(5, 880)
+ return items
+}
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+try {
+ console.log('sealed by identity (no password)\n')
+ {
+ const { page, context, errors } = await openSealed(browser, 'slides')
+ await page.evaluate(() => { try { localStorage.setItem('bento-slideshow-started', '1') } catch {} })
+ await edit(page)
+ ok(await page.evaluate((m) => window.bento.doc.title === m, MARK), 'the edit landed in the live deck (the scans below are real)')
+ const afterAutosave = await scanIndexedDB(page, MARK)
+ ok(afterAutosave.length === 0, `after the autosave: no IndexedDB record carries the content (${afterAutosave.join(', ') || 'none'})`)
+ // ⌘S: a download here (no file handle), then the save's own checkpoint.
+ // Headless Chromium HAS showSaveFilePicker, and a picker nobody answers is a
+ // cancelled save that returns before the checkpoint — so take it away, and
+ // require the download, or this step proves nothing.
+ await page.evaluate(() => { delete window.showSaveFilePicker })
+ const dl = page.waitForEvent('download', { timeout: 15000 }).catch(() => null)
+ await page.keyboard.press(process.platform === 'darwin' ? 'Meta+s' : 'Control+s')
+ ok(!!(await dl), '⌘S saved (a download), so the save checkpoint ran')
+ await page.waitForTimeout(800)
+ const afterSave = await scanIndexedDB(page, MARK)
+ ok(afterSave.length === 0, `after ⌘S: still none (${afterSave.join(', ') || 'none'})`)
+ const { file, body } = await savedFile(page)
+ const env = JSON.parse(body)
+ ok(env.format === 'bento/enc' && !file.includes(MARK) && !file.includes('data-bento-preview') && !/<title>[^<]*ZZSEALED/.test(file),
+ 'the saved file: a sealed envelope, neutral <title>, no preview, no content')
+ const menu = await saveMenu(page)
+ ok(/Encrypt with password/.test(menu) && !/Change password|Remove password/.test(menu),
+ 'the password items follow the password, not the seal: "Encrypt with password…" is offered, "Change"/"Remove password" are not')
+ ok(errors.length === 0, `no page error${errors.length ? ' — ' + errors[0] : ''}`)
+ await context.close()
+ }
+
+ console.log('\nunsealed control (same shell, no key handed over)\n')
+ {
+ const { page, context } = await openSealed(browser, 'slides', { sealed: false })
+ await edit(page)
+ const hits = await scanIndexedDB(page, MARK)
+ ok(hits.length > 0, `the unsealed edit DOES reach IndexedDB (${hits.join(', ') || 'none'}), so the scan can see a leak`)
+ await context.close()
+ }
+
+ // --- 4. a sealed document never offers or keeps an unsealed snapshot ----------
+ // Recovery is keyed by docId, so these boot FIXED documents, and share one
+ // IndexedDB across sessions through { context, url }.
+ console.log('\nan unsealed snapshot left from an earlier session\n')
+ const deck = (docId, text) => ({
+ format: 'bento/slides', version: 1, docId, title: `deck ${docId}`,
+ size: { width: 1280, height: 720 },
+ theme: { background: '#ffffff', color: '#1E2A3A', accent: '#f7a600', fontFamily: 'system-ui' },
+ slides: [{ id: 's1', background: '#ffffff', transition: 'none', notes: '', elements: [{ id: 't1', type: 'text', x: 100, y: 100, w: 600, h: 80, html: `<p>${text}</p>` }] }],
+ })
+ const MA = MARK + 'A', MB = MARK + 'B'
+ const editTo = async (page, m) => {
+ await page.evaluate((m) => {
+ const d = structuredClone(window.bento.doc)
+ d.slides[0].elements[0].html = `<p>${m}</p>`
+ window.bento.loadDoc(JSON.stringify(d))
+ }, m)
+ await page.waitForTimeout(4000) // past the autosave debounce
+ }
+ const banner = (page) => page.waitForSelector('.ed-recover', { timeout: 2500 }).then(() => true, () => false)
+ async function versionRows(page) {
+ await page.locator('.ed-split-caret').click()
+ await page.locator('.ed-save-menu').getByText('Version history…', { exact: true }).click()
+ await page.waitForSelector('.ed-version-box', { timeout: 3000 })
+ const n = await page.locator('.ed-version-box .ed-version-row').count()
+ await page.evaluate(() => document.querySelector('.ed-about-overlay')?.remove())
+ return n
+ }
+
+ // control: unsealed, then unsealed again on the same storage — the banner IS offered
+ {
+ const first = await openSealed(browser, 'slides', { sealed: false, doc: deck('rig-sealed-ctl', 'original') })
+ await editTo(first.page, MA)
+ ok((await scanIndexedDB(first.page, MA)).length > 0, 'control: the unsealed edit left a snapshot')
+ await first.page.close()
+ const again = await openSealed(browser, 'slides', { sealed: false, context: first.context, url: first.url })
+ ok(await banner(again.page), 'control: an unsealed reboot DOES offer it back (the checks below can see an offer)')
+ ok(await versionRows(again.page) > 0, 'control: and its version history lists it')
+ await first.context.close()
+ }
+ // sealed boot over a leftover snapshot, beside another document's snapshot
+ {
+ const a = await openSealed(browser, 'slides', { sealed: false, doc: deck('rig-sealed-a', 'original') })
+ await editTo(a.page, MA)
+ const b = await openSealed(browser, 'slides', { sealed: false, doc: deck('rig-sealed-b', 'original'), context: a.context })
+ await editTo(b.page, MB)
+ ok((await scanIndexedDB(b.page, MA)).length > 0 && (await scanIndexedDB(b.page, MB)).length > 0, 'two unsealed sessions left a snapshot each (A and B)')
+ await a.page.close()
+ await b.page.close()
+ const s = await openSealed(browser, 'slides', { context: a.context, url: a.url })
+ ok(!(await banner(s.page)), 'sealed boot of A: no Restore banner')
+ ok(await versionRows(s.page) === 0, 'sealed boot of A: nothing in version history')
+ const leftA = await scanIndexedDB(s.page, MA)
+ ok(leftA.length === 0, `sealed boot of A: A's unsealed snapshot is deleted (${leftA.join(', ') || 'none left'})`)
+ const leftB = await scanIndexedDB(s.page, MB)
+ ok(leftB.length > 0, `another document's snapshot survives (${leftB.join(', ') || 'GONE'})`)
+ ok(s.errors.length === 0, `no page error${s.errors.length ? ' — ' + s.errors[0] : ''}`)
+ await a.context.close()
+ }
+} finally {
+ await browser.close()
+}
+console.log(`\n${checks - failures}/${checks} checks passed`)
+if (failures) process.exit(1)
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index b46d605f..aa3020e1 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -25,7 +25,7 @@ import { startPresentation } from '../present'
// serializeFile (plain output) is deliberately NOT imported here: every path
// in this file writes a real file for a person, so all of them must inherit an
// active password. serializeAuto is the only encryption-aware serializer.
-import { adoptFileHandle, canWriteInPlace, currentFileName, fileBase, hasFileHandle, hostCan, isEncryptionActive, openedFileName, saveFile, serializeAuto, setEncryptionPassword, suggestedFileName, writeUpdatedFile, writeUpdatedFileAs } from '../save'
+import { adoptFileHandle, canWriteInPlace, currentFileName, fileBase, hasFileHandle, hostCan, isBodySealed, isEncryptionActive, openedFileName, saveFile, serializeAuto, setEncryptionPassword, suggestedFileName, writeUpdatedFile, writeUpdatedFileAs } from '../save'
import { createSaveQueue, saveRevision } from '../saving'
import type { SaveQueue } from '../../../kernel/src/savequeue.ts'
import { noteSavedFromWeb } from './returngate'
@@ -2650,11 +2650,11 @@ export class Editor {
* A host with a per-document store (bento/home) refused this deck's recovery
* copy, so from now on there is NO crash backstop for it. Say so, once, where
* the save status shows, and stop the unsaved dot's tooltip claiming the work
- * is "kept in this browser". Never for an encrypted deck: those are never
- * snapshotted, so there was no backstop to lose.
+ * is "kept in this browser". Never for a sealed deck (a password, or the
+ * identity seal): those are never snapshotted, so there was no backstop to lose.
*/
private noticeRecoveryOff(docId: string) {
- if (docId !== this.store.doc.docId || isEncryptionActive() || this.recoveryOffSaid.has(docId)) return
+ if (docId !== this.store.doc.docId || isBodySealed() || this.recoveryOffSaid.has(docId)) return
this.recoveryOffSaid.add(docId)
this.lastBackupAt = 0
this.dirtyDot.title = canWriteInPlace()
@@ -2672,10 +2672,11 @@ export class Editor {
private async runAutosave() {
const doc = this.store.doc
if (doc.readonly) return
- // Never write an encrypted deck's plaintext to IndexedDB; its file
- // write-back below stays encrypted via serializeAuto.
+ // Never write a sealed deck's plaintext to IndexedDB (sealed = a password
+ // OR the identity seal); its file write-back below stays sealed via
+ // serializeAuto.
let snapshotted = false
- if (!isEncryptionActive()) {
+ if (!isBodySealed()) {
// only true if it REALLY stored — see putRecovery; no IndexedDB (Safari
// private browsing, some file:// contexts) must not read as "backed up"
snapshotted = await putRecovery(doc)
@@ -2727,6 +2728,15 @@ export class Editor {
private async checkRecovery() {
const doc = this.store.doc
+ // A sealed document never offers or keeps an unsealed snapshot: anything
+ // stored for this docId came from an earlier session that was not sealed,
+ // so it is deleted (this docId only), never shown. Boot has already set the
+ // seal (a password at the gate, the identity seal before the app ran).
+ if (isBodySealed()) {
+ await clearRecovery(doc.docId)
+ await clearVersions(doc.docId)
+ return
+ }
const snap = await getRecovery(doc.docId)
if (!snap) return
// A snapshot is foreign input (restoregate.ts): offered only if it is a
@@ -2971,7 +2981,8 @@ export class Editor {
/** Browse and restore the locally-kept auto-save timeline for this deck. */
private async openVersionHistory() {
- const versions = await listVersions(this.store.doc.docId)
+ // a sealed document has no timeline here (checkRecovery deleted any)
+ const versions = isBodySealed() ? [] : await listVersions(this.store.doc.docId)
document.querySelector('.ed-about-overlay')?.remove()
const overlay = div('ed-about-overlay')
const box = div('ed-about ed-version-box')
@@ -3172,7 +3183,7 @@ export class Editor {
// staged language packs are in the bytes now — stop calling them pending
markFileSaved()
// record a recovery baseline + a version checkpoint at each manual save
- if (!isEncryptionActive()) { void putRecovery(this.store.doc); void addVersion(this.store.doc); this.lastVersionAt = Date.now() }
+ if (!isBodySealed()) { void putRecovery(this.store.doc); void addVersion(this.store.doc); this.lastVersionAt = Date.now() }
// Saving is the opt-in: a named, saved deck is "live by default" from
// now on (the recipient of a copy already joins on open). Connect this
// session too so author and recipient meet without another click.