Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Release 1.2.6 (#623)

nyblnetb0299574ad10
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b261392d..354eb7ad 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -465,6 +465,19 @@ jobs:
--outfile="$RUNNER_TEMP/test-embed.mjs"
node --no-warnings "$RUNNER_TEMP/test-embed.mjs"
+ - name: File-open / boot document gate rig
+ # Opening a foreign .bento.html and booting a directly-opened file run
+ # bare parseDoc -> render + injectFonts with no structural gate, exposing
+ # the document-level egress the element sanitiser never sees: a
+ # slide.background url(), an -face src from an external asset value,
+ # a weight/style src-breakout. Positive controls (raw) fetch; the opened
+ # document reaches the request log zero times; unknown keys/props from a
+ # NEWER deck survive (format additivity). Browser half needs Chrome.
+ run: |
+ slides/node_modules/.bin/esbuild scripts/test-fileopen-gate.ts --bundle --platform=node --format=esm \
+ --outfile="$RUNNER_TEMP/test-fileopen-gate.mjs"
+ node "$RUNNER_TEMP/test-fileopen-gate.mjs"
+
- name: Untrusted-markup sanitizer rig
# Every deck is untrusted input somebody may open, paste or receive over
# collab, and script in that page owns the collab keys, the plaintext
@@ -483,6 +496,21 @@ jobs:
--outfile="$RUNNER_TEMP/test-sanitize.mjs"
node "$RUNNER_TEMP/test-sanitize.mjs"
+ - name: Replace-from-JSON document gate rig
+ # The document text that arrives through window.bento.loadDoc and
+ # "Replace from JSON…" is foreign input, full or compact. It passes the
+ # structural gate (restoregate.ts sanitizeDoc): the open deck keeps its
+ # identity (docId, collab, readonly), unknown keys/props are dropped, and
+ # the document-level egress surfaces the element sanitiser never sees —
+ # slide.background url(), an @font-face src resolved from an external
+ # asset value, a weight/style src-breakout — are neutralised. Positive
+ # controls (raw, un-gated) fetch; the gated document reaches the request
+ # log zero times. Browser half needs Chrome; it self-skips otherwise.
+ run: |
+ slides/node_modules/.bin/esbuild scripts/test-replace-json-gate.ts --bundle --platform=node --format=esm \
+ --outfile="$RUNNER_TEMP/test-replace-json-gate.mjs"
+ node "$RUNNER_TEMP/test-replace-json-gate.mjs"
+
- name: Export-secrets rig
# "Copy document JSON" shipped the room's owner private key while the
# tooltip recommended pasting it into an AI chat, and "Save as
@@ -2012,6 +2040,10 @@ jobs:
# Save as → Import PowerPoint… opens only the bento.page importer, in a
# new tab with no opener, and its tooltip says it needs the network.
run: node scripts/test-slides-import-link-browser.mjs
+ - name: Under-specified documents boot in Chromium
+ # parseDoc fills required fields only where absent and drops elements
+ # that cannot render; unknown keys and element types survive (additivity).
+ run: node scripts/test-slides-minimal-doc-browser.mjs
spaces-save-browser:
runs-on: ubuntu-latest
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a0b0736..d4bce968 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ pre-1.0.
## [Unreleased]
+## [1.2.6] — 2026-10-04
+
- **Open a PowerPoint deck in Bento: bento.page/import.** Drop a `.pptx` on
the page and get back a `.bento.html` deck you can edit and present. The
conversion runs in your browser and the deck is never uploaded. The page
@@ -20,6 +22,23 @@ pre-1.0.
was left out. Tables and charts become marked placeholders for now.
The same conversion runs from a terminal as
`node convert/cli.mjs deck.pptx`.
+- **Save as → Import PowerPoint…** The Save-as menu has an entry next to
+ Replace from JSON that opens that importer (bento.page/import) in a new tab.
+ It needs an internet connection, and the entry's tooltip says so.
+- **Security: update this file. This release closes further issues found in
+ our own review.** None needs anything from you beyond updating. What each one
+ was is described here once people have had time to update.
+- **Undo can no longer reverse Stop sharing, Reset access or Duplicate as new
+ deck.** Undoing an edit made before one of those used to bring back the old
+ sharing settings, which could restore access you had just removed from a
+ collaborator. **If you have used Reset access on a shared deck, update and
+ then reset access again** to be sure the change stuck.
+- **A hand-written or AI-written deck no longer gets stuck on the loading
+ screen.** A document that left out a required part — the theme, the page
+ size, a slide's background, or an element's content — opened to the splash
+ screen and stayed there. It now opens: the missing parts take the editor's
+ defaults, anything that was given is kept, and an element with nothing to
+ show is left out.
- **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
@@ -27,9 +46,14 @@ pre-1.0.
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.
-- **Save as → Import PowerPoint…** The Save-as menu has an entry next to
- Replace from JSON that opens that importer (bento.page/import) in a new tab.
- It needs an internet connection, and the entry's tooltip says so.
+- **Pictures a collaborator adds now appear in a read-only live copy.** Large
+ pictures travel through the live session separately from the deck, and a
+ read-only viewer showed them as blank boxes. They now load like everything
+ else.
+- **A copy edited offline catches up every tab opened later.** When a copy
+ you edited offline reconnected, its changes reached the collaborators online
+ at that moment; a tab opened afterwards on the same computer could miss them.
+ It now receives them too.
## [1.2.5] — 2026-09-28
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index 159b3b9f..4495564d 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -7916,3 +7916,31 @@ identity in. slides' gate additionally rebuilds content key by key; type has
no such layer, and its renderer already treats any opened file's content as
untrusted — the risk specific to a snapshot is the identity and capability,
which is what this closes. `test-type-restore-gate.ts` pins it.
+## 2026-10-04 — parseDoc fills what the format requires, and only that
+
+`parseDoc` checked `format` and a non-empty `slides` and nothing else. A
+hand- or agent-written document that omitted a REQUIRED field passed it and
+then crashed the shell during boot: no `theme` died on `undefined.palette`, no
+`size` on `width`, a bare `{type:'text'}` on `indexOf`, a `null` element on
+`themeRefs`. The reader was left on the splash screen with no way out. Measured
+on 1.2.5 with 13 under-specified shapes; found by opening agent-written test
+documents.
+
+Fixed in `model.ts`: `parseDoc` fills each required field (`title`, `version`,
+`size`, `theme` and its four keys, and on each slide `id`, `background`,
+`transition`, `elements`, `notes`) from the editor's own defaults (`newDoc`,
+`emptySlide`), ONLY where it is absent or the wrong type. It drops an element
+that cannot render: not an object, no `type`, or missing a key its type
+requires. `REQUIRED_ELEMENT_KEYS` moved from untrusted.ts into model.ts, so the
+paste gate and the file gate share one table. A slide that is not an object is
+dropped; no slide left means null, as before.
+
+Rule, and why it does not break format additivity: never REPAIR a value that
+is present, and never drop what this version does not understand. An element of
+an unknown type is kept whole (it renders as nothing, which the renderer
+already tolerates), and unknown keys on the document, a slide, the theme or an
+element ride through and are saved back. What is dropped is only what no
+version writes and no renderer can draw. Verified: 9 real decks pass through
+byte-identical with every element kept, and a document from a "newer version"
+keeps its unknown keys and element type through boot.
+`scripts/test-slides-minimal-doc-browser.mjs` guards it (mutation-checked).
diff --git a/kernel/src/sync/online.ts b/kernel/src/sync/online.ts
index 94a24446..087afe33 100644
--- a/kernel/src/sync/online.ts
+++ b/kernel/src/sync/online.ts
@@ -995,6 +995,19 @@ export function joinFromDoc(session: SyncSession, store: Store): OnlineTransport
return active
}
+/** Apply a sharing/collab change WITHOUT an undo step. collab is per-copy
+ * capability + config, never document content, so a user's Cmd-Z must not
+ * toggle it: an undone "Stop sharing" left the flag ON with no connection (UI
+ * and session disagreeing), and an undone key rotation would restore a revoked
+ * key. The doc is still marked dirty so the change saves, and 'doc' is emitted
+ * so the Live UI refreshes, but it never goes through store.commit (which pushes
+ * undo). collab is excluded from the sync diff, so emitting 'doc' sends no op. */
+function markShared(store: Store, fn: () => void) {
+ fn()
+ store.setDirty(true)
+ store.emit('doc')
+}
+
/** flip sharing on and connect — the "Start live session" action.
* Credentials already exist (minted at creation); this only arms them. */
export async function startSharing(session: SyncSession, store: Store): Promise<OnlineTransport | null> {
@@ -1002,9 +1015,9 @@ export async function startSharing(session: SyncSession, store: Store): Promise<
if (active) return active
if (!store.doc.collab) {
const creds = await mintCollab()
- store.commit(() => { store.doc.collab = creds })
+ markShared(store, () => { store.doc.collab = creds })
}
- store.commit(() => { store.doc.collab!.on = true })
+ markShared(store, () => { store.doc.collab!.on = true })
return joinFromDoc(session, store)
}
@@ -1028,9 +1041,7 @@ export function stopSharing(session: SyncSession, store: Store) {
active = null
}
if (store.doc.collab && store.doc.collab.on !== false) {
- store.commit(() => {
- store.doc.collab!.on = false
- })
+ markShared(store, () => { store.doc.collab!.on = false })
}
}
@@ -1039,7 +1050,7 @@ export function stopSharing(session: SyncSession, store: Store) {
export async function rotateKeys(session: SyncSession, store: Store) {
stopSharing(session, store)
const fresh = await mintCollab()
- store.commit(() => {
+ markShared(store, () => {
const sync = store.doc.collab?.sync
store.doc.collab = sync ? { ...fresh, sync } : fresh
})
diff --git a/schema/slides-1.2.6.json b/schema/slides-1.2.6.json
new file mode 100644
index 00000000..185e89ff
--- /dev/null
+++ b/schema/slides-1.2.6.json
@@ -0,0 +1,2379 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "$id": "https://bento.page/schema/slides.json",
+ "title": "bento/slides document",
+ "description": "The #bento-doc JSON of a Bento Slides file, generated from the app's validation tables. Guide: https://bento.page/agents.md",
+ "x-bento-version": "1.2.6",
+ "$ref": "#/$defs/doc",
+ "$defs": {
+ "prop-fx": {
+ "type": "object",
+ "properties": {
+ "ambient": {
+ "type": "string",
+ "enum": [
+ "kenburns"
+ ]
+ },
+ "countUp": {
+ "type": "boolean"
+ },
+ "enter": {
+ "type": "string",
+ "enum": [
+ "fade-up",
+ "fade",
+ "fade-down",
+ "slide-left",
+ "slide-right",
+ "slide-up",
+ "slide-down"
+ ]
+ },
+ "enterDur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 600
+ },
+ "ken": {
+ "type": "object",
+ "properties": {
+ "dir": {
+ "type": "string",
+ "enum": [
+ "drift",
+ "out",
+ "in"
+ ]
+ },
+ "duration": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 3600
+ },
+ "scale": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100
+ }
+ },
+ "additionalProperties": false
+ },
+ "loop": {
+ "type": "object",
+ "properties": {
+ "delay": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 3600
+ },
+ "distance": {
+ "type": "number",
+ "minimum": -100000,
+ "maximum": 100000
+ },
+ "duration": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 3600
+ },
+ "ease": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "path": {
+ "type": "string",
+ "maxLength": 65536,
+ "description": "SVG path data"
+ },
+ "speeds": {
+ "type": "array",
+ "maxItems": 2000,
+ "items": {
+ "type": "number",
+ "minimum": 0.001,
+ "maximum": 1000
+ }
+ },
+ "type": {
+ "type": "string",
+ "enum": [
+ "dash-march",
+ "motion-path"
+ ]
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type"
+ ]
+ },
+ "order": {
+ "type": "number",
+ "minimum": -10000,
+ "maximum": 10000
+ },
+ "step": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 10000
+ }
+ },
+ "additionalProperties": false
+ },
+ "prop-shadow": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 10000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "x": {
+ "type": "number",
+ "minimum": -10000,
+ "maximum": 10000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -10000,
+ "maximum": 10000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "blur",
+ "color"
+ ]
+ },
+ {
+ "type": "array",
+ "maxItems": 16,
+ "items": {
+ "type": "object",
+ "properties": {
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 10000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "x": {
+ "type": "number",
+ "minimum": -10000,
+ "maximum": 10000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -10000,
+ "maximum": 10000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "blur",
+ "color"
+ ]
+ }
+ }
+ ]
+ },
+ "prop-colorGradient": {
+ "type": "object",
+ "properties": {
+ "angle": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "stops": {
+ "type": "array",
+ "maxItems": 64,
+ "items": {
+ "type": "object",
+ "properties": {
+ "at": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "at",
+ "color"
+ ]
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "stops"
+ ]
+ },
+ "prop-themeRefs": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "string"
+ },
+ "maxProperties": 64,
+ "description": "property path → palette token"
+ },
+ "prop-textStroke": {
+ "type": "object",
+ "properties": {
+ "width": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "fill": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "width",
+ "color"
+ ]
+ },
+ "prop-link": {
+ "type": "string",
+ "maxLength": 4000,
+ "description": "slide id or http(s) URL"
+ },
+ "text": {
+ "type": "object",
+ "properties": {
+ "align": {
+ "type": "string",
+ "enum": [
+ "left",
+ "center",
+ "right"
+ ]
+ },
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "colorGradient": {
+ "$ref": "#/$defs/prop-colorGradient"
+ },
+ "fontFamily": {
+ "type": "string",
+ "maxLength": 300
+ },
+ "fontSize": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 4000
+ },
+ "fontWeight": {
+ "type": "number",
+ "minimum": 1,
+ "maximum": 1000
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "html": {
+ "type": "string",
+ "maxLength": 65536
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "letterSpacing": {
+ "type": "number",
+ "minimum": -1000,
+ "maximum": 1000
+ },
+ "lineHeight": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "placeholder": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "textStroke": {
+ "$ref": "#/$defs/prop-textStroke"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "text"
+ },
+ "valign": {
+ "type": "string",
+ "enum": [
+ "top",
+ "middle",
+ "bottom"
+ ]
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id",
+ "html"
+ ],
+ "description": "text element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "prop-fillGradient": {
+ "type": "object",
+ "properties": {
+ "angle": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "stops": {
+ "type": "array",
+ "maxItems": 64,
+ "items": {
+ "type": "object",
+ "properties": {
+ "at": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "at",
+ "color"
+ ]
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "stops"
+ ]
+ },
+ "prop-from": {
+ "type": "object",
+ "properties": {
+ "el": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "side": {
+ "type": "string",
+ "enum": [
+ "auto",
+ "top",
+ "right",
+ "bottom",
+ "left"
+ ]
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "el"
+ ]
+ },
+ "prop-to": {
+ "type": "object",
+ "properties": {
+ "el": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "side": {
+ "type": "string",
+ "enum": [
+ "auto",
+ "top",
+ "right",
+ "bottom",
+ "left"
+ ]
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "el"
+ ]
+ },
+ "shape": {
+ "type": "object",
+ "properties": {
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "d": {
+ "type": "string",
+ "maxLength": 65536,
+ "description": "SVG path data"
+ },
+ "fill": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour or url(#local-id)"
+ },
+ "fillGradient": {
+ "$ref": "#/$defs/prop-fillGradient"
+ },
+ "from": {
+ "$ref": "#/$defs/prop-from"
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "heads": {
+ "type": "number",
+ "minimum": 2,
+ "maximum": 2
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "lineEnd": {
+ "type": "string",
+ "enum": [
+ "none",
+ "arrow",
+ "dot",
+ "bar",
+ "arrow-open",
+ "triangle",
+ "triangle-open",
+ "diamond",
+ "diamond-open",
+ "square",
+ "circle-open"
+ ]
+ },
+ "lineStart": {
+ "type": "string",
+ "enum": [
+ "none",
+ "arrow",
+ "dot",
+ "bar",
+ "arrow-open",
+ "triangle",
+ "triangle-open",
+ "diamond",
+ "diamond-open",
+ "square",
+ "circle-open"
+ ]
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "pathBox": {
+ "type": "array",
+ "minItems": 4,
+ "maxItems": 4,
+ "items": {
+ "type": "number"
+ }
+ },
+ "radius": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100000
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "shape": {
+ "type": "string",
+ "enum": [
+ "rect",
+ "ellipse",
+ "triangle",
+ "arrow",
+ "line",
+ "path"
+ ]
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "stroke": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour or url(#local-id)"
+ },
+ "strokeDash": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 10000
+ },
+ "strokeStyle": {
+ "type": "string",
+ "enum": [
+ "solid",
+ "dashed",
+ "dotted"
+ ]
+ },
+ "strokeWidth": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 10000
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "to": {
+ "$ref": "#/$defs/prop-to"
+ },
+ "type": {
+ "const": "shape"
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id",
+ "shape",
+ "fill"
+ ],
+ "description": "shape element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "prop-crop": {
+ "type": "object",
+ "properties": {
+ "scale": {
+ "type": "number",
+ "minimum": 1,
+ "maximum": 64
+ },
+ "x": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "y": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "x",
+ "y",
+ "scale"
+ ]
+ },
+ "image": {
+ "type": "object",
+ "properties": {
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "crop": {
+ "$ref": "#/$defs/prop-crop"
+ },
+ "fit": {
+ "type": "string",
+ "enum": [
+ "contain",
+ "cover",
+ "fill"
+ ]
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "keepAspectRatio": {
+ "type": "boolean"
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "radius": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100000
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "src": {
+ "type": "string",
+ "maxLength": 33554432,
+ "description": "data: URI, asset:<key> or URL"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "image"
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id",
+ "src"
+ ],
+ "description": "image element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "svg": {
+ "type": "object",
+ "properties": {
+ "asset": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "css": {
+ "type": "string",
+ "maxLength": 131072
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "markup": {
+ "type": "string",
+ "maxLength": 4194304
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "svg"
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id"
+ ],
+ "description": "svg element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "prop-source": {
+ "type": "object",
+ "properties": {
+ "tableId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "tableId"
+ ]
+ },
+ "prop-option": {
+ "type": "object",
+ "description": "ECharts-shaped option, plain JSON"
+ },
+ "chart": {
+ "type": "object",
+ "properties": {
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "option": {
+ "$ref": "#/$defs/prop-option"
+ },
+ "preset": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "source": {
+ "$ref": "#/$defs/prop-source"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "chart"
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id",
+ "option"
+ ],
+ "description": "chart element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "prop-style": {
+ "type": "object",
+ "properties": {
+ "borderColor": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "borderWidth": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "cellPadX": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "cellPadY": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "fontFamily": {
+ "type": "string",
+ "maxLength": 300
+ },
+ "fontSize": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 4000
+ },
+ "headerBg": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "headerColor": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "radius": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100000
+ },
+ "zebra": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ }
+ },
+ "additionalProperties": false
+ },
+ "prop-rows": {
+ "type": "array",
+ "maxItems": 2000,
+ "items": {
+ "type": "object",
+ "properties": {
+ "cells": {
+ "type": "array",
+ "maxItems": 200,
+ "items": {
+ "type": "object",
+ "properties": {
+ "align": {
+ "type": "string",
+ "enum": [
+ "left",
+ "center",
+ "right"
+ ]
+ },
+ "bg": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "bold": {
+ "type": "boolean"
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "html": {
+ "type": "string",
+ "maxLength": 65536
+ }
+ },
+ "additionalProperties": false
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "cells"
+ ]
+ }
+ },
+ "prop-columns": {
+ "type": "array",
+ "maxItems": 200,
+ "items": {
+ "type": "object",
+ "properties": {
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "w"
+ ]
+ }
+ },
+ "table": {
+ "type": "object",
+ "properties": {
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "columns": {
+ "$ref": "#/$defs/prop-columns"
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "header": {
+ "type": "boolean"
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "rows": {
+ "$ref": "#/$defs/prop-rows"
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "style": {
+ "$ref": "#/$defs/prop-style"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "table"
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id",
+ "columns",
+ "rows"
+ ],
+ "description": "table element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "media": {
+ "type": "object",
+ "properties": {
+ "autoplay": {
+ "type": "boolean"
+ },
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "controls": {
+ "type": "boolean"
+ },
+ "fit": {
+ "type": "string",
+ "enum": [
+ "contain",
+ "cover",
+ "fill"
+ ]
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "kind": {
+ "type": "string",
+ "enum": [
+ "video",
+ "audio"
+ ]
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "loop": {
+ "type": "boolean"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "muted": {
+ "type": "boolean"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "poster": {
+ "type": "string",
+ "maxLength": 33554432,
+ "description": "data: URI, asset:<key> or URL"
+ },
+ "radius": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100000
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "src": {
+ "type": "string",
+ "maxLength": 33554432,
+ "description": "data: URI, asset:<key> or URL"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "media"
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id",
+ "kind",
+ "src"
+ ],
+ "description": "media element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "prop-doc": {
+ "anyOf": [
+ {
+ "type": "string",
+ "maxLength": 200
+ },
+ {
+ "type": "object"
+ }
+ ]
+ },
+ "embed": {
+ "type": "object",
+ "properties": {
+ "app": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "doc": {
+ "$ref": "#/$defs/prop-doc"
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "live": {
+ "type": "boolean"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "embed"
+ },
+ "url": {
+ "type": "string",
+ "maxLength": 4000,
+ "pattern": "^https?://"
+ },
+ "view": {
+ "type": "string",
+ "maxLength": 4194304
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id"
+ ],
+ "description": "embed element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "code": {
+ "type": "object",
+ "properties": {
+ "align": {
+ "type": "string",
+ "enum": [
+ "left",
+ "center",
+ "right"
+ ]
+ },
+ "backdropFilter": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "blend": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "blur": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "content": {
+ "type": "string",
+ "maxLength": 65536
+ },
+ "fontFamily": {
+ "type": "string",
+ "maxLength": 300
+ },
+ "fontSize": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 4000
+ },
+ "fx": {
+ "$ref": "#/$defs/prop-fx"
+ },
+ "grammarAssetId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "grammarName": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "group": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "groupId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "h": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "lineHeight": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100
+ },
+ "link": {
+ "$ref": "#/$defs/prop-link"
+ },
+ "morphId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "opacity": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "role": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "rotation": {
+ "type": "number",
+ "minimum": -3600,
+ "maximum": 3600
+ },
+ "shadow": {
+ "$ref": "#/$defs/prop-shadow"
+ },
+ "showOnHover": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "themeAssetId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "themeName": {
+ "type": "string",
+ "maxLength": 64,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "themeRefs": {
+ "$ref": "#/$defs/prop-themeRefs"
+ },
+ "type": {
+ "const": "code"
+ },
+ "valign": {
+ "type": "string",
+ "enum": [
+ "top",
+ "middle",
+ "bottom"
+ ]
+ },
+ "w": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type",
+ "id"
+ ],
+ "description": "code element; x/y/w/h in slide px (1280×720 default); a stable id pairs morphs"
+ },
+ "element": {
+ "oneOf": [
+ {
+ "$ref": "#/$defs/text"
+ },
+ {
+ "$ref": "#/$defs/shape"
+ },
+ {
+ "$ref": "#/$defs/image"
+ },
+ {
+ "$ref": "#/$defs/svg"
+ },
+ {
+ "$ref": "#/$defs/chart"
+ },
+ {
+ "$ref": "#/$defs/table"
+ },
+ {
+ "$ref": "#/$defs/media"
+ },
+ {
+ "$ref": "#/$defs/embed"
+ },
+ {
+ "$ref": "#/$defs/code"
+ }
+ ]
+ },
+ "slide": {
+ "type": "object",
+ "properties": {
+ "background": {
+ "type": "string",
+ "maxLength": 200,
+ "description": "CSS colour; no url()"
+ },
+ "comments": {
+ "type": "array",
+ "maxItems": 500,
+ "items": {
+ "type": "object",
+ "properties": {
+ "at": {
+ "type": "string",
+ "maxLength": 200
+ },
+ "author": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "elementId": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "replies": {
+ "type": "array",
+ "maxItems": 500,
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "author": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "text": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "at": {
+ "type": "string",
+ "maxLength": 200
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "resolved": {
+ "type": "boolean"
+ },
+ "text": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "x": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ },
+ "y": {
+ "type": "number",
+ "minimum": -1000000,
+ "maximum": 1000000
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "elements": {
+ "type": "array",
+ "maxItems": 5000,
+ "items": {
+ "$ref": "#/$defs/element"
+ }
+ },
+ "hidden": {
+ "type": "boolean"
+ },
+ "hover": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "focus-group",
+ "reveal"
+ ]
+ },
+ "dim": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1
+ },
+ "default": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "type"
+ ]
+ },
+ "id": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "name": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "notes": {
+ "type": "string",
+ "maxLength": 65536
+ },
+ "stateOf": {
+ "type": "string",
+ "maxLength": 200,
+ "pattern": "^[^\"'<>{};]*$"
+ },
+ "themeRefs": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "string"
+ },
+ "maxProperties": 64,
+ "description": "property path → palette token"
+ },
+ "transition": {
+ "type": "string",
+ "enum": [
+ "none",
+ "fade",
+ "slide",
+ "zoom",
+ "morph"
+ ]
+ },
+ "unnumbered": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "id"
+ ],
+ "description": "stateOf = hidden variant reached by a link; transition morph pairs same-id elements"
+ },
+ "tableStyle": {
+ "type": "object",
+ "properties": {
+ "borderColor": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "borderWidth": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "cellPadX": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "cellPadY": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1000
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "fontFamily": {
+ "type": "string",
+ "maxLength": 300
+ },
+ "fontSize": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 4000
+ },
+ "headerBg": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "headerColor": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ },
+ "radius": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100000
+ },
+ "zebra": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "CSS colour; no url()"
+ }
+ },
+ "additionalProperties": false
+ },
+ "theme": {
+ "type": "object",
+ "properties": {
+ "accent": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "accent colour"
+ },
+ "background": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "slide background"
+ },
+ "chartPalette": {
+ "type": "array",
+ "maxItems": 64,
+ "items": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "series colour"
+ }
+ },
+ "codePalette": {
+ "type": "object",
+ "properties": {
+ "a": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "c": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "d": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "f": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "k": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "n": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "p": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ },
+ "s": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "token colour"
+ }
+ },
+ "additionalProperties": false
+ },
+ "color": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "body text colour"
+ },
+ "fontFamily": {
+ "type": "string",
+ "maxLength": 300,
+ "description": "CSS font-family stack for body text"
+ },
+ "headingFamily": {
+ "type": "string",
+ "maxLength": 300,
+ "description": "display face for headings; absent = fontFamily"
+ },
+ "palette": {
+ "type": "object",
+ "properties": {
+ "accent2": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot accent2"
+ },
+ "accent3": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot accent3"
+ },
+ "accent4": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot accent4"
+ },
+ "accent5": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot accent5"
+ },
+ "accent6": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot accent6"
+ },
+ "bg2": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot bg2"
+ },
+ "folHlink": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot folHlink"
+ },
+ "hlink": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot hlink"
+ },
+ "tx2": {
+ "type": "string",
+ "maxLength": 64,
+ "description": "brand slot tx2"
+ }
+ },
+ "additionalProperties": false
+ },
+ "table": {
+ "$ref": "#/$defs/tableStyle"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "background",
+ "color",
+ "accent",
+ "fontFamily"
+ ]
+ },
+ "doc": {
+ "type": "object",
+ "properties": {
+ "assets": {
+ "type": "object",
+ "maxProperties": 2000,
+ "additionalProperties": {
+ "type": "string",
+ "maxLength": 33554432
+ },
+ "description": "key → data: URI or svg, used as asset:<key>"
+ },
+ "blobs": {
+ "type": "object",
+ "description": "runtime-written"
+ },
+ "collab": {
+ "type": "object",
+ "description": "runtime-written credentials; never author"
+ },
+ "docId": {
+ "type": "string",
+ "maxLength": 200,
+ "description": "runtime-minted uuid; omit"
+ },
+ "fonts": {
+ "type": "array",
+ "maxItems": 2000,
+ "items": {
+ "type": "object",
+ "properties": {
+ "asset": {
+ "type": "string",
+ "maxLength": 200,
+ "description": "asset:<key> or builtin:<name>"
+ },
+ "family": {
+ "type": "string",
+ "maxLength": 300
+ },
+ "style": {
+ "type": "string",
+ "maxLength": 64
+ },
+ "weight": {
+ "type": "string",
+ "maxLength": 64
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "family",
+ "asset"
+ ]
+ }
+ },
+ "format": {
+ "const": "bento/slides"
+ },
+ "layouts": {
+ "type": "array",
+ "maxItems": 500,
+ "items": {
+ "$ref": "#/$defs/slide"
+ },
+ "description": "slide templates"
+ },
+ "meta": {
+ "type": "object",
+ "properties": {
+ "author": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "company": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "event": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "keywords": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "subject": {
+ "type": "string",
+ "maxLength": 4000
+ }
+ },
+ "additionalProperties": false
+ },
+ "modified": {
+ "type": "string",
+ "maxLength": 200,
+ "description": "runtime-written"
+ },
+ "present": {
+ "type": "object",
+ "properties": {
+ "controls": {
+ "type": "boolean"
+ },
+ "morphSeconds": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 60
+ },
+ "numberHidden": {
+ "type": "boolean"
+ },
+ "progress": {
+ "type": "boolean"
+ },
+ "slideNumber": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false
+ },
+ "readonly": {
+ "type": "boolean",
+ "description": "presentation package"
+ },
+ "size": {
+ "type": "object",
+ "properties": {
+ "height": {
+ "type": "number",
+ "minimum": 1,
+ "maximum": 100000
+ },
+ "width": {
+ "type": "number",
+ "minimum": 1,
+ "maximum": 100000
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "width",
+ "height"
+ ]
+ },
+ "slides": {
+ "type": "array",
+ "minItems": 1,
+ "maxItems": 500,
+ "items": {
+ "$ref": "#/$defs/slide"
+ }
+ },
+ "template": {
+ "type": "boolean"
+ },
+ "theme": {
+ "$ref": "#/$defs/theme"
+ },
+ "title": {
+ "type": "string",
+ "maxLength": 4000
+ },
+ "version": {
+ "type": "integer",
+ "minimum": 1,
+ "description": "format version; this shell writes 1"
+ },
+ "$schema": {
+ "type": "string"
+ },
+ "compact": {
+ "const": true,
+ "description": "input only: omitted fields take editor defaults (AGENTS.md)"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "format",
+ "slides"
+ ]
+ }
+ }
+}
diff --git a/schema/slides.json b/schema/slides.json
index fb05a163..185e89ff 100644
--- a/schema/slides.json
+++ b/schema/slides.json
@@ -3,7 +3,7 @@
"$id": "https://bento.page/schema/slides.json",
"title": "bento/slides document",
"description": "The #bento-doc JSON of a Bento Slides file, generated from the app's validation tables. Guide: https://bento.page/agents.md",
- "x-bento-version": "1.2.5",
+ "x-bento-version": "1.2.6",
"$ref": "#/$defs/doc",
"$defs": {
"prop-fx": {
diff --git a/scripts/test-export-secrets.ts b/scripts/test-export-secrets.ts
index 60350560..14a295af 100644
--- a/scripts/test-export-secrets.ts
+++ b/scripts/test-export-secrets.ts
@@ -295,16 +295,23 @@ for (const [name, src] of editor) {
// The paste side of the JSON round-trip. Adopting the pasted block would wipe
// the user's own credentials (our copy sends none) or move the deck into a
// room that came from somewhere else.
+// The identity is now kept by the document gate itself (restoregate.ts
+// sanitizeDoc with `live` — docId, collab and readonly come from the open deck),
+// which openReplaceJson invokes through parseDocInputReport; the gate's own rig
+// (test-replace-json-gate.ts) RUNS that identity rule. Pinned here: the paste
+// path hands the gate the open document.
const paste = body('openReplaceJson')
-ok(/const keep = this\.store\.doc\.collab/.test(paste) &&
- /next\.collab = keep/.test(paste) && /delete next\.collab/.test(paste),
- 'openReplaceJson() keeps THIS document\'s collab instead of adopting the pasted one')
+const pasteCode = mask(paste)
+const gateAt = pasteCode.search(/parseDocInputReport\(\s*ta\.value\s*,\s*\{\s*live:\s*this\.store\.doc\s*\}\s*\)/)
+ok(gateAt >= 0,
+ 'openReplaceJson() parses through the gate with { live: this.store.doc } — THIS document\'s collab, never the pasted one')
// …and settles it BEFORE the swap: replaceDoc's events reach the sync session
// synchronously, so a fix-up afterwards would already have re-attached the
-// session to the pasted credentials.
+// session to the pasted credentials. (Both indices must exist: a missing
+// pattern returns -1, which is "before" everything and proved nothing.)
// Masked, because the comment above the code names both of them.
-const pasteCode = mask(paste)
-ok(pasteCode.indexOf('next.collab = keep') < pasteCode.indexOf('replaceDoc(') && !/loadDoc/.test(pasteCode),
+const swapAt = pasteCode.indexOf('replaceDoc(')
+ok(gateAt >= 0 && swapAt >= 0 && gateAt < swapAt && !/loadDoc/.test(pasteCode),
'openReplaceJson() decides the session before replaceDoc, not after')
// --- 3. no user-facing path writes plaintext --------------------------------
diff --git a/scripts/test-fileopen-gate.ts b/scripts/test-fileopen-gate.ts
new file mode 100644
index 00000000..c9c5f7e1
--- /dev/null
+++ b/scripts/test-fileopen-gate.ts
@@ -0,0 +1,175 @@
+// Security regression rig for the FILE-OPEN / BOOT document path.
+//
+// On 1.2.5 main, opening a foreign .bento.html (editor.ts openFile :2772) and
+// booting a directly-opened file (main.ts :82) both run `parseDoc(json)` →
+// replaceDoc → renderSlide + injectFonts, with NO structural gate. That exposes
+// the document-level egress surfaces the element sanitiser never sees:
+// * slide.background: url(https://…) — fetched at render
+// * doc.fonts[] weight/style interpolated raw into the boot @font-face — a
+// src-breakout fetch when the family is used
+// * a font whose asset VALUE is an external url — src:url("http…")
+// Option A (security-decision-fileopen-additivity.md) adds VALUE-LEVEL guards to
+// this path: neutralise those three by value, keep the FILE's own identity, and
+// PRESERVE unknown keys/props (format additivity — the A-vs-B discriminator).
+//
+// Assertions encode the POST-FIX expectation. Against the baseline (no patch)
+// the egress rows are RED (they fetch) while the additivity + identity rows are
+// GREEN — the expected "still vulnerable" picture. When Option A lands, swap the
+// one-line transform seam below and every row goes green.
+//
+// EMBARGOED companion to security-decision-fileopen-additivity.md. Move to
+// scripts/ + CI when the fix publishes. Browser half needs Chrome; self-skips.
+import { execFileSync, spawn, spawnSync } from 'node:child_process'
+import fs from 'node:fs'
+import http from 'node:http'
+import os from 'node:os'
+import path from 'node:path'
+import { parseDoc, newDoc } from '../slides/src/model.ts'
+import { guardOpenedDoc } from '../slides/src/restoregate.ts'
+
+let failures = 0, checks = 0
+const ok = (cond: boolean, msg: string) => { checks++; if (!cond) { failures++; console.error(` ✗ ${msg}`) } else console.log(` ✓ ${msg}`) }
+const repoFile = (rel: string): string => { const f = path.resolve(rel); if (!fs.existsSync(f)) throw new Error(`run from repo root — ${rel} missing`); return f }
+
+// ─── THE FILE-OPEN TRANSFORM SEAM ───────────────────────────────────────────
+// Baseline (3a26dba7) = parseDoc alone, the ungated path editor.ts:2772 /
+// main.ts:82 use today. When slides' Option A patch lands, replace this ONE line
+// with the patched transform (confirm the exported name — e.g.
+// import { gateOpenedDoc } from '../slides/src/<file>.ts'
+// return gateOpenedDoc(parseDoc(json))
+// ) and re-run: the egress rows flip green, the additivity rows stay green.
+// Wired to the patched transform: parseDoc, then the value-level guard every
+// file-open path runs (restoregate.ts guardOpenedDoc — main.ts boot and unlock,
+// editor.ts open-a-file), which neutralises in place.
+const fileOpenTransform = (json: string): any => { const d = parseDoc(json); if (d) guardOpenedDoc(d); return d }
+// ─────────────────────────────────────────────────────────────────────────────
+
+const FILE_DOCID = 'FILE-OWN-DOCID-777'
+const foreignJson = () => JSON.stringify((() => {
+ const d = newDoc() as any
+ d.docId = FILE_DOCID // the file's OWN identity — file-open keeps it
+ d.collab = { on: true, room: 'wFILEROOM', key: 'FILEKEY' }
+ d.futureUnknownDocKey = 'survives (a newer deck)' // additivity: must be preserved
+ d.assets = { srcasset: 'https://evil.example/x.woff2', okfont: 'data:font/woff2;base64,d09GMgABAAAAAAAA' }
+ d.fonts = [
+ { family: 'FamSrc', asset: 'srcasset', weight: 'normal', style: 'normal' },
+ { family: 'FamStyle', asset: 'okfont', weight: 'normal', style: 'normal;src:url("https://evil.example/s.woff2")' },
+ ]
+ d.slides[0].background = 'url(https://evil.example/bg.png)'
+ d.slides[0].elements = [{
+ id: 't1', type: 'text', x: 10, y: 10, w: 300, h: 60, rotation: 0, opacity: 1,
+ html: 'hi', fontFamily: 'FamSrc', fontSize: 28, fontWeight: 400, color: '#000', align: 'left',
+ futureUnknownProp: 'survives (a newer element field)',
+ }]
+ return d
+})())
+
+// ── 1. the transform's output, in node ──────────────────────────────────────
+console.log('\nthe file-open transform, as data\n')
+const g: any = fileOpenTransform(foreignJson())
+ok(!!g, 'the transform accepts a valid full document')
+if (g) {
+ // identity — file-open keeps the FILE's own (it does NOT force a live deck, unlike loadDoc/Replace)
+ ok(g.docId === FILE_DOCID, 'identity — the opened file keeps its OWN docId (a shared file still finds its recovery / joins its room)')
+ // additivity — the A-vs-B discriminator: unknowns must SURVIVE (A), not be dropped (B)
+ ok('futureUnknownDocKey' in g, 'additivity — an unknown top-level key from a NEWER deck survives the open')
+ ok(!!(g.slides?.[0]?.elements?.[0] ?? {}).futureUnknownProp, 'additivity — an unknown element field from a NEWER deck survives the open')
+ // structural egress neutralisation — POST-FIX expectation (RED on baseline)
+ ok(!String(g.slides?.[0]?.background ?? '').includes('evil.example'), 'slide.background loses its external url()')
+ ok(!/src\s*:/i.test((g.fonts ?? []).map((f: any) => String(f.style ?? '')).join('|')), 'a font style descriptor cannot carry an src breakout')
+}
+
+// ── 2. render + font walk, in a browser ──────────────────────────────────────
+const CHROME = [process.env.BENTO_CHROME, '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
+ '/Applications/Chromium.app/Contents/MacOS/Chromium', '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser']
+ .find((p): p is string => !!p && fs.existsSync(p)) ?? (spawnSync('which', ['google-chrome']).status === 0 ? 'google-chrome' : undefined)
+
+const probeSource = (modelPath: string, renderPath: string, fontsPath: string, gatePath: string) => `
+import { parseDoc, newDoc } from ${JSON.stringify(modelPath)}
+import { guardOpenedDoc } from ${JSON.stringify(gatePath)}
+import { renderSlide } from ${JSON.stringify(renderPath)}
+import { injectFonts } from ${JSON.stringify(fontsPath)}
+const O = location.origin
+// SEAM mirror — keep identical to the node seam above.
+const fileOpenTransform = (json) => { const d = parseDoc(json); if (d) guardOpenedDoc(d); return d }
+const txt = (id, y, fam, extra) => ({ id, type: 'text', x: 10, y, w: 300, h: 60, rotation: 0, opacity: 1,
+ html: 'The quick brown fox', fontFamily: fam, fontSize: 28, fontWeight: 400, color: '#000', align: 'left', ...(extra || {}) })
+function craft(tag){
+ const d = newDoc(); d.docId = 'FILE'; d.collab = { on: true, room: 'wF', key: 'K' }
+ d.assets = { srcasset: O + '/font-src-' + tag, okfont: 'data:font/woff2;base64,d09GMgABAAAAAAAA' }
+ d.fonts = [ { family: 'FamSrc', asset: 'srcasset', weight: 'normal', style: 'normal' },
+ { family: 'FamStyle', asset: 'okfont', weight: 'normal', style: 'normal;src:url("' + O + '/font-style-' + tag + '")' } ]
+ d.slides[0].background = 'url(' + O + '/bg-' + tag + ')'
+ d.slides[0].elements = [ txt('t1', 10, 'FamSrc'), txt('t2', 90, 'FamStyle') ]
+ return JSON.stringify(d)
+}
+function drawAndMount(doc){
+ const s = renderSlide(doc.slides[0], doc); s.style.width='400px'; s.style.height='225px'
+ document.body.appendChild(s); void s.offsetHeight; s.getBoundingClientRect()
+ injectFonts(doc); void (document.getElementById('bento-fonts')||{}).offsetHeight
+}
+;(async () => {
+ // POSITIVE controls — prove the BROWSER fetches these, independent of the code
+ // under test. slide.background via renderSlide (not a guard). The @font-face
+ // faces are written by hand (NOT injectFonts, which Option A may make a guard).
+ const raw = parseDoc(craft('raw')); const rs = renderSlide(raw.slides[0], raw)
+ rs.style.width='400px'; rs.style.height='225px'; document.body.appendChild(rs); void rs.offsetHeight
+ const face = document.createElement('style')
+ face.textContent =
+ '@font-face{font-family:RawSrc;src:url("' + O + '/font-src-raw");font-display:swap}' +
+ '@font-face{font-family:RawStyle;src:url("data:font/woff2;base64,d09GMgABAAAAAAAA");font-style:normal;src:url("' + O + '/font-style-raw");font-display:swap}'
+ document.head.appendChild(face)
+ for (const fam of ['RawSrc','RawStyle']){ const dv=document.createElement('div'); dv.style.fontFamily=fam; dv.style.fontSize='28px'; dv.textContent='The quick brown fox'; document.body.appendChild(dv); void dv.offsetHeight }
+ // the REAL path: fileOpenTransform → renderSlide + injectFonts. Must reach zero
+ // once Option A lands; on the baseline these FETCH (vulnerable).
+ drawAndMount(fileOpenTransform(craft('gated')))
+ setTimeout(async () => {
+ try { await fetch(O + '/fence', { cache: 'no-store' }) } catch {}
+ const pre = document.createElement('pre'); pre.id='bento-results'; pre.textContent='DONE'; document.body.appendChild(pre)
+ }, 500)
+})()
+`
+
+async function runBrowser(chrome: string) {
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bento-fo-'))
+ const entry = path.join(tmp, 'probe.ts')
+ fs.writeFileSync(entry, probeSource(repoFile('slides/src/model.ts'), repoFile('slides/src/render.ts'), repoFile('slides/src/fonts.ts'), repoFile('slides/src/restoregate.ts')))
+ execFileSync(repoFile('slides/node_modules/.bin/esbuild'), [entry, '--bundle', '--format=esm', '--outfile=' + path.join(tmp, 'probe.js')], { stdio: 'pipe' })
+ const bundle = fs.readFileSync(path.join(tmp, 'probe.js'), 'utf8')
+ const page = '<!doctype html><meta charset="utf-8"><body>' + '<scr' + 'ipt type="module" src="/probe.js"></scr' + 'ipt>' + '<img src="/slow.gif" width="1" height="1"></body>'
+ const hits: string[] = []
+ const gif = (res: http.ServerResponse) => { res.writeHead(200, { 'content-type': 'image/gif' }); res.end(Buffer.from('R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==', 'base64')) }
+ const server = http.createServer((req, res) => {
+ const url = (req.url ?? '/').split('?')[0]; hits.push(url)
+ if (url === '/probe.js') { res.writeHead(200, { 'content-type': 'text/javascript' }); res.end(bundle); return }
+ if (url === '/probe.html') { res.writeHead(200, { 'content-type': 'text/html' }); res.end(page); return }
+ if (url === '/slow.gif') { setTimeout(() => gif(res), 1500); return }
+ gif(res)
+ })
+ await new Promise<void>((r) => server.listen(0, '127.0.0.1', r))
+ const port = (server.address() as { port: number }).port
+ const dom: string = await new Promise((resolve) => {
+ const child = spawn(chrome, ['--headless=new', '--disable-gpu', '--no-sandbox', '--no-first-run', '--no-default-browser-check',
+ '--disable-background-networking', '--disable-component-update', '--disable-sync', '--disable-default-apps',
+ '--user-data-dir=' + path.join(tmp, 'profile'), '--virtual-time-budget=4000', '--dump-dom', `http://127.0.0.1:${port}/probe.html`], { stdio: ['ignore', 'pipe', 'ignore'] })
+ let out = ''; child.stdout.on('data', (b: Buffer) => { out += b.toString('utf8') })
+ const k = setTimeout(() => child.kill('SIGKILL'), 45_000); child.on('close', () => { clearTimeout(k); resolve(out) })
+ })
+ try {
+ ok(dom.includes('DONE'), 'the probe ran to the end')
+ ok(hits.includes('/fence'), 'the fence arrived — the hit list is complete')
+ ok(hits.includes('/bg-raw'), 'positive — a raw slide.background url() fetches')
+ ok(hits.includes('/font-src-raw'), 'positive — a raw external @font-face src fetches')
+ ok(hits.includes('/font-style-raw'), 'positive — a raw style src-breakout fetches')
+ ok(!hits.includes('/bg-gated'), 'file-open — slide.background does NOT fetch')
+ ok(!hits.includes('/font-src-gated'), 'file-open — a font whose asset value is a url does NOT fetch')
+ ok(!hits.includes('/font-style-gated'), 'file-open — a font style src-breakout does NOT fetch')
+ console.log('requests:', JSON.stringify(hits.filter((h) => !['/probe.html', '/probe.js', '/slow.gif'].includes(h))))
+ } finally { server.close(); fs.rmSync(tmp, { recursive: true, force: true }) }
+}
+
+console.log('\nthe render and font walk, in a browser')
+if (!CHROME) console.log(' ⚠ SKIPPED — no Chrome. Set BENTO_CHROME; this is the half that proves the open does not phone home.')
+else await runBrowser(CHROME)
+console.log(`\n${checks - failures}/${checks} checks passed`)
+if (failures) process.exit(1)
diff --git a/scripts/test-replace-json-gate.ts b/scripts/test-replace-json-gate.ts
new file mode 100644
index 00000000..0b4e2000
--- /dev/null
+++ b/scripts/test-replace-json-gate.ts
@@ -0,0 +1,199 @@
+// The gate that document JSON passes when it replaces the open deck:
+// window.bento.loadDoc and "Replace from JSON…", both through
+// parseDocInputReport (compactload.ts) → sanitizeDoc (restoregate.ts).
+//
+// Two halves, the same shape as scripts/test-sanitize.ts:
+// * node — the gate's output is pure data: identity comes from the OPEN deck,
+// unknown keys/props are dropped, slide.background loses its url() and a font
+// descriptor cannot carry an src-breakout;
+// * a browser — the gated document is rendered and its fonts injected while a
+// local server logs every request. Positive controls (raw, un-gated) MUST
+// fetch, so the zeros that follow are a boundary and not an artefact.
+//
+// EMBARGOED companion to working/team/handoffs/security-finding-replace-from-json.md.
+// Move to scripts/ and register in CI when the fix publishes. Needs Chrome for
+// the browser half; it self-skips (loudly) where there is none.
+import { execFileSync, spawn, spawnSync } from 'node:child_process'
+import fs from 'node:fs'
+import http from 'node:http'
+import os from 'node:os'
+import path from 'node:path'
+import { parseDocInputReport } from '../slides/src/compactload.ts'
+import { newDoc } from '../slides/src/model.ts'
+
+let failures = 0
+let checks = 0
+function ok(cond: boolean, msg: string) {
+ checks++
+ if (!cond) { failures++; console.error(` ✗ ${msg}`) } else { console.log(` ✓ ${msg}`) }
+}
+const repoFile = (rel: string): string => {
+ const file = path.resolve(rel)
+ if (!fs.existsSync(file)) throw new Error(`run from the repo root — ${rel} not found`)
+ return file
+}
+
+// --- 1. the gate's output, in node ------------------------------------------
+console.log('\nthe document gate, as data\n')
+
+const live = newDoc() as any
+live.docId = 'LIVE-DOCID-123'
+live.collab = { on: true, room: 'wLIVEROOM', key: 'LIVEKEY' }
+live.readonly = false
+
+const foreign = () => {
+ const d = newDoc() as any
+ d.docId = 'FOREIGN-DOCID-999'
+ d.collab = { on: true, room: 'wFOREIGN', key: 'FOREIGNKEY' }
+ d.readonly = true
+ d.evilUnknownDocKey = 'drop-me'
+ d.assets = { srcasset: 'https://evil.example/x.woff2', okfont: 'data:font/woff2;base64,d09GMgABAAAAAAAA' }
+ d.fonts = [
+ { family: 'FamSrc', asset: 'srcasset', weight: 'normal', style: 'normal' },
+ { family: 'FamStyle', asset: 'okfont', weight: 'normal', style: 'normal;src:url("https://evil.example/s.woff2")' },
+ ]
+ d.slides[0].background = 'url(https://evil.example/bg.png)'
+ d.slides[0].elements = [{
+ id: 't1', type: 'text', x: 10, y: 10, w: 300, h: 60, rotation: 0, opacity: 1,
+ html: 'hi', fontFamily: 'FamSrc', fontSize: 28, fontWeight: 400, color: '#000', align: 'left',
+ evilUnknownProp: 'drop-me',
+ }]
+ return d
+}
+
+const gated = parseDocInputReport(JSON.stringify(foreign()), { live, fit: false })
+ok(!!gated, 'the gate accepts a valid full document')
+if (gated) {
+ const g: any = gated.doc
+ ok(g.docId === 'LIVE-DOCID-123', 'identity — docId is the open deck’s, not the pasted one')
+ ok(!!g.collab && g.collab.room === 'wLIVEROOM', 'identity — collab is the open deck’s room')
+ ok(g.readonly === false, 'identity — readonly is the open deck’s')
+ ok(!('evilUnknownDocKey' in g), 'an unknown document key is dropped')
+ ok(!(g.slides[0].elements[0] ?? {}).evilUnknownProp, 'an unknown element prop is dropped')
+ ok(gated.report.dropped.some((d: any) => /evilUnknownDocKey/.test(d.path)), 'the drop is reported to the caller')
+ ok(!String(g.slides[0].background ?? '').includes('evil.example'), 'slide.background loses its external url()')
+ ok(!/src\s*:/i.test((g.fonts ?? []).map((f: any) => String(f.style ?? '')).join('|')),
+ 'a font style descriptor cannot carry an src breakout')
+}
+// a compact document is gated the same way
+const compact = parseDocInputReport(JSON.stringify({ compact: true, slides: [{ elements: [[{ type: 'text', html: 'x' }]] }], evilUnknownDocKey: 'drop-me' }), { live, fit: false })
+ok(!!compact && !('evilUnknownDocKey' in (compact.doc as any)), 'a compact document passes the same gate (unknown key dropped)')
+ok(!!compact && (compact.doc as any).docId === 'LIVE-DOCID-123', 'a compact document keeps the open deck’s identity too')
+
+// --- 2. the render + font walk, in a browser --------------------------------
+const CHROME = [
+ process.env.BENTO_CHROME,
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
+ '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',
+].find((p): p is string => !!p && fs.existsSync(p))
+ ?? (spawnSync('which', ['google-chrome']).status === 0 ? 'google-chrome' : undefined)
+
+const probeSource = (compactloadPath: string, renderPath: string, fontsPath: string, modelPath: string) => `
+import { parseDocInputReport } from ${JSON.stringify(compactloadPath)}
+import { renderSlide } from ${JSON.stringify(renderPath)}
+import { injectFonts } from ${JSON.stringify(fontsPath)}
+import { newDoc } from ${JSON.stringify(modelPath)}
+const O = location.origin
+const txt = (id, y, fam, extra) => ({ id, type: 'text', x: 10, y, w: 300, h: 60, rotation: 0, opacity: 1,
+ html: 'The quick brown fox', fontFamily: fam, fontSize: 28, fontWeight: 400, color: '#000', align: 'left', ...(extra || {}) })
+function craft(tag){
+ const d = newDoc()
+ d.docId = 'FOREIGN'; d.collab = { on: true, room: 'wF', key: 'K' }; d.readonly = true
+ d.assets = { srcasset: O + '/font-src-' + tag, okfont: 'data:font/woff2;base64,d09GMgABAAAAAAAA' }
+ d.fonts = [ { family: 'FamSrc', asset: 'srcasset', weight: 'normal', style: 'normal' },
+ { family: 'FamStyle', asset: 'okfont', weight: 'normal', style: 'normal;src:url("' + O + '/font-style-' + tag + '")' } ]
+ d.slides[0].background = 'url(' + O + '/bg-' + tag + ')'
+ d.slides[0].elements = [ txt('t1', 10, 'FamSrc'), txt('t2', 90, 'FamStyle') ]
+ return d
+}
+function drawAndMount(doc){
+ const s = renderSlide(doc.slides[0], doc); s.style.width='400px'; s.style.height='225px'
+ document.body.appendChild(s); void s.offsetHeight; s.getBoundingClientRect()
+ injectFonts(doc); void (document.getElementById('bento-fonts')||{}).offsetHeight
+}
+;(async () => {
+ // POSITIVE controls prove the BROWSER fetches these, independent of the code
+ // under test. slide.background goes through renderSlide (not the guard —
+ // renderSlide applies whatever it is given). The font faces are written by
+ // hand, NOT through injectFonts, because injectFonts is now itself the guard;
+ // a used family with an external src, and the last-wins src of a style
+ // breakout, must both reach the server here.
+ const rawDoc = craft('raw'); const rs = renderSlide(rawDoc.slides[0], rawDoc)
+ rs.style.width = '400px'; rs.style.height = '225px'; document.body.appendChild(rs); void rs.offsetHeight
+ const face = document.createElement('style')
+ face.textContent =
+ '@font-face{font-family:RawSrc;src:url("' + O + '/font-src-raw");font-display:swap}' +
+ '@font-face{font-family:RawStyle;src:url("data:font/woff2;base64,d09GMgABAAAAAAAA");font-style:normal;src:url("' + O + '/font-style-raw");font-display:swap}'
+ document.head.appendChild(face)
+ for (const fam of ['RawSrc', 'RawStyle']) {
+ const dv = document.createElement('div'); dv.style.fontFamily = fam; dv.style.fontSize = '28px'
+ dv.textContent = 'The quick brown fox'; document.body.appendChild(dv); void dv.offsetHeight
+ }
+ // the same input, gated with the open deck live — must reach zero times. This
+ // is the real path: parseDocInputReport → renderSlide → injectFonts.
+ const live = newDoc(); live.docId = 'LIVE'; live.collab = { on: true, room: 'wLIVE', key: 'K' }; live.readonly = false
+ const parsed = parseDocInputReport(JSON.stringify(craft('gated')), { live, fit: false })
+ if (parsed) drawAndMount(parsed.doc)
+ setTimeout(async () => {
+ try { await fetch(O + '/fence', { cache: 'no-store' }) } catch {}
+ const pre = document.createElement('pre'); pre.id = 'bento-results'; pre.textContent = 'DONE'
+ document.body.appendChild(pre)
+ }, 500)
+})()
+`
+
+async function runBrowserSection(chrome: string) {
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bento-rjgate-'))
+ const entry = path.join(tmp, 'probe.ts')
+ fs.writeFileSync(entry, probeSource(
+ repoFile('slides/src/compactload.ts'), repoFile('slides/src/render.ts'),
+ repoFile('slides/src/fonts.ts'), repoFile('slides/src/model.ts')))
+ execFileSync(repoFile('slides/node_modules/.bin/esbuild'),
+ [entry, '--bundle', '--format=esm', '--outfile=' + path.join(tmp, 'probe.js')], { stdio: 'pipe' })
+ const bundle = fs.readFileSync(path.join(tmp, 'probe.js'), 'utf8')
+ const page = '<!doctype html><meta charset="utf-8"><body>'
+ + '<scr' + 'ipt type="module" src="/probe.js"></scr' + 'ipt>'
+ + '<img src="/slow.gif" width="1" height="1" alt=""></body>'
+ const hits: string[] = []
+ const gif = (res: http.ServerResponse) => { res.writeHead(200, { 'content-type': 'image/gif' }); res.end(Buffer.from('R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==', 'base64')) }
+ const server = http.createServer((req, res) => {
+ const url = (req.url ?? '/').split('?')[0]; hits.push(url)
+ if (url === '/probe.js') { res.writeHead(200, { 'content-type': 'text/javascript' }); res.end(bundle); return }
+ if (url === '/probe.html') { res.writeHead(200, { 'content-type': 'text/html' }); res.end(page); return }
+ if (url === '/slow.gif') { setTimeout(() => gif(res), 1500); return }
+ gif(res)
+ })
+ await new Promise<void>((r) => server.listen(0, '127.0.0.1', r))
+ const port = (server.address() as { port: number }).port
+ const dom: string = await new Promise((resolve) => {
+ const child = spawn(chrome, ['--headless=new', '--disable-gpu', '--no-sandbox', '--no-first-run',
+ '--no-default-browser-check', '--disable-background-networking', '--disable-component-update',
+ '--disable-sync', '--disable-default-apps', '--user-data-dir=' + path.join(tmp, 'profile'),
+ '--virtual-time-budget=4000', '--dump-dom', `http://127.0.0.1:${port}/probe.html`], { stdio: ['ignore', 'pipe', 'ignore'] })
+ let out = ''; child.stdout.on('data', (b: Buffer) => { out += b.toString('utf8') })
+ const kill = setTimeout(() => child.kill('SIGKILL'), 45_000)
+ child.on('close', () => { clearTimeout(kill); resolve(out) })
+ })
+ try {
+ ok(dom.includes('DONE'), 'the probe ran to the end')
+ ok(hits.includes('/fence'), 'the fence arrived — the hit list is complete')
+ ok(hits.includes('/bg-raw'), 'positive — a raw slide.background url() fetches')
+ ok(hits.includes('/font-src-raw'), 'positive — a raw font whose asset value is a url fetches')
+ ok(hits.includes('/font-style-raw'), 'positive — a raw font style src-breakout fetches')
+ ok(!hits.includes('/bg-gated'), 'gated — slide.background does not fetch')
+ ok(!hits.includes('/font-style-gated'), 'gated — a font style src-breakout does not fetch')
+ ok(!hits.includes('/font-src-gated'), 'gated — a font whose asset value is a url does not fetch')
+ } finally {
+ server.close(); fs.rmSync(tmp, { recursive: true, force: true })
+ }
+}
+
+console.log('\nthe render and font walk, in a browser')
+if (!CHROME) {
+ console.log(' ⚠ SKIPPED — no Chrome. Set BENTO_CHROME; this is the half that proves the render does not phone home.')
+} else {
+ await runBrowserSection(CHROME)
+}
+console.log(`\n${checks - failures}/${checks} checks passed`)
+if (failures) process.exit(1)
diff --git a/scripts/test-slides-audience-gate-browser.mjs b/scripts/test-slides-audience-gate-browser.mjs
index 848dac72..c36ee511 100644
--- a/scripts/test-slides-audience-gate-browser.mjs
+++ b/scripts/test-slides-audience-gate-browser.mjs
@@ -14,7 +14,9 @@
// 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;
+// 1. audience copy dropped: no write actions, Viewer, locked. By loadDoc it
+// no longer arrives at all — loadDoc keeps the OPEN deck's identity (the
+// document gate), so the pasted audience collab is never adopted;
// 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,
@@ -73,15 +75,27 @@ async function arrive(kind, route) {
}
try {
- for (const route of ['loadDoc', 'drop']) {
- console.log(`\naudience copy, by ${route}\n`)
- const r = await arrive('audience', route)
+ console.log('\naudience copy, by drop\n')
+ {
+ // a FILE keeps its own identity when opened, so the audience role arrives
+ const r = await arrive('audience', 'drop')
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('\naudience copy, by loadDoc\n')
+ {
+ // loadDoc REPLACES the open deck's content and keeps the open deck's
+ // identity (the document gate, restoregate.ts sanitizeDoc with live): the
+ // pasted audience collab is never adopted, so there is nothing to lock —
+ // the deck is still the owner's, with the owner's actions
+ const r = await arrive('audience', 'loadDoc')
+ ok(r.role !== 'audience', `the pasted audience identity is not adopted (role ${r.role ?? 'none'})`)
+ ok(!r.locked && r.banners === 0 && WRITE_ACTIONS.every((a) => r.actions.includes(a)), 'the open deck stays the open deck: unlocked, its own actions')
+ 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')
@@ -89,12 +103,12 @@ try {
}
console.log('\na role this version does not know\n')
{
- const r = await arrive('future', 'loadDoc')
+ const r = await arrive('future', 'drop')
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')
+ const r = await arrive(kind, 'drop') // a file keeps its own identity
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}")`)
diff --git a/scripts/test-slides-compact.ts b/scripts/test-slides-compact.ts
index 82b30ba8..77013563 100644
--- a/scripts/test-slides-compact.ts
+++ b/scripts/test-slides-compact.ts
@@ -154,13 +154,14 @@ ok(((mc.slides as Obj[])[0].elements as Obj[]).every((e) => e.type !== 'text' ||
console.log('\nthe gated loader and the surfaces\n')
const loader = read('slides/src/compactload.ts')
-ok(/import \{ sanitizeSlide, withDropReport, withPathSegment[^}]*\} from '\.\/untrusted'/.test(loader) && /=> sanitizeSlide\(s\)/.test(loader) && /const doc = parseDoc\(JSON\.stringify\(ex\)\)/.test(loader), 'compactload.ts expands, runs sanitizeSlide on every slide (collecting drops), then parseDoc — the gate is the single point of validation')
-ok(/if \(!isCompact\(raw\)\) \{\s*const doc = parseDoc\(json\)/.test(loader), 'a full document takes the plain parseDoc path, as today')
+ok(/import \{ sanitizeSlide, withDropReport, withPathSegment[^}]*\} from '\.\/untrusted'/.test(loader) && /=> sanitizeSlide\(s\)/.test(loader) && /const base = parseDoc\(JSON\.stringify\(ex\)\)[\s\S]{0,300}sanitizeDoc\(base as unknown as Record<string, unknown>, o\.live\)/.test(loader), 'compactload.ts expands, runs sanitizeSlide on every slide (collecting drops), then parseDoc and the document gate — one gate, one point of validation')
+ok(/if \(!isCompact\(raw\)\) \{\s*const base = parseDoc\(json\)[\s\S]{0,120}sanitizeDoc\(base as unknown as Record<string, unknown>, o\.live\)/.test(loader),
+ 'a full document passes the structural gate too (sanitizeDoc), not parseDoc alone')
const main = read('slides/src/main.ts')
-ok(/const parsed = parseDocInputReport\(json\)/.test(main) && /return parsed\.report/.test(main) && /compact: \(\) => compactJson\(store\.doc\)/.test(main), 'window.bento.loadDoc accepts compact input and returns the load report; window.bento.compact() emits compact JSON')
+ok(/const parsed = parseDocInputReport\(json, \{ live: store\.doc \}\)/.test(main) && /return parsed\.report/.test(main) && /compact: \(\) => compactJson\(store\.doc\)/.test(main), 'window.bento.loadDoc accepts compact input and returns the load report; window.bento.compact() emits compact JSON')
ok(/return serializeFile\(store\.doc\)/.test(main), 'window.bento.serialize() is unchanged — the file is full')
const editor = read('slides/src/editor/editor.ts')
-ok(/const parsed = parseDocInputReport\(ta\.value\)/.test(editor) && /Loaded: \{dropped\} fields dropped, \{warnings\} warnings — see console/.test(editor), 'Replace from JSON… accepts compact input and summarises the report in a toast')
+ok(/const parsed = parseDocInputReport\(ta\.value, \{ live: this\.store\.doc \}\)/.test(editor) && /Loaded: \{dropped\} fields dropped, \{warnings\} warnings — see console/.test(editor), 'Replace from JSON… accepts compact input and summarises the report in a toast')
ok(/t\('Copy compact JSON \(for agents\)'\)/.test(editor) && /this\.copyDocJson\(true\)/.test(editor) && /compact \? compactJson\(clone\)/.test(editor), 'the Save menu has Copy compact JSON, wired to compactJson')
ok(!/compact/i.test(read('slides/src/save.ts')) && !/compactDoc|compactJson/.test(read('slides/src/model.ts')), 'save.ts and model.ts know nothing of compaction — the on-disk file cannot be compact')
ok(!/compact/.test(read('slides/src/modelkeys.generated.ts')), 'no model key named compact — the flag is input, never stored')
diff --git a/scripts/test-slides-minimal-doc-browser.mjs b/scripts/test-slides-minimal-doc-browser.mjs
new file mode 100644
index 00000000..92f79810
--- /dev/null
+++ b/scripts/test-slides-minimal-doc-browser.mjs
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// An under-specified document boots instead of hanging on the splash.
+//
+// npm run build:single --prefix slides && node scripts/test-slides-minimal-doc-browser.mjs
+//
+// WHAT THIS PROVES, in the packaged document. parseDoc checked `format` and a
+// non-empty `slides` and nothing else, so a hand- or agent-written document
+// that omitted a REQUIRED field got through and crashed the shell during boot —
+// no `theme` died on `undefined.palette`, no `size` on `width`, a bare
+// `{type:'text'}` on `indexOf`, a `null` element on `themeRefs` — and the
+// reader was left on the splash screen for good (measured on 1.2.5; found by
+// bento/share's opener work). parseDoc now fills each required field from the
+// editor's own defaults ONLY where it is absent or the wrong type, and drops an
+// element that cannot render (the paste gate's REQUIRED_ELEMENT_KEYS, now one
+// table in model.ts). Checked here:
+// 1. every under-specified shape found boots into the editor, no page error;
+// 2. what was given is kept (title, accent, a slide's own background);
+// 3. format additivity: keys this version does not know — on the document,
+// a slide, the theme — and an element of an unknown TYPE survive boot;
+// 4. control: the starter deck boots unchanged.
+import { readFileSync, writeFileSync, mkdtempSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+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 shellPath = new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url)
+const shell = readFileSync(shellPath, 'utf8')
+const open = '<script type="application/bento+json" id="bento-doc">'
+const close = '</' + 'script>'
+const at = shell.indexOf(open) + open.length
+const dir = mkdtempSync(join(tmpdir(), 'bento-minimal-'))
+const slide = (elements) => ({ format: 'bento/slides', slides: [{ id: 's1', elements }] })
+const CASES = {
+ 'no theme, no size (the report)': { format: 'bento/slides', title: 'plain', slides: [{ id: 's1', elements: [] }] },
+ 'no title, slide with only an id': { format: 'bento/slides', slides: [{ id: 's1' }] },
+ 'partial theme, no size': { format: 'bento/slides', title: 'p', theme: { accent: '#ff0000' }, slides: [{ id: 's1', background: '#123456', elements: [] }] },
+ 'null element': slide([null]),
+ 'number element': slide([3]),
+ 'element with no type': slide([{}]),
+ 'text with no html': slide([{ type: 'text', id: 't', x: 0, y: 0, w: 100, h: 40 }]),
+ 'shape with no kind': slide([{ type: 'shape' }]),
+ 'image with no src': slide([{ type: 'image' }]),
+ 'table with no rows': slide([{ type: 'table' }]),
+ 'media with no src': slide([{ type: 'media' }]),
+ 'junk slides': { format: 'bento/slides', slides: [7, null, { id: 's2', elements: [null, 3, {}] }] },
+}
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+async function boot(doc) {
+ const file = join(dir, `d${Math.random().toString(36).slice(2)}.bento.html`)
+ writeFileSync(file, shell.slice(0, at) + (doc ? JSON.stringify(doc).replace(/</g, '\\u003c') : '') + shell.slice(shell.indexOf(close, at)))
+ const p = await browser.newPage()
+ const errors = []
+ p.on('pageerror', (e) => errors.push(e.message))
+ await p.route(/^https?:/, (r) => r.abort())
+ await p.goto('file://' + file)
+ const booted = await p.waitForFunction(() => window.bento?.doc && document.querySelector('.ed-topbar') && !document.getElementById('bento-splash'), null, { timeout: 8000 }).then(() => true, () => false)
+ const doc2 = booted ? await p.evaluate(() => JSON.parse(JSON.stringify(window.bento.doc))) : null
+ await p.close()
+ return { booted, errors, doc: doc2 }
+}
+
+try {
+ console.log('under-specified documents boot\n')
+ for (const [name, doc] of Object.entries(CASES)) {
+ const r = await boot(doc)
+ ok(r.booted && r.errors.length === 0, `${name}${r.errors.length ? ' — ' + r.errors[0].slice(0, 80) : ''}`)
+ }
+
+ console.log('\nwhat was given is kept\n')
+ {
+ const r = await boot(CASES['partial theme, no size'])
+ ok(r.doc?.title === 'p' && r.doc?.theme?.accent === '#ff0000', `title and the given accent survive (${r.doc?.title}, ${r.doc?.theme?.accent})`)
+ ok(r.doc?.slides?.[0]?.background === '#123456', 'the slide\'s own background survives')
+ ok(typeof r.doc?.theme?.fontFamily === 'string' && r.doc?.size?.width > 0, 'the missing theme keys and size are filled')
+ }
+
+ console.log('\nformat additivity: what this version does not know survives\n')
+ {
+ const future = {
+ format: 'bento/slides', title: 'from a newer Bento', futureDocKey: { a: 1 },
+ theme: { background: '#fff', color: '#111', accent: '#f60', fontFamily: 'serif', futureThemeKey: 'x' },
+ size: { width: 1280, height: 720 },
+ slides: [{ id: 's1', background: '#fff', transition: 'fade', notes: '', futureSlideKey: 'y',
+ elements: [{ type: 'hologram', id: 'h', x: 0, y: 0, w: 50, h: 50, beam: 3 }, { type: 'text', id: 't', x: 0, y: 0, w: 100, h: 40, html: 'hi', futureProp: true }] }],
+ }
+ const r = await boot(future)
+ ok(r.booted && r.errors.length === 0, 'a document from a newer version boots')
+ ok(r.doc?.futureDocKey?.a === 1 && r.doc?.theme?.futureThemeKey === 'x' && r.doc?.slides?.[0]?.futureSlideKey === 'y', 'unknown document, theme and slide keys are kept')
+ const els = r.doc?.slides?.[0]?.elements ?? []
+ ok(els.some((e) => e.type === 'hologram' && e.beam === 3), 'an element of an unknown type is kept, whole')
+ ok(els.some((e) => e.type === 'text' && e.futureProp === true), 'an unknown property on a known element is kept')
+ }
+
+ console.log('\ncontrol\n')
+ {
+ const r = await boot(null) // the empty block boots the starter deck
+ ok(r.booted && r.errors.length === 0 && r.doc?.slides?.length > 10, `the starter deck boots (${r.doc?.slides?.length} slides)`)
+ }
+} finally { await browser.close() }
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/scripts/test-sync-session.ts b/scripts/test-sync-session.ts
index cf06ecf4..b08d8590 100644
--- a/scripts/test-sync-session.ts
+++ b/scripts/test-sync-session.ts
@@ -647,6 +647,60 @@ H('docfields: a reader copy with NO sync stamp joins a live room and converges')
sW.stop?.(); sR.stop?.();
}
+// Undo/redo move CONTENT, never identity. Two halves: stopSharing is no longer
+// its own undo step (kernel markShared), AND the Store keeps the live identity
+// set (docId, collab, readonly — restoregate's FROM_LIVE) across a restore, so a
+// prior edit's snapshot can't resurrect an old docId, a stale sharing flag or a
+// dropped read-only mode.
+H('undo/redo keep the live identity (docId, collab, readonly), never the snapshot');
+type Id = { collab: { on: boolean }; docId: string; readonly?: boolean; title: string };
+const freshShared = () => {
+ const doc = newDoc(); doc.docId = 'live-id';
+ (doc as unknown as { collab: { room: string; key: string; on: boolean } }).collab = { room: 'r', key: 'k', on: true };
+ const store = new Store(JSON.parse(JSON.stringify(doc)));
+ return { store, sess: new SyncSession(store) };
+};
+// Both halves must prove the fix — i.e. the restored snapshot must carry STALE
+// identity, so the row goes RED on main's unfixed store. The identity-changing
+// actions (Stop sharing via markShared, "Duplicate as new deck", a present-only
+// save) therefore run AFTER the step whose snapshot the undo/redo pops.
+{
+ // UNDO: edit, THEN change identity, THEN undo — the content-edit snapshot it
+ // pops was taken while sharing was on / docId was live-id / no readonly.
+ const { stopSharing } = await import('../kernel/src/sync/online.ts');
+ const { store, sess } = freshShared();
+ store.commit(() => { store.doc.title = 'a real edit'; });
+ stopSharing(sess as never, store as never);
+ const d0 = store.doc as unknown as { docId: string; readonly?: boolean };
+ d0.docId = 'new-id'; d0.readonly = true; store.setDirty(true);
+ store.undo(); // pops the content-edit snapshot (stale identity on main)
+ const d = store.doc as unknown as Id;
+ ok(d.collab.on === false, 'undo keeps the live collab (sharing stays off)');
+ ok(d.docId === 'new-id', 'undo keeps the live docId, not the snapshot’s old one');
+ ok(d.readonly === true, 'undo keeps the live read-only mode');
+ ok(d.title !== 'a real edit', 'undo still reverted the genuine content edit');
+ sess.stop?.();
+}
+{
+ // REDO: edit, undo, THEN change identity, THEN redo. The redo entry was
+ // captured at undo time — before the identity changes — so it carries the
+ // OLD identity, and main resurrects all three on redo (slides' sequence).
+ const { stopSharing } = await import('../kernel/src/sync/online.ts');
+ const { store, sess } = freshShared();
+ store.commit(() => { store.doc.title = 'a real edit'; });
+ store.undo(); // redo entry captured here still has the OLD identity
+ stopSharing(sess as never, store as never);
+ const d0 = store.doc as unknown as { docId: string; readonly?: boolean };
+ d0.docId = 'new-id'; d0.readonly = true; store.setDirty(true);
+ store.redo(); // pops the stale-identity redo entry
+ const r = store.doc as unknown as Id;
+ ok(r.collab.on === false, 'redo keeps the live collab (sharing stays off)');
+ ok(r.docId === 'new-id', 'redo keeps the live docId, not the snapshot’s old one');
+ ok(r.readonly === true, 'redo keeps the live read-only mode');
+ ok(r.title === 'a real edit', 'redo re-applied the content edit');
+ sess.stop?.();
+}
+
console.log(`\n${checks - failures}/${checks} checks passed`);
// BroadcastChannel and the heartbeat keep node's event loop alive
process.exit(failures ? 1 : 0);
diff --git a/slides/package.json b/slides/package.json
index 87a53131..299b29a6 100644
--- a/slides/package.json
+++ b/slides/package.json
@@ -1,7 +1,7 @@
{
"name": "bento-slides",
"private": true,
- "version": "1.2.5",
+ "version": "1.2.6",
"license": "MIT",
"type": "module",
"scripts": {
diff --git a/slides/src/compactload.ts b/slides/src/compactload.ts
index e63707b0..fac53078 100644
--- a/slides/src/compactload.ts
+++ b/slides/src/compactload.ts
@@ -5,12 +5,15 @@
// and the measure script: this one needs the untrusted gate (bundled) and the
// DOM (text measurement).
//
-// parseDoc (model.ts) stays what it is — the file on disk is always full. A
-// COMPACT document is authored by a tool, so it gets the untrusted shape gate
-// on the way in (sanitizeSlide, the same rule pasted clips and remote ops
-// meet): an unknown key or a malformed value is dropped rather than reaching
-// the renderer. A full document is not gated here — that is today's
-// behaviour and today's promise (your own file is yours).
+// parseDoc (model.ts) stays what it is — the file on disk is always full. The
+// document text that arrives HERE ("Replace from JSON…", window.bento.loadDoc)
+// comes from a chat, a tool, a clipboard — anywhere — so compact OR full, it
+// gets the untrusted structural gate on the way in (restoregate.ts
+// sanitizeDoc: sanitizeSlide, sanitizeAssets, sanitizeFonts, blob refs,
+// unknown keys dropped — the same rule pasted clips, remote ops and restored
+// snapshots meet), and with `live` it never brings its own identity: docId,
+// collab and readonly stay the open deck's. A full document used to pass on
+// parseDoc alone, which checks the format and nothing else.
//
// Round two adds the LOAD REPORT: what the gate dropped (path + reason), what
// expansion filled, and validate()'s findings on the result — so an agent's
@@ -26,6 +29,7 @@ import { sanitizeSlide, withDropReport, withPathSegment, type Dropped } from './
import { expandDocWithStats, isCompact, STACK_GAP, type ExpandStats } from './compact'
import { measureElement } from './measure'
import { validateDoc, type ValidateResult } from './validate'
+import { sanitizeDoc } from './restoregate'
export interface LoadReport {
ok: true
@@ -57,15 +61,26 @@ export function parseDocInput(json: string): BentoDoc | null {
return parseDocInputReport(json)?.doc ?? null
}
-/** parseDocInput, plus the report. `fit` runs the text measurement (browser
- * only); it is skipped where there is no DOM. */
-export function parseDocInputReport(json: string, fit = typeof document !== 'undefined'): { doc: BentoDoc; report: LoadReport } | null {
+export interface InputOptions {
+ /** run the text measurement (browser only); default: when there is a DOM */
+ fit?: boolean
+ /** the open document: its docId, collab and readonly are kept, never the input's */
+ live?: BentoDoc
+}
+
+/** parseDocInput, plus the report. A bare boolean is the old `fit` argument. */
+export function parseDocInputReport(json: string, opts: boolean | InputOptions = {}): { doc: BentoDoc; report: LoadReport } | null {
+ const o: InputOptions = typeof opts === 'boolean' ? { fit: opts } : opts
+ const fit = o.fit ?? typeof document !== 'undefined'
let raw: unknown
try { raw = JSON.parse(json) } catch { return null }
if (!isCompact(raw)) {
- const doc = parseDoc(json)
- if (!doc) return null
- return { doc, report: { ok: true, compact: false, dropped: [], expanded: 0, fitted: 0, findings: validateDoc(doc), refit: [], laidOut: 0, stacks: [] } }
+ const base = parseDoc(json)
+ if (!base) return null
+ const gated = sanitizeDoc(base as unknown as Record<string, unknown>, o.live)
+ if (!gated) return null
+ const doc = gated.doc
+ return { doc, report: { ok: true, compact: false, dropped: gated.dropped, expanded: 0, fitted: 0, findings: validateDoc(doc), refit: [], laidOut: 0, stacks: [] } }
}
const { doc: expanded, stats } = expandDocWithStats(raw)
const ex = expanded as unknown as Record<string, unknown>
@@ -75,8 +90,14 @@ export function parseDocInputReport(json: string, fit = typeof document !== 'und
.map((s, i) => withPathSegment('slides', () => withPathSegment(String(i), () => sanitizeSlide(s))))
.filter((s): s is Slide => s !== null))
ex.slides = slides
- const doc = parseDoc(JSON.stringify(ex))
- if (!doc) return null
+ const base = parseDoc(JSON.stringify(ex))
+ if (!base) return null
+ // the rest of the document — assets, fonts, blobs, settings, identity — goes
+ // through the same gate as a full one (slides pass again, idempotently)
+ const gated = sanitizeDoc(base as unknown as Record<string, unknown>, o.live)
+ if (!gated) return null
+ const doc = gated.doc
+ dropped.push(...gated.dropped)
let fitted = 0
let refit: ExpandStats['autoHeight'] = []
if (fit && stats.autoHeight.length) {
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 7469dbb7..2cbca352 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -42,7 +42,7 @@ import { projectDoc, projectOp, type AudienceTicket } from '../audience'
import { stripEmbeddedEnvelopes } from '../envelope'
import { compactJson } from '../compact'
import { parseDocInputReport } from '../compactload'
-import { gateRestored } from '../restoregate'
+import { gateRestored, guardOpenedDoc } from '../restoregate'
import { lsGet, lsJson, lsSet } from '../../../kernel/src/storage.ts'
import { shrinkImageFile, shrinkEnabled, setShrinkEnabled, shrinkNote, fmtBytes, type ShrinkResult } from './shrink'
import { deletePlan, expand, moveBlock, parents as selParents, range as selRange, toggle as selToggle } from './slidesel'
@@ -1180,23 +1180,18 @@ export class Editor {
applyB.className = 'ed-btn ed-btn-primary'
applyB.textContent = t('Apply')
applyB.addEventListener('click', () => {
- // parseDoc + replaceDoc rather than window.bento.loadDoc (which is the
- // same two calls) because the collab decision has to be made BEFORE the
- // swap: replaceDoc's events reach the sync session synchronously, and it
- // re-attaches to whatever `collab` the new document holds.
- //
- // The live session belongs to THIS document, not to the pasted text. The
- // copy side sends no collab at all, so adopting the pasted one would
- // either wipe the user's room credentials (paste of our own JSON) or
- // silently move the deck into a room that came from somewhere else.
- // Content is imported; identity and capability are not.
- const parsed = parseDocInputReport(ta.value) // full or compact (src/compact.ts)
+ // The pasted text is foreign input, full or compact (src/compact.ts):
+ // the gate rebuilds it (restoregate.ts sanitizeDoc), and with `live` the
+ // identity and capability stay THIS document's — its docId (recovery
+ // and versions are keyed by it, on a store other local files share),
+ // its live session (the copy side sends no collab, so adopting the
+ // pasted one would wipe the room or move the deck into someone else's)
+ // and its file mode. Decided BEFORE the swap: replaceDoc's events reach
+ // the sync session synchronously and it re-attaches to whatever
+ // `collab` the new document holds. Content is imported; identity is not.
+ const parsed = parseDocInputReport(ta.value, { live: this.store.doc })
if (parsed) {
- const next = parsed.doc
- const keep = this.store.doc.collab
- if (keep) next.collab = keep
- else delete next.collab
- this.store.replaceDoc(next)
+ this.store.replaceDoc(parsed.doc)
// the load report, summarised; the whole thing goes to the console
// where an agent driving the page (or a person) can read the paths
const r = parsed.report
@@ -2801,6 +2796,10 @@ export class Editor {
}
const next = parseDoc(JSON.stringify(parsed))
if (!next) { alert(t('{name} isn’t a Bento document.', { name: named })); return true }
+ // a file is guarded by value only — its own identity, and no key dropped,
+ // since it may come from a newer Bento (restoregate.ts guardOpenedDoc)
+ const neutralised = guardOpenedDoc(next)
+ if (neutralised.length) console.info('[bento] opened file: neutralised', neutralised)
if (writable) adoptFileHandle(handle)
this.openedAs = named
diff --git a/slides/src/fonts.ts b/slides/src/fonts.ts
index f8bd03b0..411a7c9a 100644
--- a/slides/src/fonts.ts
+++ b/slides/src/fonts.ts
@@ -30,6 +30,20 @@ export function resolveFontSrc(doc: BentoDoc, asset: string): string | undefined
return doc.assets?.[asset] ?? BUILTIN_FONTS[asset]
}
+/**
+ * The src an @font-face may use: EMBEDDED bytes (a `data:` URI) or nothing. A
+ * font in a self-contained file is always its own bytes, so there is no
+ * legitimate external src; anything else — an address in the asset table,
+ * whatever route put it there (a paste, a script, the file itself) — would be
+ * fetched the moment text in that family renders. Such a face is skipped and
+ * the family falls back to the system stack. Checked here, where every face
+ * is written, so no load path can bypass it. Exact prefix, no trimming:
+ * leading whitespace does not make it a data URI.
+ */
+export function embeddedFontSrc(src: string | undefined): string {
+ return typeof src === 'string' && /^data:/i.test(src) ? src : ''
+}
+
/**
* At save: a deck that embeds bytes IDENTICAL to a built-in face is rewritten
* to name the face instead, and the bytes leave the file. Byte equality, not
@@ -84,7 +98,7 @@ const injected = new WeakMap<HTMLStyleElement, string[]>()
* touch the stylesheet, so unrelated edits never restart font loading. */
export function injectFonts(doc: BentoDoc) {
const faces = (doc.fonts ?? []).map(f => ({
- family: f.family, src: resolveFontSrc(doc, f.asset) ?? '',
+ family: f.family, src: embeddedFontSrc(resolveFontSrc(doc, f.asset)),
weight: f.weight ?? 'normal', style: f.style ?? 'normal',
}))
const signature = faces.flatMap(f => [f.family, f.src, f.weight, f.style])
diff --git a/slides/src/main.ts b/slides/src/main.ts
index 037e4b1d..3938522c 100644
--- a/slides/src/main.ts
+++ b/slides/src/main.ts
@@ -20,6 +20,13 @@ import { i18nApi, t, applyDirection } from './i18n'
import { parseDoc, type BentoDoc, type TextElement } from './model'
import { compactJson } from './compact'
import { parseDocInputReport, fitAutoHeights, restack, type LoadReport } from './compactload'
+import { guardOpenedDoc } from './restoregate'
+import type { Dropped } from './untrusted'
+
+/** Say on the console what the open-file guard neutralised, if anything. */
+function reportGuard(dropped: Dropped[]) {
+ if (dropped.length) console.info('[bento] opened file: neutralised', dropped)
+}
import { validateDoc, type ValidateOpts } from './validate'
import { buildSchema } from './schema'
import { resolveThemeRefs } from './palette'
@@ -80,6 +87,9 @@ if (envelope) {
void passwordGate()
} else {
const parsed = embedded ? parseDoc(embedded) : null
+ // the file's own document, guarded by value, keys and identity kept
+ // (restoregate.ts guardOpenedDoc — a file may be from a newer Bento)
+ if (parsed) reportGuard(guardOpenedDoc(parsed))
// Whether this is OUR starter or someone's document is knowable only here —
// downstream the two are indistinguishable, and the difference is what stops
// the return gate appearing over real work.
@@ -117,6 +127,7 @@ async function passwordGate() {
err.textContent = t('Wrong password — try again')
return
}
+ reportGuard(guardOpenedDoc(doc)) // the password proves who can read it, not what it holds
setEncryptionPassword(pass) // saves + updates keep writing encrypted
gate.remove()
bootWith(doc)
@@ -322,7 +333,9 @@ dismissSplash()
* AI/tooling round-trip: replace the whole document from a JSON string
* (the contents of #bento-doc, or a COMPACT document — `"compact": true`
* with defaults omitted, nested element arrays and missing ids allowed; see
- * src/compact.ts). Validates via parseDoc; returns false and changes
+ * src/compact.ts). The input passes the untrusted document gate (unknown or
+ * malformed fields are dropped and listed in the report) and keeps the open
+ * deck's docId, live session and file mode; returns false and changes
* nothing on invalid input. Undoable in the editor.
*
* On success returns the LOAD REPORT (truthy, so `if (loadDoc(j))` still
@@ -333,7 +346,10 @@ dismissSplash()
* An agent's loop: load → read dropped/findings → fix → load again.
*/
loadDoc(json: string): LoadReport | false {
- const parsed = parseDocInputReport(json)
+ // foreign input, gated like "Replace from JSON…"; it replaces the OPEN
+ // deck's content, so the open deck's identity (docId, collab, readonly)
+ // is kept — see compactload.ts
+ const parsed = parseDocInputReport(json, { live: store.doc })
if (!parsed) return false
store.replaceDoc(parsed.doc)
// Heights measured while a deck font was still downloading are measured
diff --git a/slides/src/model.ts b/slides/src/model.ts
index 602cec65..1e703e09 100644
--- a/slides/src/model.ts
+++ b/slides/src/model.ts
@@ -1355,6 +1355,70 @@ export function newDoc(): BentoDoc {
}
}
+const isRecord = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v)
+
+/**
+ * The keys without which an element of a type cannot render — the renderer
+ * throws, rather than defaulting, when one is missing (see untrusted.ts for
+ * why the frame numbers, svg and embed are NOT here). Both gates use it:
+ * untrusted.ts drops a pasted element that lacks one, parseDoc drops a file's.
+ */
+export const REQUIRED_ELEMENT_KEYS: Readonly<Record<string, readonly string[]>> = {
+ text: ['html'],
+ shape: ['shape', 'fill'],
+ image: ['src'],
+ chart: ['option'],
+ table: ['columns', 'rows'],
+ media: ['kind', 'src'],
+}
+
+/** Can this element render? An object with a string `type` and every key its
+ * type requires. An element of a type this version does not know passes — a
+ * newer file's element is kept and saved back untouched. */
+const renderableElement = (e: unknown): boolean =>
+ isRecord(e) && typeof e.type === 'string' &&
+ (REQUIRED_ELEMENT_KEYS[e.type] ?? []).every((k) => e[k] !== undefined && e[k] !== null)
+
+/**
+ * Fill the fields the format REQUIRES but a hand- or agent-written document
+ * may omit: `title`, `version`, `size`, `theme` (and its four colour/face
+ * keys), and on each slide `id`, `background`, `transition`, `elements` and
+ * `notes`. A document that omitted `theme` passed parseDoc and then crashed
+ * the shell at boot — `undefined.palette` — leaving the reader on the splash
+ * for good; a missing `size` did the same on `width`. Each value comes from the
+ * editor's own defaults (newDoc, emptySlide), and ONLY where the field is
+ * absent or the wrong type: a value that is there is never touched, and keys
+ * this version does not know ride through untouched (format additivity — a
+ * newer file keeps everything). A slide that is not an object is dropped,
+ * since no version writes one, and so is an element that cannot render (not
+ * an object, no `type`, or missing a key its type requires — the same rule the
+ * paste gate applies); false when no slide is left. In place.
+ */
+function fillRequired(doc: Record<string, unknown>): boolean {
+ const base = newDoc()
+ if (typeof doc.title !== 'string') doc.title = base.title
+ if (typeof doc.version !== 'number') doc.version = base.version
+ const size = doc.size as Record<string, unknown> | undefined
+ if (!isRecord(size) || !(Number(size.width) > 0) || !(Number(size.height) > 0)) doc.size = { ...base.size }
+ if (!isRecord(doc.theme)) doc.theme = { ...base.theme }
+ else {
+ const theme = doc.theme
+ for (const k of ['background', 'color', 'accent', 'fontFamily'] as const) {
+ if (typeof theme[k] !== 'string') theme[k] = base.theme[k]
+ }
+ }
+ doc.slides = (doc.slides as unknown[]).filter(isRecord)
+ for (const s of doc.slides as Record<string, unknown>[]) {
+ const blank = emptySlide()
+ if (typeof s.id !== 'string' || !s.id) s.id = blank.id
+ if (typeof s.background !== 'string') s.background = blank.background
+ if (typeof s.transition !== 'string') s.transition = blank.transition
+ s.elements = Array.isArray(s.elements) ? s.elements.filter(renderableElement) : []
+ if (typeof s.notes !== 'string') s.notes = blank.notes
+ }
+ return (doc.slides as unknown[]).length > 0
+}
+
export function parseDoc(json: string): BentoDoc | null {
try {
const doc = JSON.parse(json)
@@ -1372,7 +1436,7 @@ export function parseDoc(json: string): BentoDoc | null {
doc.docId = newDocId()
delete doc.collab
}
- return doc as BentoDoc
+ return fillRequired(doc) ? (doc as BentoDoc) : null
}
} catch {
/* fall through */
diff --git a/slides/src/restoregate.ts b/slides/src/restoregate.ts
index 6bcfb0ec..f132029c 100644
--- a/slides/src/restoregate.ts
+++ b/slides/src/restoregate.ts
@@ -24,12 +24,15 @@
// Deliberately DOM-free, so the rig runs it in node.
import { MODEL_KEYS } from './modelkeys.generated'
-import { parseDoc, type BentoDoc, type Slide } from './model'
-import { LIMITS, sanitizeAssets, sanitizeFonts, sanitizeSlide, withDropReport, withPathSegment, type Dropped } from './untrusted'
+import { FORMAT, parseDoc, type BentoDoc, type Slide } from './model'
+import { LIMITS, SLIDE_CHECKS, sanitizeAssets, sanitizeFonts, sanitizeSlide, withDropReport, withPathSegment, type Dropped } from './untrusted'
const DOC_KEYS = new Set<string>(MODEL_KEYS.doc)
-/** identity and capability: always the open file's, never the snapshot's */
-const FROM_LIVE = ['docId', 'collab', 'readonly'] as const
+/** identity and capability: always the open file's, never the snapshot's. Shared
+ * with the Store's undo/redo (store.ts restore()), which keeps the same set live
+ * so Cmd-Z never resurrects an old docId, a stale sharing flag, or a dropped
+ * read-only mode. */
+export const FROM_LIVE = ['docId', 'collab', 'readonly'] as const
const isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v)
@@ -80,13 +83,38 @@ export function gateRestored(json: string, live: BentoDoc): { doc: BentoDoc; dro
let raw: unknown
try { raw = JSON.parse(json) } catch { return null }
if (!isObj(raw)) return null
+ // A snapshot slide with no id is junk, never a slide autosave wrote. parseDoc
+ // now MINTS a missing id (so a hand-written FILE still opens), which would
+ // turn that junk into a blank slide worth offering — so it is dropped here,
+ // first, exactly as sanitizeSlide below always dropped it.
+ if (Array.isArray(raw.slides)) raw.slides = raw.slides.filter((s) => isObj(s) && typeof s.id === 'string' && s.id !== '')
// parseDoc is the format check. A `template` flag makes it mint a new
// identity and drop collab — harmless here, because identity is replaced
// with the open file's below either way
const base = parseDoc(JSON.stringify(raw)) as unknown as Record<string, unknown> | null
if (!base) return null
+ return sanitizeDoc(base, live)
+}
+
+const DEFAULT_SIZE = { width: 1280, height: 720 }
- const liveRec = live as unknown as Record<string, unknown>
+/**
+ * THE structural gate for a whole document arriving from outside: a restored
+ * snapshot (gateRestored, above) and pasted or scripted document JSON
+ * (compactload.ts parseDocInputReport — "Replace from JSON…", loadDoc). `base`
+ * has already passed parseDoc's format check.
+ *
+ * Rebuilt in the input's key order: keys outside the format dropped; slides and
+ * layouts through sanitizeSlide, assets and fonts through their sanitizers,
+ * blob refs shape-checked, settings objects kept to plain values. With `live`,
+ * identity and capability (docId, collab, readonly) are the OPEN document's,
+ * present or absent, whatever the input says — content is imported, identity
+ * is not. Without `live` they are the input's own (no caller relies on that
+ * yet; opening a file keeps its own identity by design). Null when no slide
+ * survives.
+ */
+export function sanitizeDoc(base: Record<string, unknown>, live?: BentoDoc): { doc: BentoDoc; dropped: Dropped[] } | null {
+ const liveRec = live as unknown as Record<string, unknown> | undefined
const { result, dropped } = withDropReport(() => {
const extra: Dropped[] = []
const out: Record<string, unknown> = {}
@@ -97,10 +125,13 @@ export function gateRestored(json: string, live: BentoDoc): { doc: BentoDoc; dro
// byte-identical to what was saved
for (const key of Object.keys(base)) {
if (!DOC_KEYS.has(key)) { extra.push({ path: `/${key}`, reason: 'unknown document key — dropped' }); continue }
- if ((FROM_LIVE as readonly string[]).includes(key)) { if (liveRec[key] !== undefined) out[key] = liveRec[key]; continue }
+ if ((FROM_LIVE as readonly string[]).includes(key)) {
+ if (liveRec) { if (liveRec[key] !== undefined) out[key] = liveRec[key] } else out[key] = base[key]
+ continue
+ }
const v = base[key]
switch (key) {
- case 'format': out.format = live.format; break
+ case 'format': out.format = FORMAT; break
case 'template': break
case 'slides': out.slides = gated(v, 'slides'); break
case 'layouts': out.layouts = gated(v, 'layouts'); break
@@ -112,13 +143,60 @@ export function gateRestored(json: string, live: BentoDoc): { doc: BentoDoc; dro
default: { const o = plainObject(v, `/${key}`, extra); if (o) out[key] = o }
}
}
- // identity the snapshot left out is still the open file's
- for (const k of FROM_LIVE) if (!(k in out) && liveRec[k] !== undefined) out[k] = liveRec[k]
+ // identity the input left out is still the open document's
+ if (liveRec) for (const k of FROM_LIVE) if (!(k in out) && liveRec[k] !== undefined) out[k] = liveRec[k]
return { out, extra }
})
const doc = result.out as unknown as BentoDoc
- if (!doc.slides.length) return null
- if (!doc.size || typeof doc.size.width !== 'number' || typeof doc.size.height !== 'number') doc.size = live.size
- if (!isObj(doc.theme)) doc.theme = live.theme
+ if (!Array.isArray(doc.slides) || !doc.slides.length) return null
+ if (!doc.size || typeof doc.size.width !== 'number' || typeof doc.size.height !== 'number') doc.size = live?.size ?? { ...DEFAULT_SIZE }
+ if (!isObj(doc.theme) && live) doc.theme = live.theme
return { doc, dropped: [...dropped, ...result.extra] }
}
+
+/**
+ * The guard a FILE gets when it is opened — booted from its own #bento-doc,
+ * unlocked from its password envelope, or opened from disk into the editor.
+ * Not the rebuild above: a file may come from a NEWER Bento, and dropping the
+ * keys this version does not know would lose them on the next save (PLATFORM:
+ * format additivity). So nothing is rebuilt and no key is dropped; only the
+ * document-level fields that reach CSS outside the element sanitizers are
+ * checked, BY VALUE, in place:
+ * - every slide and layout background, and theme.background (which the save
+ * preview writes straight into a style), by the same colour rule a pasted
+ * slide meets — a value that fails becomes "" (no background), the slide stays;
+ * - doc.fonts through sanitizeFonts: weight/style reach an @font-face rule raw.
+ * (The font SRC is held to embedded bytes in fonts.ts embeddedFontSrc, for
+ * every path.)
+ * Identity — docId, collab, readonly — is the file's own and is not touched:
+ * opening a shared file must still join its room and find its own history.
+ * Returns what was neutralised, for the console.
+ */
+export function guardOpenedDoc(doc: BentoDoc): Dropped[] {
+ const out: Dropped[] = []
+ // '' is "no background" already — nothing to clear, nothing to report
+ const okBackground = (v: unknown) => v === '' || SLIDE_CHECKS.background(v) !== undefined
+ const guard = (list: unknown, where: string) => {
+ if (!Array.isArray(list)) return
+ list.forEach((s, i) => {
+ if (!isObj(s) || !('background' in s) || okBackground(s.background)) return
+ s.background = ''
+ out.push({ path: `/${where}/${i}/background`, reason: 'not a colour — cleared' })
+ })
+ }
+ guard(doc.slides, 'slides')
+ guard(doc.layouts, 'layouts')
+ const theme = doc.theme as unknown
+ if (isObj(theme) && 'background' in theme && !okBackground(theme.background)) {
+ theme.background = ''
+ out.push({ path: '/theme/background', reason: 'not a colour — cleared' })
+ }
+ if (doc.fonts !== undefined) {
+ const after = sanitizeFonts(doc.fonts)
+ if (JSON.stringify(after) !== JSON.stringify(doc.fonts)) {
+ out.push({ path: '/fonts', reason: 'font entries outside the CSS-value rule — dropped or trimmed' })
+ }
+ doc.fonts = after
+ }
+ return out
+}
diff --git a/slides/src/store.ts b/slides/src/store.ts
index 70721b82..e6609fcb 100644
--- a/slides/src/store.ts
+++ b/slides/src/store.ts
@@ -2,6 +2,7 @@
// Copyright (c) 2026 The Bento authors
import { inLinearFlow } from './model'
import type { BentoDoc, Slide, SlideElement } from './model'
+import { FROM_LIVE } from './restoregate'
export type StoreEvent =
| 'doc' // any document mutation
@@ -167,7 +168,17 @@ export class Store {
if (!entry) return
const before = this.captureView()
to.push({ doc: JSON.stringify(this.doc), view: before })
+ const live = this.doc // identity/capability is the open file's, not undoable
this.doc = JSON.parse(entry.doc)
+ // Undo/redo move CONTENT, never identity: keep the live docId, collab and
+ // read-only mode (restoregate's FROM_LIVE) rather than the snapshot's, so
+ // Cmd-Z can't flip sharing back on, resurrect a pre-"Duplicate as new deck"
+ // docId, or drop a present-only save's mode. One shared list, no second copy.
+ for (const k of FROM_LIVE) {
+ const v = (live as unknown as Record<string, unknown>)[k]
+ if (v !== undefined) (this.doc as unknown as Record<string, unknown>)[k] = v
+ else delete (this.doc as unknown as Record<string, unknown>)[k]
+ }
this.reconcileView(before, entry.view)
this.setDirty(true)
this.emit('doc')
diff --git a/slides/src/untrusted.ts b/slides/src/untrusted.ts
index cd5eafa5..1c7f8f78 100644
--- a/slides/src/untrusted.ts
+++ b/slides/src/untrusted.ts
@@ -41,7 +41,7 @@
import { stripEnvelope } from './envelope'
import type { Slide, SlideElement } from './model'
-import { isWebUrl } from './model'
+import { isWebUrl, REQUIRED_ELEMENT_KEYS } from './model'
import { parseThemeRef } from './palette.ts'
import { MODEL_KEYS } from './modelkeys.generated'
import { TIP_KINDS } from './tips'
@@ -534,14 +534,9 @@ export const ELEMENT_CHECKS: Record<string, Check> = {
* absent for the same reason: an empty or refused `view` paints a
* placeholder, never throws.
*/
-const REQUIRED_ELEMENT_KEYS: Record<string, readonly string[]> = {
- text: ['html'],
- shape: ['shape', 'fill'],
- image: ['src'],
- chart: ['option'],
- table: ['columns', 'rows'],
- media: ['kind', 'src'],
-}
+// The table itself lives in model.ts: parseDoc holds a FILE to the same rule
+// (an element that cannot render is dropped there too), and one list cannot
+// drift from itself.
/** Exported so the rig can prove each name is a real key of that element type. */
export const REQUIRED_KEYS: Readonly<Record<string, readonly string[]>> = REQUIRED_ELEMENT_KEYS