Cotton code
111 lines · 4.8 KB · TypeScriptRaw
/** * THE ADMIN DOOR (NEXT-ADMIN-KEYS part 1, 27 Nov 2026). With token scopes off (every account's default), requireAdmin * answered an owner `ctn_` token with "not the admin" instead of refusing it, so every admin route without its own * check ran for any assistant key holding the owner scope: definitions, import, export, person (another phone made * owner), seal-check and the rest. Now: * *   - On live (and any Worker not labelled dev or test), every /v1/admin route takes the admin token alone, token *     scopes on or off. The coordinator's tooling reaches it as before: https://cottondb.com/b/p-<db>/v1/admin/... with *     the admin token. *   - On the dev and test Workers, an invented account's own owner token still reaches the few routes a builder's *     tooling needs without the admin token (DEV_OWNER_ROUTES, each with its caller), unless the account's token *     scopes are on. * * No phone, Mac or MCP tool calls /v1/admin: the phones and the Mac write through /v1/act, /v1/sync and /v1/import with * their device credentials, and the MCP tools act inside the object. */import { devWorker } from "./env.ts";/** Every route the object's /v1/admin answers (src/business.ts `admin()`), as "METHOD /path". */export const ADMIN_ROUTES: readonly string[] = [  "GET /feedback/file",  "PUT /business",  "PUT /definitions",  "POST /definitions/tables",  "POST /definitions/tools",  "POST /definitions/boards",  "POST /definitions/themes",  "POST /media/recount",  "POST /account/hold",  "POST /account/erase-now",  "GET /order-shadow",  "POST /order-shadow",  "POST /space/mode",  "POST /space/bought",  "POST /media/cap",  "GET /groups/duplicates",  "POST /photos/prune",  "POST /erase",  "POST /retired/erase",  "POST /circle/seal",  "POST /circle/sealed-only",  "POST /alarm/kick",  "GET /jobs",  "POST /dev/invent-personal",  "POST /dev/jobs-seed",  "POST /change-log/thin-machine",  "POST /import",  "POST /reset",  "POST /dev/plant-rows",  "POST /dev/plant-history",  "POST /service-tokens/rekey",  "GET /row-counts",  "GET /mail-all",  "POST /mail-all",  "GET /token-scopes",  "POST /token-scopes",  "GET /memory-lock",  "POST /memory-lock",  "GET /open-tables-lock",  "POST /open-tables-lock",  "GET /secret-lock",  "POST /secret-lock",  // The restore routes (/v1/admin/restore/…) are answered before this door, the admin token's alone and on dev and  // test only (src/business.ts `restoreDoor`, RESTORE 2): no owner token ever reaches them.  "GET /restore-audit",  // SNAPSHOTS 1: the switch's state; the admin token alone (src/business.ts `snapshotsAdmin`, which also answers POST  // and the sub-paths /manifest, /run and /restore/*, each refusing any other token).  "GET /snapshots",  "GET /seal-check",  "GET /vault-key-check",  "GET /export",  "POST /person",];/** * What an invented account's owner token still reaches on the dev and test Workers, and who calls it so: * *   POST /reset, POST /import, GET /export        dev-seed (scripts/dev-seed/client.ts) with the token it mints at sign-in; *                                                 export and import also the e2e proofs (e2e-import, e2e-device, e2e-seal, *                                                 e2e-unlock, e2e-mac, e2e-dev-seed, undo-shrink) and books-seed-walk. *   PUT /definitions, POST /definitions/tables    the e2e proofs that lay a test table (e2e-unlock, e2e-seal, *                                                 e2e-films-seed-open). *   POST /definitions/tools|boards|themes         import-personal rehearsed on dev with an invented account's token. *   POST /dev/plant-rows, POST /dev/plant-history the size proofs (order-shadow-proof, slow-read-proof, first-sync-plant, *                                                 delete-proof, e2e-undo-shrink-killed); both answer 404 on live anyway. *   GET /row-counts, GET|POST /order-shadow       order-shadow-proof. *   PUT /business                                 e2e-undo-shrink-killed (the change log's window); the names that point *                                                 a database elsewhere (siblings, kind, database_id) stay the admin's. */export const DEV_OWNER_ROUTES: ReadonlySet<string> = new Set([  "POST /reset",  "POST /import",  "GET /export",  "PUT /definitions",  "POST /definitions/tables",  "POST /definitions/tools",  "POST /definitions/boards",  "POST /definitions/themes",  "POST /dev/plant-rows",  "POST /dev/plant-history",  "GET /row-counts",  "GET /order-shadow",  "POST /order-shadow",  "PUT /business",]);/** Whether an owner token (not the admin token) is let through the admin door to `method path` on this Worker. */export function ownerReaches(env: { ENV_LABEL?: string }, method: string, path: string): boolean {  return devWorker(env) && DEV_OWNER_ROUTES.has(`${method} ${path}`);}