Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Release 1.2.5 (#577)
nyblnet3a26dba7ee53
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex c975ef4a..13ef8848 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -918,6 +918,13 @@ jobs:# a reader and a writer that share a bug agree with each other perfectly.run: node scripts/test-dash-zip.ts+ - name: zip decompression-bomb cap+ # readZip caps each entry's inflated output at min(declared size, a hard+ # ceiling), aborting the stream the instant it overflows — a crafted+ # archive that under-declares its size can no longer exhaust memory before+ # the size check runs. Every check is mutation-proven against a neutered cap.+ run: node scripts/test-zip-bomb.ts+- name: bento/dash xlsx# Both 1900 date epochs, including the leap-year bug — getting it wrong# shifts every date by four years, silently.@@ -1788,6 +1795,14 @@ jobs:slides/node_modules/.bin/esbuild scripts/test-clipboard.ts --bundle --platform=node --format=esm --outfile="$RUNNER_TEMP/test-clipboard.mjs"node "$RUNNER_TEMP/test-clipboard.mjs"+ - name: Restore gate rig+ # A snapshot kept in the browser (recovery banner, Version history) is+ # foreign input: gated like a pasted clip, and it never brings its own+ # docId, live-session credentials or file mode.+ run: |+ slides/node_modules/.bin/esbuild scripts/test-slides-restore-gate.ts --bundle --platform=node --format=esm --outfile="$RUNNER_TEMP/test-slides-restore-gate.mjs"+ node "$RUNNER_TEMP/test-slides-restore-gate.mjs"+- name: CRDT property-removal rig# Removing a property travels as a `set` op with `v` ABSENT, and the# receiving replica threw on it: JSON.stringify(undefined) is undefined,diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ddc393a9..1a50778d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,11 @@ pre-1.0.## [Unreleased]+## [1.2.5] — 2026-09-28++- **Security: update this file. This release closes three security 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.- **Orange text can be read in dark mode again.** The armed comment tool, thetick beside your language, your own name in a comment thread and the labelson slide and point comments were drawn in a dark brown meant for text on thediff --git a/kernel/src/convert/zip.ts b/kernel/src/convert/zip.tsindex 89026584..fadef8f7 100644--- a/kernel/src/convert/zip.ts+++ b/kernel/src/convert/zip.ts@@ -40,6 +40,22 @@ export class ZipError extends Error {constructor(message: string) { super(message); this.name = 'ZipError' }}+/** Thrown when a single entry's decompressed output passes its cap — a+ * decompression bomb. A subclass so readZip can tell it apart from an ordinary+ * inflate failure and give the user the right refusal. */+export class ZipBombError extends ZipError {+ constructor(message: string) { super(message); this.name = 'ZipBombError' }+}++/** The hard per-entry output ceiling, the backstop when a crafted archive+ * DECLARES a huge uncompressed size (the declared size is otherwise the cap).+ * DEFLATE expands up to ~1032:1, so a real on-disk few-MB entry can inflate to+ * many GB; without a cap that lands as a tab-killing allocation before any size+ * check runs. 256 MiB is far above any legitimate OPC part and well below the+ * point a browser tab dies; an app with a stricter budget passes its own+ * `maxEntryBytes` to readZip (convert's preflight sits below this). */+export const MAX_ENTRY_BYTES = 256 * 1024 * 1024+const SIG_LOCAL = 0x04034b50const SIG_CD = 0x02014b50const SIG_EOCD = 0x06054b50@@ -81,16 +97,40 @@ export function crc32(b: Uint8Array): number {const hasCompression = (): boolean => typeof CompressionStream !== 'undefined'-async function through(b: Uint8Array, s: ReadableWritablePair<Uint8Array, Uint8Array>): Promise<Uint8Array> {+async function through(+ b: Uint8Array,+ s: ReadableWritablePair<Uint8Array, Uint8Array>,+ cap = Infinity,+): Promise<Uint8Array> {// A Blob is the shortest route from bytes to a ReadableStream that works- // identically in a browser and in node's rigs; `Response.arrayBuffer` is the- // shortest route back. Neither allocates more than one extra copy.- const out = new Blob([b as BlobPart]).stream().pipeThrough(s as ReadableWritablePair<BufferSource, BufferSource>)- return new Uint8Array(await new Response(out as BodyInit).arrayBuffer())+ // identically in a browser and in node's rigs.+ const out = new Blob([b as BlobPart]).stream()+ .pipeThrough(s as ReadableWritablePair<BufferSource, BufferSource>) as unknown as ReadableStream<Uint8Array>+ // Uncapped (the write side): `Response.arrayBuffer` is the shortest route back+ // and this path is unchanged.+ if (cap === Infinity) return new Uint8Array(await new Response(out as BodyInit).arrayBuffer())+ // Capped (inflate): read incrementally and ABORT the moment cumulative output+ // passes the cap, so a decompression bomb never gets its full output allocated+ // — the guard that used to run only AFTER the whole stream was in memory.+ const reader = out.getReader()+ const chunks: Uint8Array[] = []+ let total = 0+ for (;;) {+ const { done, value } = await reader.read()+ if (done) break+ if (!value) continue+ total += value.length+ if (total > cap) {+ await reader.cancel().catch(() => {})+ throw new ZipBombError(`decompressed output exceeded its ${cap}-byte cap`)+ }+ chunks.push(value)+ }+ return concat(chunks)}-const inflateRaw = (b: Uint8Array): Promise<Uint8Array> =>- through(b, new DecompressionStream('deflate-raw') as unknown as ReadableWritablePair<Uint8Array, Uint8Array>)+const inflateRaw = (b: Uint8Array, cap = Infinity): Promise<Uint8Array> =>+ through(b, new DecompressionStream('deflate-raw') as unknown as ReadableWritablePair<Uint8Array, Uint8Array>, cap)const deflateRaw = (b: Uint8Array): Promise<Uint8Array> =>through(b, new CompressionStream('deflate-raw') as unknown as ReadableWritablePair<Uint8Array, Uint8Array>)@@ -136,7 +176,11 @@ function findEocd(v: DataView, len: number): number {* that stops early and a total that is wrong by exactly the missing rows, and* nothing on screen says so.*/-export async function readZip(bytes: Uint8Array): Promise<ZipParts> {+export async function readZip(+ bytes: Uint8Array,+ opts: { maxEntryBytes?: number } = {},+): Promise<ZipParts> {+ const ceiling = opts.maxEntryBytes ?? MAX_ENTRY_BYTESif (bytes.length < 22) throw new ZipError('this file is too small to be a ZIP archive')const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)const eocd = findEocd(v, bytes.length)@@ -215,9 +259,17 @@ export async function readZip(bytes: Uint8Array): Promise<ZipParts> {// caller saw an unnamed exception from somewhere inside a stream and had// nothing to tell the user. Every failure this file can produce has to// arrive as a ZipError naming the part, or the refusal is not a refusal.+ // The cap is the DECLARED size (a legitimate entry inflates to exactly+ // that), floored by the hard ceiling for an archive that declares a huge+ // one. A crafted archive that UNDER-declares — the bomb — expands past its+ // own declared usize and trips the cap long before memory is gone.+ const cap = Math.min(usize, ceiling)try {- data = await inflateRaw(raw)- } catch {+ data = await inflateRaw(raw, cap)+ } catch (e) {+ if (e instanceof ZipBombError) {+ throw new ZipError(`"${name}" expands past its ${cap}-byte cap — refusing it as a possible decompression bomb`)+ }throw new ZipError(`"${name}" could not be decompressed — the file is damaged or truncated`)}} else throw new ZipError(`"${name}" uses compression method ${method}, which dash does not implement`)diff --git a/schema/slides-1.2.5.json b/schema/slides-1.2.5.jsonnew file mode 100644index 00000000..fb05a163--- /dev/null+++ b/schema/slides-1.2.5.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.5",+ "$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.jsonindex 482ec7a6..fb05a163 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.4",+ "x-bento-version": "1.2.5","$ref": "#/$defs/doc","$defs": {"prop-fx": {diff --git a/scripts/test-slides-restore-gate.ts b/scripts/test-slides-restore-gate.tsnew file mode 100644index 00000000..7f328268--- /dev/null+++ b/scripts/test-slides-restore-gate.ts@@ -0,0 +1,128 @@+#!/usr/bin/env node+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// A document kept in this browser is gated before it replaces the open one.+//+// BUNDLED, not run directly — untrusted.ts imports extensionless — and run+// from the repo root (it reads editor.ts from there):+//+// slides/node_modules/.bin/esbuild scripts/test-slides-restore-gate.ts --bundle \+// --platform=node --format=esm --outfile="$TMPDIR/test-slides-restore-gate.mjs" \+// && node "$TMPDIR/test-slides-restore-gate.mjs"+//+// WHAT THIS PROVES. The "Restore your unsaved changes?" snapshot and every+// Version history entry live in IndexedDB under the deck's docId — and on+// file:// that store is shared by every local document. Restore used to hand+// the stored JSON straight to store.replaceDoc. Now (slides/src/restoregate.ts):+// 1. a snapshot never brings identity or capability: docId, collab and+// readonly are the OPEN FILE's, present or absent, whatever it carries;+// 2. its content passes the untrusted gate a pasted clip does — unknown+// keys, bad enums and malformed elements are dropped, not kept;+// 3. an honest snapshot of a real deck comes back as it went in, key for+// key (nothing legitimate is lost to the gate);+// 4. something that is not a document, or has no slide left, is never+// offered;+// 5. every restore path in the editor goes through the gate — no raw+// replaceDoc of stored JSON remains.++import { readFileSync } from 'node:fs'+import { join } from 'node:path'+import { gateRestored } from '../slides/src/restoregate.ts'+import { starterDoc } from '../slides/src/starterdeck.ts'+import type { BentoDoc } from '../slides/src/model.ts'++let failures = 0+let checks = 0+function ok(cond: boolean, msg: string) {+ checks+++ if (!cond) { failures++; console.log(` FAIL ${msg}`) }+ else console.log(` ok ${msg}`)+}+const clone = <T>(v: T): T => JSON.parse(JSON.stringify(v))+// the same document regardless of key order (the gate rebuilds each element+// key by key, type first, as the paste gate does)+const canon = (v: unknown): string => JSON.stringify(v, (_k, x) => x && typeof x === 'object' && !Array.isArray(x)+ ? Object.fromEntries(Object.keys(x).sort().map((k) => [k, x[k]])) : x)+const root = process.cwd()++const live = starterDoc()+live.collab = { v: 2, room: 'wLIVEROOM', key: 'live-key', on: true } as unknown as BentoDoc['collab']++console.log('identity and capability are the open file\'s\n')+{+ const snap = clone(live) as unknown as Record<string, unknown>+ snap.docId = 'some-other-deck'+ snap.collab = { v: 2, room: 'wOTHERROOM', key: 'other-key', on: true }+ snap.readonly = true+ const g = gateRestored(JSON.stringify(snap), live)+ ok(!!g && g.doc.docId === live.docId, `docId stays the open file's (${g?.doc.docId})`)+ ok(!!g && JSON.stringify(g.doc.collab) === JSON.stringify(live.collab), 'collab stays the open file\'s room and key')+ ok(!!g && g.doc.readonly === undefined, 'a snapshot cannot turn the deck into a present-only player')+}+{+ const noCollab = clone(live); delete noCollab.collab+ const snap = clone(live) as unknown as Record<string, unknown>+ snap.collab = { v: 2, room: 'wOTHERROOM', key: 'other-key', on: true }+ const g = gateRestored(JSON.stringify(snap), noCollab)+ ok(!!g && g.doc.collab === undefined, 'a deck with no live session does not gain one from a snapshot')+}+{+ // a snapshot that simply OMITS the identity still gets the open file's+ const snap = clone(live) as unknown as Record<string, unknown>+ delete snap.collab+ const g = gateRestored(JSON.stringify(snap), live)+ ok(!!g && JSON.stringify(g.doc.collab) === JSON.stringify(live.collab), 'a snapshot without collab still restores into the open file\'s live session')+}+{+ const snap = clone(live) as unknown as Record<string, unknown>+ snap.template = true+ const g = gateRestored(JSON.stringify(snap), live)+ ok(!!g && g.doc.docId === live.docId && !('template' in g.doc), 'a `template` flag does not re-mint the identity or survive')+}++console.log('\ncontent passes the untrusted gate\n')+{+ const snap = clone(live) as unknown as Record<string, any>+ snap.notAField = 'x'+ const el = snap.slides[0].elements[0]+ el.notAKey = 'x'+ snap.slides[0].transition = 'not-a-transition'+ snap.slides[1].elements.push({ type: 'no-such-type', id: 'junk', x: 0, y: 0, w: 10, h: 10 })+ snap.theme.nested = { deep: { deeper: 1 } }+ const g = gateRestored(JSON.stringify(snap), live)+ const s = g ? JSON.stringify(g.doc) : ''+ ok(!!g && !('notAField' in g.doc), 'an unknown document key is dropped')+ ok(!!g && !('notAKey' in (g.doc.slides[0].elements[0] as object)), 'an unknown element key is dropped')+ ok(!!g && g.doc.slides[0].transition !== 'not-a-transition', 'an enum outside the format\'s literals is dropped')+ ok(!!g && !s.includes('"junk"'), 'an element of an unknown type is dropped')+ ok(!!g && !('deep' in ((g.doc.theme as Record<string, object>).nested ?? {})), 'a settings object keeps plain values, one nested level at most')+ ok(!!g && g.dropped.length >= 5, `the drops are reported (${g?.dropped.length})`)+}++console.log('\nan honest snapshot round-trips\n')+{+ const g = gateRestored(JSON.stringify(live), live)+ ok(!!g && canon(g.doc) === canon(live), 'the starter deck (every feature it shows) comes back identical, key for key')+ ok(!!g && g.dropped.length === 0, `nothing is dropped from it (${g?.dropped.map((d) => d.path).join(', ') || 'none'})`)+}++console.log('\nnot a document → never offered\n')+ok(gateRestored('not json', live) === null, 'unparseable text')+ok(gateRestored('[]', live) === null, 'a JSON array')+ok(gateRestored(JSON.stringify({ format: 'something/else', slides: [{ id: 's' }] }), live) === null, 'another format')+ok(gateRestored(JSON.stringify({ ...clone(live), slides: [{ no: 'id' }] }), live) === null, 'a document with no slide that survives the gate')++console.log('\nevery restore path uses the gate\n')+{+ const src = readFileSync(join(root, 'slides/src/editor/editor.ts'), 'utf8')+ const check = src.slice(src.indexOf('private async checkRecovery()'), src.indexOf('private async checkRecovery()') + 900)+ const banner = src.slice(src.indexOf('private showRecoveryBanner('), src.indexOf('private showRecoveryBanner(') + 1400)+ const history = src.slice(src.indexOf('private async openVersionHistory()'), src.indexOf('private async openVersionHistory()') + 2400)+ ok(/gateRestored\(snap\.json, doc\)/.test(check), 'the recovery check gates before offering')+ ok(/gateRestored\(snap\.json, this\.store\.doc\)[\s\S]*replaceDoc\(gated\.doc\)/.test(banner), 'Restore gates against the CURRENT document, then applies the gated one')+ ok(/gateRestored\(v\.json, this\.store\.doc\)[\s\S]*replaceDoc\(gated\.doc\)/.test(history), 'Version history restore gates the same way')+ ok(!/replaceDoc\((recovered|JSON\.parse\(v\.json\)|JSON\.parse\(snap\.json\))\)/.test(src), 'no raw replaceDoc of stored JSON remains')+}++console.log(`\n${checks - failures}/${checks} checks passed`)+process.exit(failures ? 1 : 0)diff --git a/scripts/test-zip-bomb.ts b/scripts/test-zip-bomb.tsnew file mode 100644index 00000000..11787efb--- /dev/null+++ b/scripts/test-zip-bomb.ts@@ -0,0 +1,97 @@+#!/usr/bin/env node+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// kernel/src/convert/zip.ts — the decompression-bomb output cap.+//+// node scripts/test-zip-bomb.ts+//+// WHAT THIS PROVES. readZip used to inflate a deflated entry FULLY into memory+// and only THEN check its size against the central directory — so an archive+// whose header UNDER-declares the uncompressed size (deflate expands ~1032:1)+// exhausted memory before any guard ran. The fix caps output INSIDE the inflate,+// at min(declared size, a hard per-entry ceiling), aborting the stream the+// instant cumulative output passes the cap. These checks pin that:+// 1. an entry that expands past its DECLARED usize throws at the cap, not OOM;+// 2. an entry that expands past the HARD CEILING throws at the cap;+// 3. a legitimate entry at/under the ceiling still opens, bytes intact;+// 4. a STORED entry that lies about its size is refused, not crashed.+// All fixtures are tiny (≤256 KB) — the point is that the cap fires early, so the+// bomb never needs to be big to be caught, and the rig never allocates a bomb.++import { writeZip, readZip, ZipError, ZipBombError, MAX_ENTRY_BYTES, _internals } from '../kernel/src/convert/zip.ts'++let failures = 0, checks = 0+function ok(what: string, cond: unknown): void {+ checks+++ if (cond) return+ failures+++ console.error(` FAIL ${what}`)+}+async function throwsBomb(what: string, fn: () => Promise<unknown>): Promise<void> {+ checks+++ try { await fn(); failures++; console.error(` FAIL ${what} — it did NOT throw`) }+ catch (e) {+ // Match the CAP refusal specifically ("possible decompression bomb"), not the+ // "truncated or damaged" size-mismatch throw — and not the entry NAME, which+ // is why the fixtures below are named neutrally. Under a neutered cap the+ // size check fires with a different message and this correctly fails.+ const msg = e instanceof Error ? e.message : String(e)+ if (e instanceof ZipError && /decompression bomb/i.test(msg)) return+ failures+++ console.error(` FAIL ${what} — threw the wrong thing: ${e instanceof Error ? e.name : ''} ${msg}`)+ }+}++const zeros = (n: number): Uint8Array => new Uint8Array(n) // deflates ~1000:1++/** Overwrite the central-directory `usize` (uncompressed size) of the first+ * entry with a lie — the crafted-header case, built from a real archive so+ * everything else (csize, offsets, CRC) stays honest. */+function lieAboutSize(zip: Uint8Array, declared: number): Uint8Array {+ const v = new DataView(zip.buffer, zip.byteOffset, zip.byteLength)+ const eocd = _internals.findEocd(v, zip.length)+ const cdOffset = v.getUint32(eocd + 16, true)+ // central-directory record: usize is a u32 at offset +24 (see readZip).+ v.setUint32(cdOffset + 24, declared, true)+ return zip+}++// ————— 1. under-declared usize: expands past what the directory promises —————+{+ const honest = await writeZip([{ name: 'a.bin', data: zeros(256 * 1024) }])+ const lying = lieAboutSize(honest.slice(), 10) // says 10 bytes; expands to 256 KB+ await throwsBomb('an entry that expands past its declared usize is refused', () => readZip(lying))+}++// ————— 2. past the HARD CEILING (declared size honest, ceiling injected tiny) —————+{+ const honest = await writeZip([{ name: 'big.bin', data: zeros(200 * 1024) }])+ await throwsBomb('an entry past the hard ceiling is refused', () => readZip(honest, { maxEntryBytes: 1000 }))+}++// ————— 3. a legitimate entry at/under the ceiling opens, bytes intact —————+{+ const payload = new TextEncoder().encode('the quick brown fox '.repeat(20)) // ~400 B+ const honest = await writeZip([{ name: 'ok.txt', data: payload }])+ const parts = await readZip(honest, { maxEntryBytes: 64 * 1024 }) // well above the entry+ const got = parts.get('ok.txt')+ ok('a legitimate entry under the ceiling still opens', !!got)+ ok('…and its bytes are intact', !!got && got.length === payload.length && got.every((b, i) => b === payload[i]))+}++// ————— 4. a STORED (uncompressed) entry that lies is refused, not crashed —————+{+ // Force store: a payload of ≤64 bytes is stored, not deflated (writeZip rule).+ const honest = await writeZip([{ name: 's.bin', data: new Uint8Array([1, 2, 3, 4]) }])+ const lying = lieAboutSize(honest.slice(), 9999)+ checks+++ try { await readZip(lying); failures++; console.error(' FAIL a stored entry that lies about its size is refused — it did NOT throw') }+ catch (e) { if (!(e instanceof ZipError)) { failures++; console.error(` FAIL stored-lie threw a non-ZipError: ${String(e)}`) } }+}++// ————— sanity: the exported ceiling is a real, sane number —————+ok('MAX_ENTRY_BYTES is a positive byte ceiling', typeof MAX_ENTRY_BYTES === 'number' && MAX_ENTRY_BYTES > 0)+ok('ZipBombError is a ZipError subclass', new ZipBombError('x') instanceof ZipError)++console.log(failures ? `\ntest-zip-bomb: ${failures} FAILED of ${checks}` : `test-zip-bomb: ${checks} checks OK`)+process.exit(failures ? 1 : 0)diff --git a/slides/package.json b/slides/package.jsonindex d0b9e648..87a53131 100644--- a/slides/package.json+++ b/slides/package.json@@ -1,7 +1,7 @@{"name": "bento-slides","private": true,- "version": "1.2.4",+ "version": "1.2.5","license": "MIT","type": "module","scripts": {diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.tsindex 5c8aa1be..1e7196b4 100644--- a/slides/src/editor/editor.ts+++ b/slides/src/editor/editor.ts@@ -42,6 +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 { 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'@@ -2608,10 +2609,12 @@ export class Editor {const doc = this.store.docconst snap = await getRecovery(doc.docId)if (!snap) return- let recovered: import('../model').BentoDoc- try { recovered = JSON.parse(snap.json) } catch { return }- if (docContentKey(recovered) === docContentKey(doc)) return // the file already has these edits- this.showRecoveryBanner(snap, recovered)+ // A snapshot is foreign input (restoregate.ts): offered only if it is a+ // document after the untrusted gate, compared as it WOULD be restored+ const gated = gateRestored(snap.json, doc)+ if (!gated) return+ if (docContentKey(gated.doc) === docContentKey(doc)) return // the file already has these edits+ this.showRecoveryBanner(snap)}/**@@ -2792,7 +2795,7 @@ export class Editor {document.body.appendChild(bar)}- private showRecoveryBanner(snap: Snapshot, recovered: import('../model').BentoDoc) {+ private showRecoveryBanner(snap: Snapshot) {document.querySelector('.ed-recover')?.remove()const bar = div('ed-recover')const when = new Date(snap.at).toLocaleString([], { hour: '2-digit', minute: '2-digit', month: 'short', day: 'numeric' })@@ -2802,7 +2805,13 @@ export class Editor {restore.className = 'ed-btn ed-btn-primary'restore.textContent = t('Restore')restore.addEventListener('click', () => {- this.store.replaceDoc(recovered)+ // gated again against the document as it is NOW: the live session may+ // have been joined or rotated since the banner appeared, and the identity+ // re-attached must be the current one+ const gated = gateRestored(snap.json, this.store.doc)+ if (!gated) { bar.remove(); return }+ if (gated.dropped.length) console.info('[bento] restore: dropped', gated.dropped)+ this.store.replaceDoc(gated.doc)this.canvas.render()bar.remove()this.toast(t('Restored your unsaved changes'))@@ -2840,7 +2849,10 @@ export class Editor {`<span class="vh-do">${t('Restore')}</span>`rowEl.addEventListener('click', () => {try {- this.store.replaceDoc(JSON.parse(v.json))+ const gated = gateRestored(v.json, this.store.doc) // foreign input, as above+ if (!gated) throw new Error('not a document')+ if (gated.dropped.length) console.info('[bento] restore: dropped', gated.dropped)+ this.store.replaceDoc(gated.doc)this.canvas.render()overlay.remove()this.toast(t('Restored the version from {when} — ⌘Z undoes', { when }))diff --git a/slides/src/render.ts b/slides/src/render.tsindex b103c2ff..fa1586ea 100644--- a/slides/src/render.ts+++ b/slides/src/render.ts@@ -838,10 +838,96 @@ export function svgHrefAllowed(value: string, tag = 'image'): boolean {/** Every `url(…)` target in a CSS-ish string, quotes and padding removed. */function urlTargets(value: string): string[] {- return Array.from(value.matchAll(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi))+ return Array.from(cssDecodeIdentEscapes(value).matchAll(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi)).map((m) => m[2].replace(/[\u0000-\u0020]/g, '').toLowerCase())}++/**+ * CSS escapes that spell IDENTIFIER characters, decoded: `\75 ` is `u`, `\72`+ * is `r`, `\l` is `l`. The browser decodes escapes inside an ident before it+ * decides what the token is, so a check over the raw text has to read the+ * letters the browser will read. Escapes for anything else (`\28` for a+ * paren, `\22` for a quote) are left as they are: inside an ident they are+ * just part of the name, never syntax, and decoding them here would invent+ * syntax the browser never sees.+ */+function cssDecodeIdentEscapes(css: string): string {+ return css.replace(/\\([0-9a-fA-F]{1,6})[ \t\n\r\f]?|\\([^\n\r\f0-9a-fA-F])/g, (m, hexs: string | undefined, ch: string | undefined) => {+ const c = hexs ? String.fromCodePoint(Math.min(parseInt(hexs, 16), 0x10ffff)) : ch!+ return /^[-\w]$/.test(c) || c.codePointAt(0)! >= 0x80 ? c : m+ })+}++/**+ * The CSS functions an untrusted svg sheet or style value may call, as an+ * ALLOWLIST, for the reason the at-rules below are one. A function that takes+ * an image can fetch, and some take the address as a bare string with no+ * `url(` in it; a list of the dangerous ones would be one browser release from+ * incomplete. Everything a diagram draws with is here: colour, maths,+ * transforms, gradients, filters, shapes, easing, grid sizing, font-face+ * descriptors, custom properties. `url` is policed on its own (in-document+ * `#` and `data:image/` targets only).+ */+const CSS_FN_ALLOWED = new Set([+ 'rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color', 'color-mix', 'light-dark',+ 'calc', 'min', 'max', 'clamp', 'round', 'mod', 'rem', 'abs', 'sign', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp',+ 'var', 'env',+ 'translate', 'translatex', 'translatey', 'translatez', 'translate3d', 'rotate', 'rotatex', 'rotatey', 'rotatez', 'rotate3d',+ 'scale', 'scalex', 'scaley', 'scalez', 'scale3d', 'skew', 'skewx', 'skewy', 'matrix', 'matrix3d', 'perspective',+ 'cubic-bezier', 'steps', 'linear',+ 'linear-gradient', 'radial-gradient', 'conic-gradient', 'repeating-linear-gradient', 'repeating-radial-gradient', 'repeating-conic-gradient',+ '-webkit-linear-gradient', '-webkit-radial-gradient', '-webkit-repeating-linear-gradient', '-webkit-repeating-radial-gradient',+ 'blur', 'brightness', 'contrast', 'drop-shadow', 'grayscale', 'hue-rotate', 'invert', 'opacity', 'saturate', 'sepia',+ 'circle', 'ellipse', 'inset', 'polygon', 'path', 'rect', 'xywh', 'ray',+ 'counter', 'counters', 'minmax', 'repeat', 'fit-content', 'local', 'format', 'tech', 'selector',+ 'url',+])++/** A function call in CSS text: a name (letters, escapes, non-ASCII) then `(`,+ * not after a colon — `:not(`, `:nth-child(` are selectors, not values. */+const CSS_FN_CALL = /(^|[^:\w\\-])((?:[-\w]|\\[\s\S]|[^\x00-\x7f])+)\(/g++/**+ * Neutralise every function call a sheet may not make: RENAMED to one no+ * browser implements, so the declaration it sits in is invalid and CSS drops+ * it (the same fail-closed move as the at-rules). A name still holding an+ * escape after decoding is refused on sight.+ */+function cssRefuseFunctions(css: string): string {+ return css.replace(CSS_FN_CALL, (m, pre: string, name: string) =>+ !name.includes('\\') && CSS_FN_ALLOWED.has(name.toLowerCase()) ? m : `${pre}bento-refused(`)+}++/** Does this CSS text carry a fetch — an off-list function, or a url() to+ * anything but `#…` / `data:image/…`? Escapes are decoded first. */+function cssFetches(text: string): boolean {+ const t = cssDecodeIdentEscapes(text)+ if (urlTargets(t).some((u) => !(u.startsWith('#') || u.startsWith('data:image/')))) return true+ return Array.from(t.matchAll(CSS_FN_CALL)).some((m) => m[2].includes('\\') || !CSS_FN_ALLOWED.has(m[2].toLowerCase()))+}++/**+ * The browser's own reading of a sheet, where there is a browser. A+ * constructed CSSStyleSheet is parsed but never applied, so nothing in it+ * loads, and its rules serialise CANONICALLY: escapes decoded, a bare-string+ * image function written with `url(…)`. Every top-level rule's cssText (which+ * carries its nested rules: @media, @supports, @layer, nesting) is checked for+ * a fetch the text filter missed. There should never be one; if there is, the+ * whole sheet is dropped rather than trusted. `null` = no CSSOM here (the node+ * rigs), where the text filter, which fails closed on its own, is the answer.+ */+function cssomFindsFetch(css: string): boolean | null {+ if (typeof CSSStyleSheet === 'undefined') return null+ try {+ const sheet = new CSSStyleSheet()+ sheet.replaceSync(css)+ return Array.from(sheet.cssRules).some((r) => cssFetches(r.cssText))+ } catch {+ return true // the browser would not parse it: keep none of it+ }+}+/*** `url(#grad)` is the gradient/marker idiom every diagram is built on;* `url(https://…)` in the same attribute is a live fetch out of a self-@@ -851,8 +937,21 @@ function urlTargets(value: string): string[] {** Exported for `scripts/test-sanitize.ts`.*/-export function svgUrlRefsAllowed(value: string): boolean {- return urlTargets(value).every((t) => t.startsWith('#') || t.startsWith('data:image/'))+export function svgUrlRefsAllowed(value: string, attr = ''): boolean {+ const n = attr.toLowerCase()+ const allowed = (t: string) => t.startsWith('#') || t.startsWith('data:image/')+ // aria-* and data-* are text, never parsed as CSS: an accessible label that+ // reads "f(x) = 2" is not a function call, so only a url() is looked at+ if (n.startsWith('aria-') || n.startsWith('data-')) return urlTargets(value).every(allowed)+ if (cssFetches(value)) return false+ // `style` is a declaration block: where there is a browser, its own parse+ // (on a detached element, which loads nothing) is checked too+ if (n === 'style' && typeof document !== 'undefined') {+ const probe = document.createElement('div')+ probe.style.cssText = value+ if (cssFetches(probe.style.cssText)) return false+ }+ return true}/**@@ -907,10 +1006,16 @@ export function sanitizeSvgCss(css: string): string {(/^-?[a-zA-Z][-\w]*$/.test(kw) && CSS_AT_ALLOWED.has(kw.toLowerCase())? `${pre}@${kw}`: `${pre}@bento-refused `))- return atFiltered.replace(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi, (m, _q: string, target: string) => {+ // Function names are read the way the browser reads them — escapes decoded —+ // before anything is judged, then every function off the allowlist is+ // refused, then url() targets are checked on the decoded text.+ const fnFiltered = cssRefuseFunctions(cssDecodeIdentEscapes(atFiltered))+ const out = fnFiltered.replace(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi, (m, _q: string, target: string) => {const v = String(target).replace(/[\u0000-\u0020]/g, '').toLowerCase()return v.startsWith('#') || v.startsWith('data:image/') ? m : 'none'})+ // …and where there is a browser, its own parse is the last word+ return cssomFindsFetch(out) === true ? '' : out}/**@@ -971,7 +1076,7 @@ export function sanitizeSvg(markup: string, scope: string): DocumentFragment {if (!svgAttrAllowed(target) || /(^|:)(href|style)$/.test(target)) { gone = true; break }continue}- if (!svgUrlRefsAllowed(attr.value) || (name === 'style' && /@import|expression\s*\(/i.test(attr.value))) {+ if (!svgUrlRefsAllowed(attr.value, name) || (name === 'style' && /@import|expression\s*\(/i.test(attr.value))) {el.removeAttribute(attr.name)continue}diff --git a/slides/src/restoregate.ts b/slides/src/restoregate.tsnew file mode 100644index 00000000..6bcfb0ec--- /dev/null+++ b/slides/src/restoregate.ts@@ -0,0 +1,124 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+//+// The gate a document kept in THIS BROWSER passes before it replaces the one+// that is open: the "Restore your unsaved changes?" snapshot and every entry+// in Version history.+//+// WHY IT IS A GATE AT ALL. Those snapshots are not the file. They live in+// IndexedDB under the deck's docId, and on file:// every local .bento.html+// shares one origin — so the store is shared too, readable and writable by+// any other local document. A snapshot is therefore foreign input that arrives+// behind the most trusting prompt in the app ("restore YOUR changes"), and it+// used to go straight into store.replaceDoc as raw JSON.+//+// So it is held to what a pasted clip is held to (untrusted.ts rebuilds every+// slide, layout, asset and font key by key; anything unknown or malformed is+// DROPPED, never repaired), and it never brings its own identity or+// capability: the docId, the live-session credentials (`collab`) and the file+// mode (`readonly`) are the OPEN FILE's, whatever the snapshot says. Content+// is restored; who the deck is, which room it syncs with and whether it can be+// edited are not. A snapshot whose content survives the gate but differs from+// the file is still offered — the point is that what it can do is bounded.+//+// 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'++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++const isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v)++/** A plain value a settings object may hold: a bounded string, a finite+ * number, a boolean, or a short list of those. Anything else is dropped. */+function plain(v: unknown): boolean {+ if (typeof v === 'string') return v.length <= LIMITS.scalar * 5+ if (typeof v === 'number') return Number.isFinite(v)+ if (typeof v === 'boolean') return true+ if (Array.isArray(v)) return v.length <= 64 && v.every((x) => typeof x !== 'object' && plain(x))+ return false+}++/** Settings objects (theme, meta, present, size) keep plain values, and one+ * nested level of them (theme.codePalette is a map of colours) — the deepest+ * any of them goes. Anything deeper or stranger is dropped. */+function plainObject(v: unknown, path: string, dropped: Dropped[], depth = 0): Record<string, unknown> | undefined {+ if (!isObj(v)) { dropped.push({ path, reason: 'not an object — dropped' }); return undefined }+ const out: Record<string, unknown> = {}+ for (const [k, x] of Object.entries(v)) {+ if (k === '__proto__') continue+ if (plain(x)) out[k] = x+ else if (depth === 0 && isObj(x)) { const o = plainObject(x, `${path}/${k}`, dropped, 1); if (o) out[k] = o }+ else dropped.push({ path: `${path}/${k}`, reason: 'not a plain value — dropped' })+ }+ return out+}++/** Relay blob references: { key, mime, size } and nothing else. */+function blobs(v: unknown, dropped: Dropped[]): BentoDoc['blobs'] {+ if (!isObj(v)) return undefined+ const out: NonNullable<BentoDoc['blobs']> = {}+ for (const [k, b] of Object.entries(v)) {+ if (k === '__proto__' || k.length > LIMITS.scalar) continue+ if (isObj(b) && typeof b.key === 'string' && b.key.length <= LIMITS.scalar && typeof b.mime === 'string' && b.mime.length <= 100 && typeof b.size === 'number' && Number.isFinite(b.size)) {+ out[k] = { key: b.key, mime: b.mime, size: b.size }+ } else dropped.push({ path: `/blobs/${k}`, reason: 'malformed blob reference — dropped' })+ }+ return out+}++/**+ * Gate a snapshot's JSON against the open document. Returns the document to+ * restore (with the live file's identity) and what was dropped, or null when+ * it is not a document at all / has no slide left — then it is never offered.+ */+export function gateRestored(json: string, live: BentoDoc): { doc: BentoDoc; dropped: Dropped[] } | null {+ let raw: unknown+ try { raw = JSON.parse(json) } catch { return null }+ if (!isObj(raw)) return null+ // 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++ const liveRec = live as unknown as Record<string, unknown>+ const { result, dropped } = withDropReport(() => {+ const extra: Dropped[] = []+ const out: Record<string, unknown> = {}+ const gated = (list: unknown, where: string) => ((Array.isArray(list) ? list : []) as unknown[])+ .map((x, i) => withPathSegment(where, () => withPathSegment(String(i), () => sanitizeSlide(x))))+ .filter((x): x is Slide => x !== null)+ // walked in the SNAPSHOT's key order, so an honest snapshot comes back+ // 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 }+ const v = base[key]+ switch (key) {+ case 'format': out.format = live.format; break+ case 'template': break+ case 'slides': out.slides = gated(v, 'slides'); break+ case 'layouts': out.layouts = gated(v, 'layouts'); break+ case 'assets': out.assets = sanitizeAssets(v); break+ case 'fonts': out.fonts = sanitizeFonts(v); break+ case 'blobs': { const b = blobs(v, extra); if (b) out.blobs = b; break }+ case 'title': if (typeof v === 'string' && v.length <= LIMITS.scalar * 5) out.title = v; break+ case 'version': case 'modified': if (typeof v === 'number' || typeof v === 'string') out[key] = v; break+ 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]+ 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+ return { doc, dropped: [...dropped, ...result.extra] }+}