Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Match the published index shape: an object bound to this app
nyblnet128b80a14dd4
diff --git a/docs/i18n-packs.md b/docs/i18n-packs.mdindex 68b2c9b4..4b6b8689 100644--- a/docs/i18n-packs.md+++ b/docs/i18n-packs.md@@ -109,12 +109,14 @@ sha256, verified against the `PUBLIC_KEY_JWK` already embedded in every shellsigns packs beside the shell, and the manifest gains a `packs` array listing`{lang, version, sha256, url}`. No new trust root, no second key.-### What the client checks (implemented)+### Loading++`registerI18n` already accepts a packed table (kernel). Pack loading adds a+merge step: a pack's strings layer over the bundled core for its language.+Lookup misses fall back per string to the English key, which is what makes a+partial or stale pack degrade gracefully rather than break.-The INDEX is signed; individual packs are not separately signed. The index is-a signed envelope — `{payload: "<json string>", sig: "<base64>"}`, the exact-shape `sign-release.mjs` already emits for the update manifest — and every-listing in it pins its pack's `sha256`. So:+### What the client checks (implemented)```embedded release key -> signs the index@@ -130,15 +132,19 @@ else in the codebase does release-channel crypto:- `fetchPinned(url, sha256)` — fetch, hash, compare; `null` on any mismatch.They verify BYTES. They do not decide what is safe to use — that policy is the-caller's, and packs are DATA (see the decision log entry, 2026-07-26).--`slides/src/packs.ts` composes them and **fails closed**: an unsigned index, a-listing with no pin, or bytes that don't match yield nothing to add and a-`'unverified'` error in the UI. There is no permissive fallback for an+caller's, and packs are DATA (see the decision log entry, 2026-07-26). Anything+side-loaded that ever carries CODE needs stricter policy — pinned at install,+never auto-refreshed — and must not inherit the pack rules by reusing this+fetch.++`slides/src/packs.ts` composes them and **fails closed**. It expects the index+payload specified above: an object whose `app` is this app's id (the signing+key is platform-wide, so the id is what stops a validly signed index for+another app) carrying a `packs` array. An unsigned index, an index for another+app, a listing with no pin, or bytes that don't match all yield nothing to add+and a `'unverified'` error in the UI. There is no permissive fallback for anunsigned index — nothing is published yet, so there is nothing to be-compatible with. The index payload may be a listing array or an object with a-`packs` array, which is the manifest's own shape, so one signed file can serve-as both.+compatible with, and a fallback shipped now would be permanent.Two things deliberately NOT checked:@@ -150,16 +156,9 @@ Two things deliberately NOT checked:already holds rather than dropping it. The unverified bytes are refused; thepreviously verified ones stay. Degraded beats absent.-Rig: `node scripts/test-packs.ts` — tampered pack, tampered index, unsigned-index, missing pin, and the good path, against real WebCrypto with a-throwaway key standing in for the release key.--### Loading--`registerI18n` already accepts a packed table (kernel). Pack loading adds a-merge step: a pack's strings layer over the bundled core for its language.-Lookup misses fall back per string to the English key, which is what makes a-partial or stale pack degrade gracefully rather than break.+Rig: `node scripts/test-packs.ts` (in CI) — tampered pack, tampered index,+unsigned index, index signed for another app, missing pin, and the good path,+against real WebCrypto with a throwaway key standing in for the release key.### Incorporation into the filediff --git a/scripts/test-packs.ts b/scripts/test-packs.tsindex a4a1eacf..00f632ba 100644--- a/scripts/test-packs.ts+++ b/scripts/test-packs.ts@@ -134,10 +134,22 @@ Object.defineProperty(globalThis, 'fetch', {})// Imported AFTER the globals exist — module scope must find them in place.+const { configureApp } = await import('../kernel/src/app.ts')+configureApp({+ appId: 'bento-slides',+ appName: 'bento/slides',+ manifestUrl: `${CHANNEL}/manifest.json`,+})const packs = await import('../slides/src/packs.ts')-const goodIndex = async (sha256 = packHash) =>- envelope([{ lang: 'xx', label: 'Testish', url: PACK_URL, version: '1.0.0', sha256 }])+/** The index payload shape scripts/sign-packs.mjs publishes. */+const index = async (listings: unknown[], app = 'bento-slides') =>+ envelope({ app, version: '1.0.0', at: new Date().toISOString(), packs: listings })++const listing = (sha256 = packHash, version = '1.0.0') => ({+ lang: 'xx', label: 'Testish', version, url: PACK_URL, sha256, bytes: packBytes.length,+})+const goodIndex = async (sha256 = packHash) => index([listing(sha256)])// --- 1. the good path -------------------------------------------------------console.log('\nsigned index, matching hash')@@ -166,7 +178,7 @@ servedPack = evilBytesconst forgedHash = await sha256Hex(evilBytes)const honest = JSON.parse(await goodIndex())const forged = JSON.stringify({- payload: JSON.stringify([{ lang: 'xx', label: 'Testish', url: PACK_URL, version: '1.0.0', sha256: forgedHash }]),+ payload: JSON.parse(await index([listing(forgedHash)])).payload,sig: honest.sig, // the old signature, over the old payload})servedIndex = forged@@ -174,11 +186,21 @@ ok((await packs.availablePacks()).length === 0, 'an index whose signature fails// --- 4. unsigned index ------------------------------------------------------console.log('\nunsigned index')-servedIndex = JSON.stringify([{ lang: 'xx', label: 'Testish', url: PACK_URL, sha256: packHash }])-ok((await packs.availablePacks()).length === 0, 'a bare (unsigned) listing array is refused — fail closed')-servedIndex = await envelope([{ lang: 'xx', label: 'Testish', url: PACK_URL }])+servedIndex = JSON.stringify({ app: 'bento-slides', version: '1.0.0', packs: [listing()] })+ok((await packs.availablePacks()).length === 0, 'a bare (unsigned) payload is refused — fail closed')+servedIndex = await index([{ lang: 'xx', label: 'Testish', url: PACK_URL }])ok((await packs.availablePacks()).length === 0, 'a signed listing with NO pinned hash is not offered')+// --- 4b. an index signed for another app ------------------------------------+// The release key is platform-wide, so a validly signed bento/spaces index is+// a real thing an attacker could replay onto this channel. The app id is what+// stops it — same check verifyManifest makes on the release manifest.+console.log('\nindex signed for a different app')+servedIndex = await index([listing()], 'bento-spaces')+ok((await packs.availablePacks()).length === 0, 'a validly signed index for ANOTHER app offers nothing')+servedIndex = await envelope([listing()])+ok((await packs.availablePacks()).length === 0, 'a bare array payload (no app id) offers nothing')+// --- 5. no pin at the fetch itself -----------------------------------------console.log('\nlisting with no usable pin, handed straight to fetchPack')ok(@@ -206,9 +228,7 @@ servedPack = packBytesconst fresh = await packs.fetchPack((await packs.availablePacks())[0])ok(typeof fresh !== 'string' && packs.stageForFile(fresh), 'stage the verified pack into the file')servedPack = evilBytes // channel turns hostile between install and update-servedIndex = await envelope([- { lang: 'xx', label: 'Testish', url: PACK_URL, version: '1.0.1', sha256: packHash },-])+servedIndex = await index([listing(packHash, '1.0.1')])const out = await packs.refreshPacksForVersion('1.0.1')ok(out.kept.includes('xx') && !out.refreshed.includes('xx'), 'the pack is KEPT, not refreshed')const inFile = packs.packsInFile().find((p) => p.lang === 'xx')diff --git a/slides/src/packs.ts b/slides/src/packs.tsindex 5c19e9b3..5c09c3c0 100644--- a/slides/src/packs.ts+++ b/slides/src/packs.ts@@ -18,6 +18,7 @@// so a language belongs to the deck. The trade is that adding a language// requires saving the file — which the UI states plainly rather than hiding.+import { appConfig } from '../../kernel/src/app.ts'import { addPack, removePack, type LanguagePack } from '../../kernel/src/i18n.ts'import { readShellBlocks, type ShellBlock } from '../../kernel/src/save.ts'import { fetchPinned, verifySigned } from '../../kernel/src/update.ts'@@ -41,8 +42,10 @@ export interface PackListing {url: string/** app version the pack was built against, for display */version?: string- /** hex sha256 of the pack's bytes, PINNED by the signed index */+ /** lowercase hex sha256 of the pack's bytes, PINNED by the signed index */sha256: string+ /** size of the pack, for display */+ bytes?: number}export type PackError = 'offline' | 'bad-pack' | 'wrong-app' | 'unverified'@@ -205,25 +208,36 @@ export function shellBlocksForPacks(): ShellBlock[] {* FAIL CLOSED, no legacy path. An unsigned or badly signed index yields NO* listings — the Languages dialog then says there is nothing to add, which is* exactly right: an index we cannot authenticate is an index we know nothing- * about. Nothing is published yet, so there is no old plain-array index in the- * world to be compatible with, and adding a permissive fallback would mean- * anyone who can answer for the channel picks the strings in your UI.+ * about. Nothing is published yet, so there is no unsigned index in the world+ * to be compatible with, and adding a permissive fallback would mean anyone+ * who can answer for the channel picks the strings in your UI.*- * The payload is a listing array, or an object carrying one under `packs` —- * which is the shape of the signed release manifest itself (sign-release.mjs- * puts pack hashes in the manifest payload), so one signed file can serve as- * both if the channel prefers that. Same envelope either way.+ * Payload shape, produced by scripts/sign-packs.mjs (spec in+ * docs/i18n-packs.md §"Signing and release"):+ *+ * { app: 'bento-slides', version, at, packs: [ { lang, label, version,+ * url, sha256, bytes } ] }+ *+ * `app` is checked exactly as the release manifest's is: the signing key is+ * platform-wide, so the id is what stops a validly-signed bento/spaces index+ * being served to bento/slides. `url` is relative to the channel unless+ * absolute, so a dev channel serves its OWN packs instead of quietly reaching+ * back to bento.page.*/async function fetchIndex(): Promise<PackListing[]> {try {const res = await fetch(`${channel()}/packs.json`, { cache: 'no-store' })if (!res.ok) return []- const payload = await verifySigned(await res.text(), 'language pack index')- const list = Array.isArray(payload) ? payload : (payload as { packs?: unknown })?.packs- if (!Array.isArray(list)) return []+ const payload = (await verifySigned(await res.text(), 'language pack index')) as {+ app?: unknown+ packs?: unknown+ }+ if (!payload || typeof payload !== 'object') return []+ if (payload.app !== appConfig().appId) return []+ if (!Array.isArray(payload.packs)) return []// A listing with no usable pin can never be verified, so it can never be// offered — drop it here rather than let it fail later at the Add button.- return (list as PackListing[]).filter(+ return (payload.packs as PackListing[]).filter((p) => p?.lang && p?.url && /^[0-9a-f]{64}$/i.test(p?.sha256 ?? ''),)} catch {