Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

slides: write chrome is an allowlist (no role / writer); audience and reader copies arriving in a running editor are locked (#593)

nyblnete27638f1295d
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a7dfdc87..ab556be4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1961,3 +1961,8 @@ jobs:
# Real UI and serialization, offline; delayed mock writes expose save races.
run: |
node scripts/test-slides-font-lifecycle-browser.mjs
+ - name: Write chrome follows the copy's role in Chromium
+ # canWriteDeck is an allowlist that fails closed: an audience, reader or
+ # unknown-role copy arriving in a running editor (dropped, loadDoc) gets
+ # no write actions and is locked; owner and writer copies keep theirs.
+ run: node scripts/test-slides-audience-gate-browser.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1a50778d..8e367666 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,14 @@ pre-1.0.
## [Unreleased]
+- **A view-only or audience copy opened inside the editor stays view-only.**
+ Dropping an audience copy (the hand-out for a live show) onto an open deck,
+ or loading one by script, used to offer "Invite to edit…", "Go live" and
+ "Reset access…" and call you an Editor; a read-only copy opened the same way
+ could be edited. Both are now locked, the same as when you open them
+ directly. The live session never accepted their changes; now the editor
+ agrees.
+
## [1.2.5] — 2026-09-28
- **Security: update this file. This release closes three security issues
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index 15cbe7b0..32c2c193 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -7442,6 +7442,30 @@ rigs treat a drawn arrow as a deliberate difference: named in
`test-maths-lite.ts`, counted with the identical ones in the coverage floor.
Cost: +966 B of shell.
+## 2026-10-04 — slides: write chrome is an allowlist, and the lock follows a document that arrives
+
+The editor decided whether a copy could write with `collab.role !== 'reader'`. That
+was a denylist, so the broadcast `audience` role (#454) passed it: an audience
+copy dropped onto a running editor, or handed to `window.bento.loadDoc`, got
+"Invite to edit…", "Go live" and "Reset access…", an Editor label, and no
+editing lock. Measured on 1.2.5 by both routes. Booting an audience copy was
+never affected (`bootWith` sends it to the show), and the relay refused its
+writes throughout, so this was chrome, not capability. Separately, the
+read-only lock ran only at build time, so even a plain reader copy dropped onto
+a running editor could be edited.
+
+Fixed: `canWriteDeck(collab)` in `slides/src/editor/editor.ts` is an allowlist
+that fails closed. No collab, an absent role (owner and legacy writer copies)
+or `'writer'` may write; `'reader'`, `'audience'` and any role a later version
+adds are read-only. It gates the Share panel's write actions, the People row's
+label and the read-only lock, and a store listener applies the lock when a
+non-writing document arrives in a running editor. Type made the same change
+for its write chrome the same day; the two apps share the rule.
+
+Rule: decide what a copy may do by naming the roles that MAY, never the roles
+that may not. A role added later should arrive read-only until someone grants
+it more. Guarded by `scripts/test-slides-audience-gate-browser.mjs` (both
+routes, reader, unknown role, owner/writer controls; mutation-checked).
## 2026-10-04 — Whether a copy may write is an allowlist of roles (type)
**A copy's write capability is decided by the roles that can write, never by
diff --git a/scripts/test-slides-audience-gate-browser.mjs b/scripts/test-slides-audience-gate-browser.mjs
new file mode 100644
index 00000000..848dac72
--- /dev/null
+++ b/scripts/test-slides-audience-gate-browser.mjs
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// Only a copy that can write gets write chrome — however it reached the editor.
+//
+// npm run build:single --prefix slides && node scripts/test-slides-audience-gate-browser.mjs
+//
+// WHAT THIS PROVES, in the packaged document. An audience copy (the live
+// broadcast's ticket, role 'audience') boots straight into the show and never
+// the editor — but it can still ARRIVE in a running editor: dropped onto it,
+// or handed to window.bento.loadDoc. There, the write chrome was gated on
+// `role !== 'reader'`, a denylist that answered yes for 'audience': the Share
+// panel offered "Invite to edit…", "Go live" and "Reset access…", the People
+// row said Editor, and nothing locked editing. (Measured on 1.2.5, both routes.)
+// Now `canWriteDeck` is an allowlist that fails closed — no collab, no role, or
+// 'writer' — and the read-only lock follows a document that arrives, not only
+// one that boots (which also covers a plain READER copy dropped onto an editor).
+// 1. audience copy, by loadDoc and by drop: no write actions, Viewer, locked;
+// 2. reader copy dropped: locked (was not — the lock ran at build only);
+// 3. a role this version does not know: read-only (fails closed);
+// 4. controls: an owner copy (no role) and a 'writer' copy keep every action,
+// stay editable, and say Owner/Editor.
+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 WRITE_ACTIONS = ['Invite to edit…', 'Go live', 'Reset access…']
+const base = { v: 2, on: false, room: 'wROOM', key: 'room-key', owner: 'OWNERPUB' }
+const COPIES = {
+ audience: { ...base, role: 'audience', key: 'show-key', invite: { pub: 'INVPUB', priv: 'INVPRIV', role: 'audience', sig: 'SIG' } },
+ reader: { ...base, role: 'reader' },
+ future: { ...base, role: 'some-later-role', invite: { pub: 'INVPUB', priv: 'INVPRIV', role: 'writer', sig: 'SIG' } },
+ owner: { ...base, ownerPriv: 'OWNERPRIV' },
+ writer: { ...base, role: 'writer', invite: { pub: 'INVPUB', priv: 'INVPRIV', role: 'writer', sig: 'SIG' } },
+}
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+const SHELL = new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url).href
+async function arrive(kind, route) {
+ const p = await browser.newPage()
+ const errors = []
+ p.on('pageerror', (e) => errors.push(e.message))
+ p.on('dialog', (d) => d.dismiss())
+ await p.route(/^https?:/, (r) => r.abort())
+ await p.goto(SHELL)
+ await p.waitForFunction(() => window.bento?.doc && document.querySelector('.ed-btn-share'))
+ await p.evaluate(async ({ collab, route }) => {
+ const d = JSON.parse(JSON.stringify(window.bento.doc)); d.collab = collab
+ if (route === 'loadDoc') { window.bento.loadDoc(JSON.stringify(d)); return }
+ // a saved copy dropped onto the running editor
+ const html = `<!doctype html><html><body><script type="application/bento+json" id="bento-doc">${JSON.stringify(d).replace(/</g, '\\u003c')}<` + `/script></body></html>`
+ const dt = new DataTransfer()
+ dt.items.add(new File([html], 'copy.bento.html', { type: 'text/html' }))
+ const target = document.querySelector('.ed-canvas-wrap') ?? document.body
+ target.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, dataTransfer: dt }))
+ target.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: dt }))
+ await new Promise((r) => setTimeout(r, 600))
+ }, { collab: COPIES[kind], route })
+ await p.waitForTimeout(300)
+ const r = await p.evaluate(() => {
+ const btn = document.querySelector('.ed-btn-share'); btn.click()
+ const pop = document.querySelector('.ed-share-pop')
+ const actions = [...pop.querySelectorAll('.ed-share-btn')].map((b) => b.getAttribute('aria-label') ?? b.textContent.trim())
+ const me = pop.querySelector('.ed-share-me')?.textContent ?? ''
+ btn.click()
+ return { role: window.bento.doc.collab?.role, actions, me, locked: document.body.classList.contains('ed-reader'), banners: document.querySelectorAll('.ed-reader-banner').length }
+ })
+ await p.close()
+ return { ...r, errors }
+}
+
+try {
+ for (const route of ['loadDoc', 'drop']) {
+ console.log(`\naudience copy, by ${route}\n`)
+ const r = await arrive('audience', route)
+ ok(r.role === 'audience', `it arrived in the editor (role ${r.role})`)
+ ok(!WRITE_ACTIONS.some((a) => r.actions.includes(a)), `no write actions (${r.actions.join(', ') || 'none'})`)
+ ok(/Viewer/.test(r.me) && !/Editor|Owner/.test(r.me), `the People row says Viewer ("${r.me}")`)
+ ok(r.locked && r.banners === 1, `editing is locked, one banner (${r.banners})`)
+ ok(r.errors.length === 0, `no page errors${r.errors.length ? ': ' + r.errors.join('; ') : ''}`)
+ }
+ console.log('\nreader copy dropped onto the editor\n')
+ {
+ const r = await arrive('reader', 'drop')
+ ok(r.locked && !WRITE_ACTIONS.some((a) => r.actions.includes(a)), `locked, no write actions (locked ${r.locked})`)
+ }
+ console.log('\na role this version does not know\n')
+ {
+ const r = await arrive('future', 'loadDoc')
+ ok(r.locked && !WRITE_ACTIONS.some((a) => r.actions.includes(a)), `fails closed: locked, no write actions (${r.actions.join(', ') || 'none'})`)
+ }
+ for (const kind of ['owner', 'writer']) {
+ console.log(`\ncontrol: ${kind} copy\n`)
+ const r = await arrive(kind, 'loadDoc')
+ ok(WRITE_ACTIONS.every((a) => r.actions.includes(a)), `every write action is offered`)
+ ok(!r.locked && r.banners === 0, 'editing is not locked')
+ ok(kind === 'owner' ? /Owner/.test(r.me) : /Editor/.test(r.me), `the People row says ${kind === 'owner' ? 'Owner' : 'Editor'} ("${r.me}")`)
+ }
+} finally { await browser.close() }
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 1e7196b4..ef65ce55 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -86,6 +86,20 @@ const SHAPE_MENU: Array<{ kind: ShapeKind; label: string; icon: string; heads?:
{ kind: 'path', label: 'Polygon', icon: ICONS.polygon, draw: 'poly', tip: 'Click to place corners; click the first point (or double-click) to close the shape' },
]
+/**
+ * May this copy write? An ALLOWLIST that fails closed: a deck with no live
+ * session, or one whose role is absent (owner and legacy writer copies) or
+ * 'writer'. Every other role — 'reader', 'audience', and any role a later
+ * version adds — is read-only here. It used to be `role !== 'reader'`, a
+ * denylist that answered yes for the broadcast 'audience' role, so an audience
+ * copy dropped onto a running editor got "Invite to edit…", "Reset access…"
+ * and an Editor label. (The relay refused its writes all along; this was the
+ * chrome, not the capability.)
+ */
+export function canWriteDeck(collab: { role?: string } | undefined): boolean {
+ return !collab || collab.role === undefined || collab.role === 'writer'
+}
+
export class Editor {
private canvas!: SlideCanvas
private panel!: PropsPanel
@@ -138,6 +152,10 @@ export class Editor {
store.on('doc', () => this.syncThemeRefs())
store.on('doc', () => this.syncFonts())
this.syncFonts()
+ // A document that cannot write can ARRIVE in a running editor, not only boot
+ // in one — an audience or reader copy dropped onto it, or loaded by script.
+ // The build-time check never sees those, so the lock follows the document.
+ store.on('doc', () => { if (!store.readOnly && !canWriteDeck(store.doc.collab)) this.enterReaderMode() })
document.addEventListener('bento:apply-layout', ((ev: CustomEvent) => {
this.openLayoutPicker(ev.detail.anchor as HTMLElement, { kind: 'apply' })
}) as EventListener)
@@ -524,7 +542,7 @@ export class Editor {
this.canvas.onSlideNav = (dir) => this.store.goToLinear(dir)
this.panel = new PropsPanel(this.props, this.store)
- if (this.store.doc.collab?.role === 'reader') this.enterReaderMode()
+ if (!canWriteDeck(this.store.doc.collab)) this.enterReaderMode()
}
/** Live viewer: block user edits (store.readOnly), hide editing chrome, and
@@ -1356,7 +1374,7 @@ export class Editor {
if (cme) {
let myPub: string | undefined
let myRole: 'owner' | 'editor' | 'viewer' | undefined
- if (cme.role === 'reader') myRole = 'viewer'
+ if (!canWriteDeck(cme)) myRole = 'viewer'
else if (cme.v === 2 && cme.ownerPriv) { myRole = 'owner'; myPub = cme.owner }
else if (cme.v === 2 && cme.invite) {
myRole = 'editor'
@@ -1461,7 +1479,7 @@ export class Editor {
// SHARE ACTIONS — sharing IS files: each button saves a copy to send, and
// turns the live session on. Labels stay short; the tooltips explain.
- const canWrite = !!cme && cme.role !== 'reader'
+ const canWrite = !!cme && canWriteDeck(cme)
if (canWrite) {
const label = div('ed-share-label')
label.textContent = t('Share a copy')