Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
dash: adopt the kernel doc-fields allowlist for share copies (#630)
nyblnet2112dd7e9f2a
diff --git a/dash/src/recovery.ts b/dash/src/recovery.tsindex 008da336..020702a0 100644--- a/dash/src/recovery.ts+++ b/dash/src/recovery.ts@@ -52,6 +52,7 @@ import { isEncryptionActive } from '../../kernel/src/save.ts'import { planReplace } from './about.ts'import { parseDoc, type DashDoc } from './model.ts'import type { Store } from './store.ts'+import { FROM_LIVE } from '../../kernel/src/docfields.ts'import { t } from './i18n.ts'// --- the content key ---------------------------------------------------------@@ -158,13 +159,14 @@ export interface DecideInput {** `template` is dash's own: restored, it would stop the automatic save to the* file (writeback.ts refuses a template) and make the next open re-mint the- * identity. Same class as the other three.+ * identity. Same class as the other three — and all four are the shared kernel+ * list now (kernel/src/docfields.ts), re-exported here.** Opening a FILE and Replace from JSON do not come through here. A file* carries its own capability by design; Replace from JSON keeps the live room* already (about.ts).*/-export const FROM_LIVE = ['docId', 'collab', 'readonly', 'template'] as const+export { FROM_LIVE }/** The snapshot's content under the live workbook's identity. */export function keepLiveIdentity(next: DashDoc, live: DashDoc): DashDoc {diff --git a/dash/src/sync/online.ts b/dash/src/sync/online.tsindex cf997bb1..718c03a0 100644--- a/dash/src/sync/online.ts+++ b/dash/src/sync/online.ts@@ -30,7 +30,7 @@ import type { Frame, RefusalCode, SyncSession, Transport } from './session.ts'import { offlineEnabled } from '../../../kernel/src/update.ts'import { netWebSocket } from '../../../kernel/src/net.ts'import { lsGet, lsSet } from '../../../kernel/src/storage.ts'-import { carryThroughRotation } from '../../../kernel/src/docfields.ts'+import { carryThroughRotation, collabForReader, collabForInvite } from '../../../kernel/src/docfields.ts'export const DEFAULT_SYNC_HOST = 'wss://sync.bento.page'const SNAP_EVERY = 200 // ops between encrypted snapshot uploads@@ -835,18 +835,22 @@ export async function rotateKeys(session: SyncSession, store: Store) {store.markUnsaved()}-/** Save-a-copy helpers: what to strip for each tier. A reader copy keeps the- * READ key and loses every private half, so the relay drops its writes. */+/** Save-a-copy helpers, via the kernel ALLOWLIST (kernel/src/docfields.ts): a copy+ * keeps only what is on the list, so a new field — private or not — fails CLOSED.+ * A reader keeps the READ key and loses every private half AND the sync stamp+ * (a reader does not contribute), so the relay drops its writes. */export function readerCopy(collab: CollabBlock): CollabBlock {- const { ownerPriv: _o, writerPriv: _w, invite: _i, ...rest } = collab- return { ...rest, role: 'reader' }+ return collabForReader(collab) as unknown as CollabBlock}-/** An invite copy: the owner's private half stays home, an owner-signed invite- * travels. Each device that opens it mints its own member key. */-export async function inviteCopy(collab: CollabBlock): Promise<CollabBlock> {- if (!collab.ownerPriv) return collab // not the owner's copy — nothing to delegate+/** An invite copy: the owner's private half stays home; a FRESH owner-signed+ * invite travels and the top-level role comes from it. Each device that opens it+ * mints its own member key. The allowlist drops any legacy writer key too. */+export async function inviteCopy(collab: CollabBlock): Promise<CollabBlock | null> {+ // A non-owner holds no key to root the chain in — and returning the SOURCE+ // block would leak writerPriv, sync, an old invite and any other field. Refuse,+ // as spaces does, rather than hand back an un-projected copy.+ if (!collab.ownerPriv) return nullconst invite = await mintInvite(collab.ownerPriv)- const { ownerPriv: _o, ...rest } = collab- return { ...rest, invite, role: 'writer' }+ return collabForInvite(collab, invite) as unknown as CollabBlock}diff --git a/scripts/test-dash-share-dirty.ts b/scripts/test-dash-share-dirty.tsindex 3c925b49..77d05768 100644--- a/scripts/test-dash-share-dirty.ts+++ b/scripts/test-dash-share-dirty.ts@@ -42,7 +42,7 @@ const { parseDoc } = await import('../dash/src/model.ts')const { Store } = await import('../dash/src/store.ts')const online = await import('../dash/src/sync/online.ts')const { SyncSession } = await import('../dash/src/sync/session.ts')-const { startSharing, stopSharing, rotateKeys, copyCanWrite, joinFromDoc, collabOf, mintCollab, disconnectOnline } = online+const { startSharing, stopSharing, rotateKeys, copyCanWrite, joinFromDoc, collabOf, mintCollab, disconnectOnline, readerCopy, inviteCopy } = onlinetype DashDoc = import('../dash/src/model.ts').DashDoclet checks = 0, failures = 0@@ -169,6 +169,54 @@ console.log('\nan audience copy is a Viewer in presence, not an Editor')}}+// The allowlist bar (security, 2026-10-05): dash's save-a-copy builders go through+// the kernel allowlist now (online.ts readerCopy/inviteCopy). Build each from ONE+// collab carrying every known secret, an unknown field and a JSON own __proto__+// key, and prove only the allowlist survives.+console.log('\nshare copies, from one poisoned collab (the allowlist bar)')+{+ const base = await mintCollab() // a real ownerPriv, so inviteCopy can sign+ const pc = JSON.parse('{"__proto__":{"polluted":true}}') as Record<string, unknown>+ Object.assign(pc, base, {+ writerPriv: 'WPRIV',+ invite: { pub: 'SRC', priv: 'SRCPRIV', role: 'writer', sig: 's' },+ audience: { invite: { priv: 'APRIV' } },+ sync: { v: 2, tag: 'stamp' }, links: [{ url: 'https://pub' }], futureSecret: 'LEAK',+ })++ const READER_KEYS = ['room', 'key', 'owner', 'writerPub', 'on', 'v', 'role']+ const INVITE_KEYS = ['room', 'key', 'owner', 'writerPub', 'on', 'v', 'sync', 'invite', 'role']+ const POISON = ['writerPriv', 'ownerPriv', 'audience', 'futureSecret', 'links']++ const rc = readerCopy(pc as never) as unknown as Record<string, unknown>+ const ic = (await inviteCopy(pc as never)) as unknown as Record<string, unknown>++ ok(Object.keys(rc).every((k) => READER_KEYS.includes(k)),+ `reader copy: ONLY reader-allowlist keys survive (${Object.keys(rc).sort().join(',')})`)+ ok(rc.role === 'reader' && rc.sync === undefined, 'reader: role forced reader, no sync stamp (dash used to keep it)')+ ok(Object.keys(ic).every((k) => INVITE_KEYS.includes(k)),+ `invite copy: ONLY invite-allowlist keys survive (${Object.keys(ic).sort().join(',')})`)+ ok(ic.sync !== undefined && (ic.invite as { pub: string }).pub !== 'SRC',+ 'invite: keeps sync, carries a FRESH invite not the source’s')+ ok(ic.role === 'writer', 'invite: top-level role from the fresh writer invite')+ for (const f of POISON) { ok(!(f in rc), `reader drops ${f}`); ok(!(f in ic), `invite drops ${f}`) }+ ok(!Object.hasOwn(rc, '__proto__') && !Object.hasOwn(ic, '__proto__'), 'neither copy carries a __proto__ own key')+ ok(({} as Record<string, unknown>).polluted === undefined, 'and the __proto__ source key polluted nothing (Object.hasOwn)')++ // the planted bypass: the old destructure-rest kept writerPriv (dash's bug) and+ // sync; spreading the source keeps every secret. The key-set check turns it red.+ const bypass = { ...pc, role: 'reader' } as Record<string, unknown>+ ok('writerPriv' in bypass && !Object.keys(bypass).every((k) => READER_KEYS.includes(k)),+ 'a spread-the-source bypass FAILS the reader key-set check (not vacuous)')++ // a NON-owner source holds no key to root a chain in; inviteCopy must REFUSE,+ // never hand back the un-projected source block (which would leak every secret).+ const nonOwner = { ...pc } as Record<string, unknown>+ delete nonOwner.ownerPriv+ ok((await inviteCopy(nonOwner as never)) === null,+ 'inviteCopy on a non-owner source returns null, never the source block')+}+console.log(`\n${checks - failures}/${checks} checks passed`)// A SyncSession keeps heartbeat timers, and they would hold the process open// after a clean run — which a CI runner reports as a hang, not a pass.diff --git a/scripts/test-export-secrets.ts b/scripts/test-export-secrets.tsindex e3000b0a..067bf2a6 100644--- a/scripts/test-export-secrets.ts+++ b/scripts/test-export-secrets.ts@@ -495,6 +495,29 @@ for (const app of ['spaces', 'type']) {ok(!/keepHandle:\s*true/.test(hook), 'spaces: onShareCopy does not retain the file handle')}+// dash: its save-a-copy builders live in sync/online.ts (not a share.ts), minted+// through the kernel allowlist now. SOURCE guard; the behaviour is in+// scripts/test-dash-share-dirty.ts. The old builders used a destructure-REST+// denylist ({ ownerPriv, ...rest }) that kept writerPriv and sync — the allowlist+// closes both, so the guard also rejects a return to that shape.+{+ const rel = 'dash/src/sync/online.ts'+ const src = read(rel)+ const readerFn = mask(exportedBody(src, 'readerCopy'))+ const inviteFn = mask(exportedBody(src, 'inviteCopy'))+ ok(/collabForReader\(/.test(readerFn), `${rel}: readerCopy routes through collabForReader`)+ ok(/collabForInvite\(/.test(inviteFn), `${rel}: inviteCopy routes through collabForInvite`)+ ok(/mintInvite\(/.test(inviteFn), `${rel}: inviteCopy mints a SCOPED invite`)+ ok(!/\{\s*\.\.\.(?!collabFor)/.test(readerFn) && !/\{\s*\.\.\.(?!collabFor)/.test(inviteFn),+ `${rel}: neither builder rebuilds collab by spreading the source — only a collabFor* projection`)+ ok(!/\.\.\.rest\b/.test(readerFn) && !/\.\.\.rest\b/.test(inviteFn),+ `${rel}: neither builder uses a destructure-rest denylist`)+ // a non-owner early-return must NOT hand back the un-projected source block+ // (`return collab`) — that leaks everything; refuse with `return null` instead.+ ok(!/\breturn collab\b/.test(inviteFn),+ `${rel}: inviteCopy never returns the source block unchanged (null for a non-owner)`)+}+// --- the OTHER half of the round trip: pasting one back in -------------------//// Stripping `collab` out of "Copy document JSON" is right, and it changed what