Mapa images: revision 2, answering Fable's round 1
Make team page copies only its source's images, before its write (H1); the JPEG walker keeps every non-metadata marker, DRI included (H2); attach only introduced ids; 64 KiB padding; truncation at each format's end; SQL-driven sweep off the boot path; one blob semaphore; person and team quotas; CopyImage; the lows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+518
−251
docs/superpowers/specs/2026-11-17-mapa-images.md+518 −251
CI passed — run details
CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error
added 16 packages in 307ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.c25f62142895a785.js (318737 bytes, 99.5KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (41.567965ms)
ℹ 760 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (57.781538ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (92.705589ms)
ℹ 748 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (113.578729ms)
ℹ 755 inserts, 715 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (3159.435732ms)
ℹ 18240 edits over 760 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (942.95911ms)
ℹ 4124 links over 760 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":610,"A page link can’t show [ or ]]. Select words without them.":370,"Select some words to link them to a page.":163,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":17}
✔ linear: trailing spaces (24.086046ms)
✔ linear: trailing whitespace (14.432252ms)
✔ linear: unclosed web links (10.883382ms)
✔ linear: web links with no address (17.449414ms)
✔ linear: unclosed wiki links (19.474793ms)
✔ linear: unclosed embeds (13.079071ms)
✔ linear: closes only (4.532989ms)
✔ the selected words become the chip's shown text (11.372158ms)
✔ words that are the title make a plain [[Title]] (3.398813ms)
✔ spaces at the selection's edges stay outside the chip (1.140958ms)
✔ a date makes a date link, in a heading, an item and a quote (9.105507ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.009203ms)
✔ only the linked block's bytes change, and undo gives the body back (2.174883ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (1.106819ms)
✔ a target the words cannot be linked to as typed is refused (0.231665ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.269525ms)
✔ web-linked words are refused: the address would be lost (review M4) (0.957464ms)
✔ words whose Markdown would read otherwise are refused (review M3) (1.555136ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.36921ms)
✔ linkCheck says why it refuses (review low 2) (0.689577ms)
✔ golden file has bodies (0.669974ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (16.583826ms)
✔ markup.mjs strips and spans every block as Go does (30.165917ms)
✔ the schema's toDOM draws every body as Go renders it (42.540666ms)
✔ emphasis draws the four pinned outputs (14.108599ms)
✔ a body ends in the editor's empty paragraph (0.204439ms)
✔ a POST that never answers is aborted after the timeout (21.302922ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.179494ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (9.446349ms)
✔ an offered draft never commits by itself; Save commits it (1.207291ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.561979ms)
✔ closing carries text not yet sent, and the cap leaves it out (21.24832ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (2.85845ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (2.010202ms)
✔ typing mid-flight: the merge is not applied and the base does not move (0.751002ms)
✔ a merge the editor cannot represent stops after three tries (2.908266ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (0.940315ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.233045ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (0.646714ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.601738ms)
✔ noBase and gone lead to the existing choices (0.739803ms)
✔ a commit that merged is applied when nothing was typed since (0.742538ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (5.578927ms)
✔ an own draft committed meanwhile goes on as a new draft (1.109344ms)
✔ a reload keeps a stored draft; unsent text still commits (0.485248ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (0.839964ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (1.987424ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.024168ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (3.295597ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (0.858446ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.263179ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.715302ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.388944ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.535635ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.46862ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.507877ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (5.102522ms)
✔ marks close before code, links and atoms, and reopen after (0.358983ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (5.055081ms)
✔ empty blocks are written as nothing (1.736485ms)
✔ an unclosed fence that is no longer last gets its closing fence (1.039645ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.377202ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (2.839299ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (1.662548ms)
✔ a trailing hard break stays on screen and is written as nothing (0.531177ms)
✔ the reparse waits while an IME is composing (0.624616ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (3.087061ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.722203ms)
✔ rebuild changes origins only, outside undo history (1.309696ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.139185ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (2.328366ms)
✔ a duplicate ^id typed above its holder never takes the id from it (0.735896ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (0.996191ms)
✔ a history command that throws is refused, never thrown (2.942244ms)
✔ one rename at a time, from either field (2.074802ms)
✔ an empty or unchanged title sends nothing (0.232307ms)
✔ a refusal keeps what was typed, and the title (0.256198ms)
✔ the pending state holds for the busy rule (8.232736ms)
✔ a failed POST says so and keeps the title (0.347794ms)
✔ Update links posts the confirm page's POST (0.234119ms)
✔ clean is CleanTitle's whitespace rule (0.112973ms)
✔ the saver's base follows a rename made over it, and only that (0.340041ms)
✔ closing sends the rename as one keepalive POST (1.335741ms)
✔ a drag whose anchor the document no longer reaches selects to its end (6.092595ms)
ℹ tests 90
ℹ suites 0
ℹ pass 90
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4533.179202
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
? amadan.net/oficina/mapa/cmd/mapa [no test files]
ok amadan.net/oficina/mapa/internal/mapa (cached)
? amadan.net/oficina/mapa/internal/mapa/icons [no test files]
ok amadan.net/oficina/mapa/internal/mapa/markup (cached)
ok amadan.net/oficina/mapa/internal/mapa/seal (cached)
ok amadan.net/oficina/mapa/internal/mapatest 9.894s
? amadan.net/oficina/mapa/scripts/mutate [no test files]
? amadan.net/oficina/mapa/scripts/preview [no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
credits: checked
diff --git a/docs/superpowers/specs/2026-11-17-mapa-images.md b/docs/superpowers/specs/2026-11-17-mapa-images.md| index d11f64d..bf0667d 100644 |
| --- a/docs/superpowers/specs/2026-11-17-mapa-images.md |
| +++ b/docs/superpowers/specs/2026-11-17-mapa-images.md |
| @@ -1,6 +1,8 @@ |
| # Mapa images |
| -**Status:** revision 1, 2026-11-17. For review. Nothing is built. |
| +**Status:** revision 2, 2026-11-17. For review. Nothing is built. |
| +- Fable reviewed revision 1 (`4d40e4e`) and found CHANGES REQUIRED: 2 high, 9 medium and 16 low findings. |
| +- This revision answers all of them. §11 maps each finding to its change. |
| **Asked for by Paul, 2026-11-17:** *"we should handle image uploads. CARLOS Platform has everything we need to handle that."* The Notion importer (specced separately) depends on this spec. It must bring Notion's images across as real Mapa images (§7). |
| @@ -11,14 +13,28 @@ |
| - the level-up spec, `2026-11-14-mapa-level-up.md`, which is approved and built; |
| - `AGENTS.md`'s hard rules. |
| -This spec changes no trust property. It adds one kind of object, one gate-4 row and one route that serves bytes. §6 lists every server change and the gate that holds it. |
| +This spec changes no trust property. It adds: |
| +- one kind of object; |
| +- one gate-4 row; |
| +- one route that serves bytes. |
| + |
| +§6 lists every server change and the gate that holds it. |
| + |
| +**Names in this spec.** Its decisions are "decision 1" to "decision 4" (§1.2). Its gates are IMG1 to IMG7 (§6). |
| **Prior art in the suite:** |
| -- **Slides** (`internal/slides/assets.go`, `d047eef`): bytes in CARLOS's bucket, served *through the app*, sniffed from the bytes, `nosniff` and a `sandbox` CSP. |
| - - Presigned URLs were tried there first and never worked. The page CSP is `img-src 'self' data:`, and the bucket has no CORS rule. |
| +- **Slides** (`internal/slides/assets.go`, `d047eef`): |
| + - Bytes go in CARLOS's bucket and are served *through the app*. They are sniffed from the bytes and served with `nosniff` and a `sandbox` CSP. |
| + - Presigned URLs were tried first and never worked. The page CSP is `img-src 'self' data:`, and the bucket has no CORS rule. |
| - Slides keeps SVG behind a sanitiser. Slides does not seal. |
| -- **Docs**, plan 7 (`docs/superpowers/plans/2026-09-02-images-links-tables.md`): it refuses SVG, stores sealed bytes with the stored type `application/octet-stream`, keeps a placeholder as a decoration and inserts the node when the upload succeeds, and re-uploads an image pasted from another document. |
| -- **rastrillo `blobs`** (in Mapa's pin): `S3FromEnv` reads `CARLOS_STORE_*`. It is a content-addressed `Put`/`Get`/`Delete` with a SigV4 signer and no SDK. |
| +- **Docs**, plan 7 (`docs/superpowers/plans/2026-09-02-images-links-tables.md`): |
| + - It refuses SVG. |
| + - It stores sealed bytes with the stored type `application/octet-stream`. |
| + - Its placeholder is a decoration, and the node is inserted only when the upload succeeds. |
| + - An image pasted from another document is uploaded again. |
| +- **rastrillo `blobs`** (in Mapa's pin): |
| + - `S3FromEnv` reads `CARLOS_STORE_*`. |
| + - It is a content-addressed `Put`/`Get`/`Delete`, with a SigV4 signer and no SDK. |
| --- |
| @@ -26,65 +42,73 @@ This spec changes no trust property. It adds one kind of object, one gate-4 row |
| ### 1.1 What CARLOS gives an app |
| -Found from `carlos store --help`, Slides' live store (`carlos store status --app slides`), carlos/platform `internal/objstore`, `docs/site/cli.md` and the 2026-11-15 plan catalog: |
| +This comes from `carlos store --help`, Slides' live store, carlos/platform `internal/objstore` and `internal/console`, `docs/site/cli.md`, and the 2026-11-15 plan catalog. |
| -- **A bucket of its own, with an IAM user of its own,** in `eu-west-1` (Slides' bucket is `carlos-store-bds-slides`). The user's policy allows Get, Put and Delete on objects and List on the bucket. |
| -- **Credentials as config.** `CARLOS_STORE_BUCKET` and `_REGION` arrive as env. `_ACCESS_KEY` and `_SECRET_KEY` arrive as secrets. `_ENDPOINT` arrives only on a deployment that has one. |
| +- **The app gets its own bucket and IAM user** in `eu-west-1`. Slides' bucket is `carlos-store-bds-slides`. |
| + - The policy allows Get, Put and Delete on objects, and List on the bucket. |
| +- **Credentials arrive as config:** |
| + - `CARLOS_STORE_BUCKET` and `_REGION` as env; |
| + - `_ACCESS_KEY` and `_SECRET_KEY` as secrets; |
| + - `_ENDPOINT` only on a deployment that has one. |
| - `carlos store rotate` mints a new key and keeps the old one live until `--finish`. |
| -- **No signing service and no proxy.** Presigning is the app's own job (rastrillo signs). Nothing serves the bytes for the app. |
| -- **Encryption:** AWS's default server-side encryption. That does not stop a credentialled reader, so it is not Mapa's seal. |
| -- **No versioning and no lifecycle rules.** Nothing is deleted unless the app deletes it. Deleting an instance leaves its bucket. |
| -- **Size and cost:** the bytes count against the account's plan: |
| +- **There is no signing service and no proxy.** Presigning is the app's own job; rastrillo signs. |
| +- **Encryption:** AWS's default server-side encryption. A reader with the credentials still sees plaintext, so this is not Mapa's seal. |
| +- **There is no versioning and no lifecycle rule.** Nothing is deleted unless the app deletes it. Deleting an instance leaves its bucket. |
| +- **Size and cost:** stored bytes count against the account's plan. |
| - Free: 50 MB, or 1 GB kept for accounts approved for storage before 2026-11-15. |
| - - Personal: 25 GiB. |
| - - Business: 500 GiB. |
| - - Storage packs add 50 GiB each. |
| - - A store past its plan's grace period has `PutObject` denied, while Get and Delete still work. |
| -- **Scanning** is off by default. A plan with `storage_scan_required` (Free, under the new catalog) forces scanning. It also refuses a client-encrypted attestation and per-instance stores. Slides' store has no scanning today, so the oficina account's plan does not force it now. §8 and Q5 deal with this. |
| + - Personal: 25 GiB. Business: 500 GiB. Storage packs add 50 GiB each. |
| + - Past the plan's grace, `PutObject` is denied. Get and Delete still work. |
| +- **Scanning is off by default.** |
| + - Under the new catalog, a plan with `storage_scan_required` (Free) does not refuse `store create`. It creates the store and then **forces scanning and enforcement** on it (`forceStoreScanning`). |
| + - It refuses a client-encrypted attestation. It refuses per-instance stores too. |
| + - A scanner reading ciphertext claims coverage it cannot have. One false "infected" tag would make an image unreadable. |
| + - §8 step 1 and Q5 deal with this. |
| ### 1.2 Decisions |
| | # | Decision | Rejected | |
| |---|---|---| |
| -| I1 | **The bytes are sealed in Mapa, under Mapa's DEK, before they leave the process.** The bucket holds only ciphertext. Mapa's `seal` package gains a purpose, `image`, so the HKDF-derived key is apart from every other key (build note 21). The object is stored as `application/octet-stream`, so its type is not visible in the bucket either. | Plaintext in the bucket, as Slides does. Slides does not seal anything; Mapa seals everything (base §4), and an image of a whiteboard is as private as the page it sits on. Docs' plan 7 already took the same view. Using rastrillo's `blobs.Sealed`: `AGENTS.md` makes `seal/` Mapa's only encryption | |
| -| I2 | **Readers get images only through Mapa:** `GET /i/{id}`. That route checks scope, reads the ciphertext, checks it, opens it and writes the image. | Presigned or public URLs. A URL cannot check scope, the bucket holds ciphertext that only the app can open, and Slides found that its CSP and CORS refuse them anyway | |
| -| I3 | **The object key is the SHA-256 of the ciphertext** (rastrillo's content addressing). Every seal draws a fresh nonce, so two uploads of the same picture are two unrelated objects. **Before opening, Mapa checks that the bytes it read hash to the key.** A swapped object is therefore refused, not served. | De-duplicating by plaintext hash. Equal keys would show in plaintext that Ana's private note and a team page hold the same picture: a link-graph fact that base decision 14 keeps sealed | |
| -| I4 | **Development and tests use `blobs.Dir`** beside the database, as Slides does. Production with no store bound boots, and upload answers 503 "Images aren't set up on this Mapa yet". A partly delivered store (a bucket with no key) is a boot refusal in `config.go`. | Falling back to the database or the local disk in production. The disk is ephemeral and hibernates, and blobs in SQLite ride the replicated WAL | |
| +| 1 | **The bytes are sealed in Mapa, under Mapa's DEK, before they leave the process. The bucket holds only ciphertext.** <br>• Mapa's `seal` package gains the purposes `image` and `image-record`, so each key is derived apart from every other key (build note 21). <br>• Before sealing, the plaintext is padded to the next multiple of 64 KiB. The true length is kept in the sealed record. <br>• The object is stored as `application/octet-stream`. | Plaintext in the bucket, as Slides does. Slides seals nothing; Mapa seals everything (base §4). An image of a whiteboard is as private as the page it sits on. Docs' plan 7 took the same view. <br>Using rastrillo's `blobs.Sealed`: `AGENTS.md` makes `seal/` Mapa's only encryption | |
| +| 2 | **Readers get images only through Mapa**, at `GET /i/{id}`. That route checks scope, then reads, checks, opens and writes the image. | Presigned or public URLs. A URL cannot check scope, and the bucket holds ciphertext only the app can open. Slides found that its own CSP and the missing CORS rule refuse them anyway | |
| +| 3 | **The object key is the SHA-256 of the ciphertext**, as rastrillo addresses everything. <br>• Every seal draws a fresh nonce, so two uploads of the same picture are unrelated objects. <br>• Before opening, Mapa checks that the bytes read hash to the key. A swapped object is refused, not served. | De-duplicating by plaintext hash. Equal keys would show, in plaintext, that Ana's private note and a team page hold the same picture: a link-graph fact that base decision 14 keeps sealed. Exact ciphertext sizes would show it too, which is why decision 1 pads | |
| +| 4 | **Development and tests use `blobs.Dir`** beside the database, as Slides does. <br>• Production with no store bound boots, and upload answers 503: "Images aren't set up on this Mapa yet". <br>• A partly delivered store (a bucket with no key) also boots. Uploads answer 503 and a loud log line names the missing variable. An images fault never takes the knowledge base down. | Falling back to the database or local disk in production. The disk is ephemeral and hibernates, and SQLite blobs ride the replicated WAL. <br>Refusing to boot on a partial store, as Slides does | |
| ### 1.3 The `images` table, and the gate-4 row |
| -One row per image. "Image" means one picture attached to one place (§3). Copies are separate rows with separate objects. |
| +**One row per image.** An image is one picture in one place (§3). Copies are separate rows with separate objects. |
| | Column | Plaintext? | Why | |
| |---|---|---| |
| | `id` | yes | the row's own key, never shown | |
| -| `public_id` | yes | the URL's id: random base 36 from its own nonce stream, unique, as pages' public ids are (build note 32). It is never sequential, so it counts nothing | |
| -| `owner` (member id) | yes | who uploaded it. Pending images are readable by this person only (§3), and the per-person quota counts by it | |
| -| `page_id` (nullable) | yes | the page it is attached to; null while pending. S2-style reads answer from the page's rung without unsealing | |
| -| `created_at` | yes | the pending window and the history window (§3.3) | |
| -| `stored_bytes` | yes | the ciphertext's size, for the quota. The bucket shows it anyway | |
| +| `public_id` | yes | the URL's id. Random base 36 from its own nonce stream, unique, as pages' public ids are (build note 32). Never sequential, so it counts nothing | |
| +| `owner` (member id) | yes | who uploaded it. Pending images are their owner's only (§3.1), and quota counts by it | |
| +| `page_id` (nullable) | yes | the page it is attached to; null while pending. Scope is answered from the page's rung without unsealing | |
| +| `created_at` | yes | the pending window (§3.3) | |
| +| `unreferenced_at` (nullable) | yes | when the page's current body stopped referencing it (§3.3). Retention runs as SQL over it | |
| +| `stored_bytes` | yes | the ciphertext's size, padded to 64 KiB steps, for the quota. The bucket shows it anyway | |
| | `object_key` | yes | the bucket key: a hash of ciphertext, which says nothing about content | |
| -| `sealed_record` | sealed | the sniffed type, width and height after orientation, and the plaintext size | |
| +| `sealed_record` | sealed | the sniffed type, the width and height after orientation, and the true size | |
| -- **No filename is kept,** sealed or not. The alt text lives in the page body (§2), so it is sealed with the body. |
| +- **No filename is kept,** sealed or not. |
| +- **The alt text lives in the page body** (§2), so it is sealed with the body. |
| - **`image_trash (object_key, queued_at)`** is the queue of objects to delete (§3.3). It is plaintext and holds only keys. |
| **Base §4 gains one row:** |
| -> `images (id, public_id, owner, page_id, created_at, stored_bytes, object_key)`, and `image_trash (object_key, queued_at)` | serving, scope and retention without unsealing | **how many images each page holds, who uploaded each and when, and roughly how big each is**, on private pages too. A copy (§3.2) made at the same moment as another image of the same ciphertext size suggests the two are the same picture. |
| +> `images (id, public_id, owner, page_id, created_at, unreferenced_at, stored_bytes, object_key)` and `image_trash (object_key, queued_at)` | serving, scope, quota and retention without unsealing | **how many images each page holds, who uploaded each, when, when it was taken out of the text, and its size to within 64 KiB**, on private pages too. Two images of the same padded size are not thereby the same picture, but small images all pad to one size, and large ones narrow the field. |
| -The leak has the same shape as "revision store" and "ciphertext sizes": counts, times and sizes, never content, and never which page an image came from. |
| +That is the same shape as the existing rows "revision store" and "ciphertext sizes": counts, times and coarse sizes. It never shows content. It never shows that an image on one page came from another page. |
| ### 1.4 Serving |
| -`GET /i/{id}`: |
| +`GET /i/{id}` works in this order: |
| -1. **Scope first** (§3.1). If the viewer may not read the image, the answer is the app's ordinary 404. The body and headers are the same as for an id that never existed. |
| -2. If it is readable, the answer depends on `If-None-Match`: |
| - - It names `"<public_id>"`: the answer is `304`, with no store read. |
| - - Otherwise Mapa reads the object, checks its hash (I3), opens it, and writes it. |
| +1. **Scope first** (§3.1). If the viewer may not read the image, the answer is the app's ordinary 404, with the same body and headers as an id that never existed. |
| +2. **A readable image:** |
| + - If `If-None-Match` names `"<public_id>"`, the answer is `304`, and the store is not read. |
| + - Otherwise Mapa reads the object, checks its hash (decision 3), opens it, removes the padding and writes it. |
| 3. **Headers:** |
| - - `Content-Type`: the sniffed type from the sealed record; |
| + - `Content-Type`: the sniffed type, taken from the sealed record; |
| - `X-Content-Type-Options: nosniff`; |
| - `Content-Security-Policy: default-src 'none'; sandbox`; |
| - `Content-Disposition: inline`; |
| @@ -92,10 +116,14 @@ The leak has the same shape as "revision store" and "ciphertext sizes": counts, |
| - `ETag: "<public_id>"`. |
| 4. **Caching:** `Cache-Control: private, max-age=3600, immutable`. |
| - An id's bytes never change, so `immutable` is honest. |
| - - `private` keeps CARLOS's edge and any shared cache out. |
| - - **The hour is the honest bound:** a person who loses access to an image, or sees it removed (§3.3), may still have their browser's own copy for up to an hour. Help says so. |
| - - Pages that carry the editor island stay `no-store` (level-up §6.8). Only the image bytes are cached. |
| -5. **Memory:** rastrillo's `S3.Put` and Mapa's seal each hold the whole object. Ten MiB is the cap per image (§5), and at most four uploads run at once per process; a fifth gets 503 with Retry-After. The worst case is therefore about 120 MiB. |
| + - `private` keeps CARLOS's edge and every shared cache out. |
| + - **The hour is the stated bound.** A person who loses access to an image, or sees it removed (§3.3), may still have their browser's own copy for up to an hour. Help says so. |
| + - Pages that carry the editor island stay `no-store` (level-up §6.8). Only the bytes are cached. |
| +5. **Memory: one semaphore covers every blob operation.** That means uploads, serving, copies and the importer. |
| + - It admits four at a time. Each holds at most about 30 MiB: the body, the sealed copy and the opened copy, for a 10 MiB image. |
| + - Waiters queue. A request that waits 10 s answers 503 with `Retry-After`. The importer's calls wait without a limit (§7). |
| + - So blob work costs at most about 120 MiB. The figure is measured on the instance's real memory size at build time and recorded in the build notes. |
| + - Streaming, chunked sealing is the fix if that bound is ever too much (§9). |
| --- |
| @@ -107,55 +135,92 @@ The leak has the same shape as "revision store" and "ciphertext sizes": counts, |
|  |
| ``` |
| -- **An image is the standard ``,** and Mapa renders it as an image **only when `src` is exactly `/i/<public id>`**. The public id is `[0-9a-z]{1,13}`. |
| -- **The alt text** is any text without `[`, `]` or a line break, at most 1,000 bytes. The editor's alt field refuses those characters. |
| -- **There is no title** (`"…"` after the address) and no size suffix. |
| -- **Every other `` renders as it does today:** a literal `!` followed by a web link. An external image is never fetched or hotlinked, because that would hand a reader's address to a third party and `img-src 'self'` refuses it anyway. Paste and the importer turn external images into Mapa images or links (§4.1, §7). |
| -- **It is an inline span** (`markup.Image`) wherever links are parsed, and never inside code. Like a link, it is part of its block. A paragraph that is only an image is drawn as one, because the CSS gives an image alone in its block `display: block`. |
| -- **The text index** reads the alt text as body text. It does not read the address, so search, unlinked mentions and snippets never see `i` or an id. |
| -- **S3 and memoria** see the image as its alt text. No bytes, and no image id, reach a sibling. |
| -- **History's word diff** shows an image as `[image: alt]`. |
| - |
| -**Rejected: `![[image:…]]`.** `![[app:item]]` is Mapa's embed grammar (base §7). Its rules are a team container's write-time check, render enforcement (gate 12) and S10 payloads, and they would all have to learn that `image` is not an app. It also has no standard place for alt text. It survives nowhere outside Mapa, while `` is what Obsidian, GitHub and every Markdown tool read. The stored address is relative, so it never names a host. That matters because Paul's team URLs will move hosts (`paulca.mapa.oficina.works`). |
| +- **An image is the standard ``.** Mapa renders it as an image **only when `src` is exactly `/i/<public id>`**, where the public id is `[0-9a-z]{1,13}`. |
| +- **Alt text** is any text without `[`, `]` or a line break, at most 1,000 bytes of UTF-8. The editor's alt field refuses those characters and that length. |
| +- **There is no title** (`"…"` after the address), and **no size suffix**. |
| +- **Every other `` renders exactly as it does today.** |
| + - Today `` is literal text, because `SafeURL` refuses a relative address. So no existing golden case changes meaning. |
| + - An external image is never fetched or hotlinked. That would hand a reader's address to a third party, and `img-src 'self'` refuses it anyway. |
| + - Paste and the importer turn external images into Mapa images or into links (§2.2, §7). |
| +- **It is an inline span** (`markup.Image`) wherever links are parsed, and never inside code. |
| + - Like a link, it is part of its block. |
| + - **When a block's text is only one image**, perhaps with a `^id`, both Go's `Render` and `toDOM` mark that image with the class `alone`. The CSS draws it as a block. |
| +- **The text index** reads alt text as body text. It does not read the address. |
| + - So search and snippets find alt text, and never `i` or an id. |
| + - **Unlinked mentions ignore alt text.** `linkFirstMention` edits only text spans, so it could never link one. |
| +- **S3 and memoria** see an image as its alt text. No bytes and no image id reach a sibling. |
| +- **History's word diff** treats the image span as one token, so it shows as changed when its id changes, even under the same alt text. It is drawn as `[image: alt]`. |
| + |
| +**Rejected: `![[image:…]]`.** |
| +- `![[app:item]]` is Mapa's embed grammar (base §7). Its rules would all have to learn that `image` is not an app. Those rules are the team container's check at write, render enforcement (gate 12) and S10 payloads. |
| +- It has no standard place for alt text. |
| +- It survives nowhere outside Mapa. `` is what Obsidian, GitHub and every Markdown tool read. |
| +- The stored address is relative, so it never names a host. That matters because Paul's team URLs will move host (`paulca.mapa.oficina.works`). |
| ### 2.2 Copy, paste and export |
| -- **Within Mapa, with script.** Copy and cut put `` into `text/plain` and into the `application/x-mapa` slice (level-up §6.6). |
| - - **Paste into a different page** first calls `POST /images/copy` with the slice's ids. It gets back a new pending image (§3.2) for each id the viewer may read, and rewrites those addresses in the pasted text before inserting it. |
| - - An id the viewer may not read is left as it is, and renders as unavailable. The reply leaves it out exactly as it leaves out an id that does not exist. |
| - - Paste into the same page keeps the ids: the picture is already attached there. |
| - - The rewritten blocks are new blocks with fresh origins, so fidelity (§2.3) is untouched. |
| -- **Image files on the clipboard,** from screenshots, Finder or Photos, are uploaded (§4.1). |
| -- **HTML from outside:** an `<img>` with a remote `src` becomes a web link (`[alt](src)`), or nothing when there is no safe address. Mapa never fetches it. |
| -- **The scriptless textarea:** text pasted there is kept as typed. A copied `` from another page renders as unavailable on this one (§3.1), so the Markdown screen's help line says to use Upload instead. This is a known limit of the floor, not a leak. |
| -- **Export** (base decision 15, not built yet): each exported page's attached images go into `attachments/<public id>.<ext>`, and the page's addresses are rewritten to `attachments/…`. Obsidian reads that form. Until export exists, there is nothing to do. |
| +- **Copying within Mapa, with script:** |
| + - Copy and cut put `` into `text/plain` and into the `application/x-mapa` slice (level-up §6.6). |
| + - **The slice also carries the public id of the page it came from.** |
| +- **Paste into the same page** keeps the ids. |
| +- **Paste into any other page,** or from a slice with no source page, works like this: |
| + - It calls `POST /images/copy` with every image id that the island does not resolve as attached here. |
| + - The reply holds `{id, width, height}` for each new pending image (§3.2), one for each id the person may read. |
| + - The editor rewrites those addresses in the pasted text before inserting it. |
| + - Any other id stays as it is and renders as unavailable. The reply leaves it out, exactly as it leaves out an id that does not exist. |
| + - The pasted blocks are new blocks with fresh origins, so fidelity (§2.3) is untouched. |
| +- **Image files on the clipboard** are uploaded (§4.1). They come from screenshots, Finder or Photos. |
| +- **HTML from outside:** an `<img>` with a remote `src` becomes a web link, `[alt](src)`. With no safe address it becomes nothing. Mapa never fetches it. |
| +- **An address typed by hand** gets its state from `POST /links/resolve`, which now answers image ids too. It is scoped as rendering is (§3.1), so the editor reserves the right box. |
| +- **The scriptless textarea keeps pasted text as typed.** |
| + - A copied `` from another page renders as unavailable there (§3.1). The Markdown screen's help line says to use Upload instead. |
| + - This is a known limit of the floor, not a leak. |
| +- **Export** (base decision 15) is not built yet. When it is: |
| + - each page's attached images go into `attachments/<public id>.<ext>`; |
| + - the page's addresses are rewritten to `attachments/…`, which Obsidian reads. |
| ### 2.3 Fidelity gates L1–L4 |
| -- **Corpus.** New cases include: |
| - - an image alone in a paragraph, in a list item and in a quote; |
| +- **New corpus cases:** |
| + - an image alone in a paragraph, in a list item, in a task item, in a quote and in a heading; |
| - an image between words, two images on one line, and an image with `^id`; |
| - - an empty alt, and alt text with `*` and `` ` ``; |
| + - an image inside emphasis, and inside a web link's label (`[](https://…)`); |
| + - an empty alt; alt with `*` and `` ` ``; alt at exactly 1,000 bytes, and at 1,001, made of multi-byte characters; |
| - `` and ``; |
| - ``, `` and ``; |
| - - `` added on a line of its own, and the base unchanged. |
| -- Nothing is committed and no draft is written. Save commits as before, and the commit attaches the image (§3.2). |
| -- This re-render is the same one a refused save already does, and it works for every page kind, including an unwritten day and a new scratch page. |
| +The Markdown screen's form gains a file input and a second button, **Upload and insert**. |
| + |
| +- **What the POST carries:** the textarea's text, the base revision and the file. |
| + - `MaxBytesReader` bounds the request at the text's own limit plus 10 MiB. |
| + - The file part alone is held to 10 MiB. |
| +- **What the server does:** |
| + - It uploads the file as a pending image. |
| + - It shows the Markdown screen again: the submitted text, with `` added **at the end** on a line of its own, and the base unchanged. |
| + - Nothing is committed, and no draft is written. |
| +- **Save** commits as before, and the commit attaches the image (§3.2). |
| +- **This re-render is the one a refused save already does.** It works for every kind of page, an unwritten day and a new scratch page included. |
| +- **Below the form,** "Images on this page" (§3.3) offers Open and Remove. |
| ### 4.5 No shift: L5 |
| - **The server draws** `<img src="/i/{id}" alt="…" width="W" height="H" loading="lazy" decoding="async">`, with W and H from the sealed record. |
| - - The browser reserves the box from the aspect ratio before any byte arrives. |
| + - The browser reserves the box from the aspect ratio before a byte arrives. |
| - An unavailable image is a box of fixed size. |
| -- **The island** (level-up §6.8) gains image resolutions, scoped exactly as rendering is (§3.1), so the editor's NodeView draws identical markup. |
| +- **The island** (level-up §6.8) gains image resolutions, scoped as rendering is (§3.1). So the editor's NodeView draws identical markup. |
| +- **New images get their size** from the upload reply, the copy reply and `/links/resolve` (§2.2). |
| - **L5 gains a page with images:** |
| - - one image above the fold, one below, one unavailable, one in a draft; |
| + - one above the fold, one below, one unavailable, and one in a draft; |
| - every block's box is the same before and after mount, **and before and after the images load**; |
| - no `layout-shift` entry is recorded. |
| ### 4.6 Accessibility: L10 |
| -- The image NodeView is named "Image: <alt>", or "Image with no description". |
| -- A selected image shows the focus ring. |
| -- The alt field has its label. |
| -- The upload box is `role="group"`, named "Uploading <file>". Its `<progress>` is labelled. |
| -- A polite live region announces "Image added" or the failure. |
| -- Insert → Image is the keyboard path; drag and drop is never the only one. |
| -- **L10 gains:** a keyboard-only walk of Insert → Image (with the picker stubbed), the alt field, the bubble's Alt text, and Remove's confirm. axe-core then finds nothing serious on a page with images. |
| +- **Naming:** |
| + - The image NodeView is named "Image: <alt>", or "Image with no description". |
| + - The alt field has its label. |
| + - The upload box is `role="group"`, named "Uploading <file>". Its `<progress>` is labelled. |
| +- **A selected image** shows the focus ring. |
| +- **A polite live region** announces "Image added" or the failure. |
| +- **Insert → Image is the keyboard path.** Drag and drop is never the only way in. |
| +- **L10 gains:** |
| + - a keyboard-only walk of Insert → Image with the file picker stubbed, then the alt field, the bubble's Alt text, and Remove's confirm; |
| + - an upload finishing while the person types elsewhere: focus does not move, and the live region speaks; |
| + - axe-core finds nothing serious on a page with images. |
| --- |
| ## 5. Formats and safety |
| -- **Allowed types:** PNG, JPEG, GIF (animation included) and WebP (animation included). |
| - - **The type is decided from the bytes** (magic numbers, as Slides' `sniffImage` does). The claimed `Content-Type` and the file name are ignored. |
| - - Then the format's own decoder reads the header (`image.DecodeConfig`: the standard library, plus `golang.org/x/image/webp`, a new dependency added to the Colophon). It must agree on the type and give dimensions inside the limits. |
| +- **Allowed:** PNG, JPEG, GIF and WebP, animated GIF and WebP included. |
| +- **The type is decided from the bytes** (magic numbers, as Slides' `sniffImage` does). The claimed `Content-Type` and the file name are ignored. |
| +- **The format's own decoder then reads the header** (`image.DecodeConfig`). That is the standard library, plus `golang.org/x/image/webp`, a new dependency added to the Colophon. It must agree on the type, and give dimensions inside the limits. |
| - **Refused:** |
| - - **SVG.** It is a document that can carry script, served from Mapa's own origin. Docs refused it for that reason; Slides sanitises it, and that is a second parser to keep safe (Q1). |
| - - HEIC, AVIF, TIFF, BMP, PDF and anything else. |
| - - Each refusal is 415 with a sentence naming the four formats that are accepted. |
| -- **Metadata is stripped, without re-encoding.** A container walker in pure Go (`CGO_ENABLED=0`, so there is no WebP encoder, and re-encoding a JPEG loses quality) rewrites the file: |
| - - **JPEG:** keeps the SOF, DQT, DHT, SOS and scan data, APP0 (JFIF), APP2 ICC and APP14 (Adobe). It drops APP1 (EXIF and XMP), APP13 (IPTC), COM and every other APPn. **Orientation is kept:** when EXIF said anything but 1, Mapa writes a minimal APP1 holding only the Orientation tag, so phone photos stay upright. The stored width and height are the ones after rotation. |
| - - **PNG:** keeps the critical chunks, plus `iCCP`, `sRGB`, `gAMA`, `cHRM`, `pHYs`, `tRNS`, `bKGD`, `sBIT` and the APNG chunks. It drops `eXIf`, `tEXt`, `zTXt`, `iTXt`, `tIME` and unknown ancillary chunks. |
| - - **WebP:** keeps `VP8`/`VP8L`/`VP8X`, `ALPH`, `ANIM`/`ANMF` and `ICCP`. It drops `EXIF`, `XMP ` and unknown chunks, and fixes VP8X's flags and RIFF's size. |
| - - **GIF:** keeps the image data, the graphic control extensions and the `NETSCAPE2.0` loop. It drops comments, plain text and every other application extension (XMP rides in one). |
| - - **Anything the walker cannot parse is refused,** not passed through. So location, camera serials, author names, edit history and thumbnails never reach the bucket. |
| + - **SVG.** It is a document that can carry script, served from Mapa's own origin. Docs refused it for this reason. Slides sanitises it, and that would be a second parser to keep safe (Q1). |
| + - HEIC, AVIF, TIFF, BMP, PDF, and everything else. |
| + - Each refusal is a 415 with a sentence naming the four formats Mapa takes. |
| +- **Metadata is stripped without re-encoding.** |
| + - The work is done by a container walker in pure Go. `CGO_ENABLED=0` means there is no WebP encoder, and re-encoding a JPEG loses quality. |
| + - **The walker drops named kinds of metadata and keeps the image's own structure**, so a segment it does not list is never lost when the picture needs it. |
| +- **JPEG:** |
| + - **Dropped:** |
| + - every APPn segment except three: APP0 that starts `JFIF\0`, APP2 that starts `ICC_PROFILE\0`, and APP14 that starts `Adobe`; |
| + - every COM segment. |
| + - **Kept:** every other marker segment. That covers every SOFn, DQT, DHT, DRI, DNL, DAC and SOS, with the scan data and its RSTn markers. |
| + - **In the kept APP0,** the JFIF thumbnail is removed (width and height set to 0, data dropped). JFXX APP0 segments go. |
| + - **Orientation is kept.** When EXIF gave anything but 1, Mapa writes a minimal APP1 holding only the Orientation tag, so phone photos stay upright. The stored width and height are those after rotation. |
| + - **The file ends at EOI.** That drops Motion Photo video, MPF second images, gain maps and vendor trailers. |
| +- **PNG:** |
| + - **Kept:** |
| + - the critical chunks; |
| + - `iCCP`, `sRGB`, `gAMA`, `cHRM`, `cICP`, `mDCV`, `cLLI`, `sBIT`, `pHYs`, `tRNS` and `bKGD`; |
| + - the APNG chunks (`acTL`, `fcTL`, `fdAT`). |
| + - **Dropped:** `eXIf`, `tEXt`, `zTXt`, `iTXt`, `tIME` and every unknown ancillary chunk. |
| + - **The file ends at IEND.** |
| +- **WebP:** |
| + - **Kept:** `VP8 `, `VP8L`, `VP8X`, `ALPH`, `ANIM`, `ANMF` and `ICCP`. |
| + - **Dropped:** `EXIF`, `XMP ` and unknown chunks. VP8X's flags and RIFF's size are rewritten to match. |
| + - **The file ends at the RIFF length.** |
| +- **GIF:** |
| + - **Kept:** the image data, the graphic control extensions, and the `NETSCAPE2.0` loop extension. |
| + - **Dropped:** comments, plain-text extensions and every other application extension. XMP rides in one. |
| + - **The file ends at the trailer.** |
| +- **ICC profiles are kept** because colour needs them. A profile can name a monitor or the person who calibrated it. That is the one piece of descriptive metadata left, and Help says so. |
| +- **Anything the walker cannot parse is refused,** never passed through. So location, camera serials, author names, edit history, thumbnails and hidden trailers never reach the bucket. |
| - **Limits:** |
| - - 10 MiB of upload body, enforced with `http.MaxBytesReader` before any parse; |
| - - at most 10,000 px on a side and 40 megapixels in all, from `DecodeConfig`, before any further work. Mapa never decodes pixels, so a decompression bomb costs nothing. |
| -- **Served safely** (§1.4): the stored type, `nosniff`, and `default-src 'none'; sandbox`. |
| - - An image opened on its own is still an image on Mapa's origin, and cannot run anything. |
| - - A polyglot (a JPEG with HTML after it) is served as `image/jpeg` with `nosniff`, so it cannot become a page. |
| - - The page CSP is unchanged (`img-src 'self' data:`). |
| -- **Scanning** cannot read sealed objects, and Mapa never asks for it (Q5). The format allowlist, the strict walker and the sandboxed serving are Mapa's own defence. |
| + - The upload body is bounded with `http.MaxBytesReader` before anything is parsed. |
| + - From `DecodeConfig`, before any further work: |
| + - at most 10,000 px on a side; |
| + - at most 50 megapixels in all (§4.1 scales large photos down when script is on). |
| + - Mapa never decodes pixels, so a decompression bomb costs it nothing. |
| + - A reader's browser still decodes whatever is shown. 50 MP is about 200 MB there, and that is why script scales photos down. |
| +- **Served safely** (§1.4): |
| + - The headers are the stored type, `nosniff`, and `default-src 'none'; sandbox`. |
| + - An image opened on its own is still an image on Mapa's origin, and can run nothing. |
| + - Nothing follows the image's end, so no trailing document is served. |
| + - The page CSP does not change (`img-src 'self' data:`). |
| +- **Scanning cannot read sealed objects,** and Mapa never asks for it (Q5). The allowlist, the strict walker and sandboxed serving are Mapa's own defence. |
| --- |
| @@ -324,114 +492,182 @@ The Markdown screen's form gains a file input and a second button, **Upload and |
| | Change | Gate | |
| |---|---| |
| -| **Migration `0005_images`:** `images` and `image_trash` (§1.3). The `public_id` index is unique, and there is an index on `(page_id)` and on `(owner, page_id)` | migration check; **gate 4**: `plaintext_test.go` names the new columns exactly, and the file scan (I2 below) | |
| -| **`seal` purposes `image` and `image-record`** | **gate 4** | |
| -| **`images.go`:** sniff, walk and strip, limits, seal, `Put`, row and event. One function serves the route and the importer (§7) | I5, I6 | |
| -| **`POST /images`:** upload. JSON for script; the Markdown screen's re-render without (§4.4) | I3, I6, L8 | |
| -| **`GET /i/{id}`:** scoped serving, 304, headers (§1.4) | **gate 1**, I1, **gate 10**/L7, I6 | |
| -| **`POST /images/copy`:** `{ids}` → `{id: new}`, only for ids the person may read | **gate 1**, I1, **gate 8** | |
| -| **`GET` and `POST /i/{id}/remove`:** confirm page and removal | **gate 8**, I7, L8 | |
| -| **`tx.commit` attaches** pending images owned by the person committing (§3.2) | I7, and a mutation: attach without the owner check | |
| -| **`MakeTeamPage` copies and rewrites; `Restore` re-points** | I7, L9 | |
| -| **`Store.Sweep` sweeps images and empties the trash** (§3.3) | I7, gate 8's named exemption | |
| -| **`markup.Image`, `Render` and the resolver;** the text index skips the address | L1–L4, I1 | |
| -| **Event vocabulary:** object kind `image`, verbs `uploaded` and `removed`. The index already reads only `object_kind = page` events (`index.go`) | **gate 8** | |
| -| **`config.go`:** `CARLOS_STORE_*` read through `blobs.S3FromEnv`; a partly delivered store refuses to boot; `MAPA_IMAGE_QUOTA_BYTES` | `config_test.go` | |
| - |
| -**New gates.** They run in `make ci` unless marked as browser gates. |
| - |
| -- **I1, scope** (extends gate 1 and L6). Ana has a private page with images, a pending upload, and a private image whose id is typed into a team page. Bo's view is byte-identical with or without each of these, across: |
| - - the team page's HTML and its island; |
| - - `GET /i/<Ana's id>`, which gives the same status, headers and body as an id that never existed; |
| - - `POST /images/copy`. |
| - |
| - Two `make mutate` mutants must each be caught: one drops the route's scope check, and one resolves images attached to other pages. |
| -- **I2, the plaintext file scan** (extends gate 4). The test uploads a PNG and a JPEG carrying canary strings in `tEXt`, EXIF, XMP and the file name, and uses a canary alt text. Then neither the database file (WAL included) nor the blob directory holds any canary, a PNG or JPEG magic number, or the alt text. The fake S3 records `Content-Type: application/octet-stream`. |
| -- **I3, events** (extends gate 8). Upload, copy and removal each log their event. The sweep is the named exemption. A mutant that drops the upload's event is caught. |
| -- **I4, nothing written by a GET** (extends gate 10 and L7). The row-dump hash is unchanged across `GET /i/{id}` (200 and 304), page views with images, the island, and the remove confirm page. |
| -- **I5, stripping.** For each format, the canary metadata and GPS are gone from what is served, while ICC and the JPEG orientation stay. The pixels are unchanged: Mapa decodes before and after in the test only. Truncated, oversized and malformed chunks are refused. A Go fuzz target on each walker runs its seed corpus in CI. |
| -- **I6, refusals and headers.** |
| - - Refused: a type claimed but not true; SVG; HEIC; HTML; over 10 MiB; over 10,000 px or 40 MP; over the person's quota; no store (503); five uploads at once. |
| +| **Migration `0005_images`:** `images` and `image_trash` (§1.3). <br>Unique `public_id`. Indexes on `(page_id, unreferenced_at)` and `(owner, page_id)` | the migration check <br>**gate 4**: `plaintext_test.go` names the new columns exactly, and IMG2 | |
| +| **`seal` purposes `image` and `image-record`;** the 64 KiB padding | **gate 4**, IMG2 | |
| +| **`images.go`:** sniffing, the walker, the limits, the seal, `Put`, the row and the event. One function serves the route and the importer (§7), and another serves copies. <br>Object work runs before any transaction. If a transaction fails after a `Put`, the object is deleted | IMG5, IMG6, IMG7 | |
| +| **The blob semaphore** (§1.4) | IMG6 | |
| +| **`POST /images`:** the upload. JSON with script; the Markdown screen re-rendered without it (§4.4) | IMG3, IMG6, L8 | |
| +| **`GET /i/{id}`:** scoped serving, 304, headers (§1.4) | **gate 1**, IMG1, **gate 10**/L7, IMG6 | |
| +| **`POST /images/copy`:** `{ids}` → `{id: {id, width, height}}`, only for ids the person may read | **gate 1**, IMG1, **gate 8** | |
| +| **`POST /links/resolve`** answers image ids, scoped | IMG1, L6 | |
| +| **`GET` and `POST /i/{id}/remove`:** the confirm page and removal. The Markdown screen's Images on this page list | **gate 8**, IMG1, IMG7, L8 | |
| +| **`tx.commit`** attaches the committer's own pending images that the commit introduces, and stamps and clears `unreferenced_at` (§3.2, §3.3) | IMG7 <br>Two mutants: attaching without the owner check; attaching ids that were not introduced | |
| +| **`MakeTeamPage` copies, then writes. `Restore` re-points. `draftToScratch` copies** | IMG7, L9 <br>A mutant: Make team page copying an image that is not attached to its source | |
| +| **`Store.Sweep`** sweeps images. `image_trash` is emptied off the boot path (§3.3) | IMG7, gate 8's named exemption | |
| +| **`markup.Image`, the `alone` class, `Render` and the resolver.** The text index skips the address; mentions skip alt text | L1–L4, IMG1 | |
| +| **Event vocabulary:** object kind `image`, verbs `uploaded` and `removed`. Every event reader already filters on `object_kind = page` (index, recent, versions, verbs) | **gate 8** | |
| +| **`config.go`:** `CARLOS_STORE_*` through `blobs.S3FromEnv`. A partial store boots with uploads at 503 and logs loudly (decision 4). Also `MAPA_IMAGE_QUOTA_PERSON` and `MAPA_IMAGE_QUOTA_TEAM` | `config_test.go` | |
| + |
| +**New gates.** They run in `make ci` unless marked "browser". |
| + |
| +- **IMG1, scope.** This extends gate 1 and L6. |
| + - **The setup:** Ana has: |
| + - a private page with images; |
| + - a pending upload; |
| + - a private image whose id is typed into a team page. |
| + - **What must not change:** Bo's output is byte-identical with or without each of those, across: |
| + - the team page's HTML and its island; |
| + - `/links/resolve`; |
| + - `GET /i/<Ana's id>` and `GET /i/<Ana's id>/remove`, which give the same status, headers and body as an id that never existed; |
| + - `POST /images/copy`. |
| + - **Ana's own commit** of the team page that holds her typed pending id leaves the image unattached. |
| + - **Mutants** (`make mutate`), each of which must be caught: |
| + - one drops the route's scope check; |
| + - one resolves images attached to other pages; |
| + - one makes attach ignore "introduced". |
| +- **IMG2, the plaintext file scan.** This extends gate 4. |
| + - **The setup:** a PNG and a JPEG are uploaded with canary strings: |
| + - in `tEXt`, EXIF, XMP and a JPEG trailer after EOI; |
| + - in the file name; |
| + - in the alt text. |
| + - **What must hold:** |
| + - The database file holds no canary and no alt text, WAL included. |
| + - The blob directory holds no canary and no alt text. |
| + - No blob starts with a PNG or JPEG magic number. Only offset 0 is checked, because ciphertext matches by chance elsewhere. |
| + - The fake S3 records `Content-Type: application/octet-stream`. |
| + - Every stored size is a multiple of 64 KiB plus the seal's constant. |
| +- **IMG3, events.** This extends gate 8. |
| + - Upload, copy and removal each log their event. |
| + - The sweep is the named exemption. |
| + - A mutant that drops the upload's event must be caught. |
| +- **IMG4, nothing written by a GET.** This extends gate 10 and L7. The row-dump hash stays unchanged across: |
| + - `GET /i/{id}`, both 200 and 304; |
| + - page views with images; |
| + - the island; |
| + - the remove confirm page. |
| +- **IMG5, stripping.** For each format: |
| + - The canary metadata, GPS and trailers are gone from what is served. |
| + - ICC and the JPEG orientation stay. |
| + - **The pixels are unchanged.** The test decodes before and after; Mapa itself never decodes. |
| + - JPEG fixtures cover baseline, progressive, **restart intervals (DRI)**, CMYK with Adobe APP14, a JFIF thumbnail, and Motion Photo. |
| + - Truncated, oversized and malformed chunks are refused. |
| + - A Go fuzz target on each walker runs its seed corpus in CI. |
| +- **IMG6, refusals, headers and memory.** |
| + - **Each of these is refused:** |
| + - a claimed type that is not true; |
| + - SVG, HEIC and HTML; |
| + - a file over 10 MiB; |
| + - an image over 10,000 px on a side or over 50 MP; |
| + - an upload over either quota; |
| + - an upload with no store (503); |
| + - a fifth blob operation that has waited 10 s. |
| - Every served image carries §1.4's headers. |
| -- **I7, lifecycle.** |
| - - Attach happens only for the committer's own pending images. |
| - - Copy happens only for images the person can read. |
| - - Make team page copies; Restore re-points. |
| - - Removal makes the image unavailable everywhere, History included. |
| - - The sweep keeps an image that a retained revision or a draft references. It removes a pending image after a day, and a deleted page's images after 90 days. |
| - - A failed object delete stays queued. |
| - - A failed transaction after `Put` deletes the object. |
| +- **IMG7, lifecycle.** |
| + - **Attaching:** a commit attaches only the committer's own pending images that it introduces. Bulk verbs attach nothing. |
| + - **Copying:** only images the person can read are copied. |
| + - **Make team page:** |
| + - copies only images attached to its source; |
| + - leaves pending copies when its write fails; |
| + - makes no S3 call inside its transaction. |
| + - **Restore** re-points. A deleted page's draft brings copies into its scratch page. |
| + - **`unreferenced_at`** is stamped on removal from the text and cleared on Revert. |
| + - **Removal** makes the image unavailable everywhere, History included. |
| + - **The sweep:** |
| + - keeps an image that a draft or a revision in the window references; |
| + - removes a pending image after seven days, and a deleted page's images after 90; |
| + - unseals nothing when no candidate exists; |
| + - never fails boot when the bucket is down. |
| + - **Failures:** a failed object delete stays queued. A failed transaction after `Put` deletes the object. |
| - **The page gates extend:** |
| - - L5: §4.5's page; |
| - - L8: Upload and insert, and Remove's confirm, with script off; |
| - - L9: an upload in flight across autosave, commit, rebase and leaving; |
| - - L10: §4.6; |
| - - L12: the bundle's size is logged. |
| + - **L5:** §4.5's page. |
| + - **L8:** Upload and insert, the Images on this page list, and Remove's confirm, all with script off. |
| + - **L9:** an upload in flight across autosave, commit, rebase, the inline choice, and leaving. |
| + - **L10:** §4.6. |
| + - **L12:** the bundle's size is logged. |
| --- |
| ## 7. The importer hook |
| -The Notion importer calls the store, never the HTTP route. It uses the same function the route uses: |
| +The Notion importer calls the store, never the HTTP route, through the same functions the routes use: |
| ```go |
| // AddImage reads one image, checks and strips it (§5), seals it, stores |
| // it, and records it as a pending image owned by actor, logging |
| -// "uploaded" by actor. It never names Mapa as the actor. |
| +// "uploaded" by actor (never Mapa). It waits for the blob semaphore |
| +// (§1.4) rather than failing. |
| func (store *Store) AddImage(ctx context.Context, actor int64, |
| data io.Reader) (Image, error) |
| -// Image.Markdown(alt) is "", with alt cleaned to |
| -// the form §2.1 allows ([, ] and line breaks removed; at most 1,000 |
| -// bytes). |
| +// CopyImage makes a new pending image owned by actor from one actor may |
| +// read, with a new object. It is the function /images/copy and Make |
| +// team page use. |
| +func (store *Store) CopyImage(ctx context.Context, actor int64, |
| + publicID string) (Image, error) |
| + |
| +// Markdown is "", with alt cleaned to §2.1's form: |
| +// [, ] and line breaks removed, and at most 1,000 bytes, cut at a rune. |
| func (image Image) Markdown(alt string) string |
| ``` |
| -**How the importer uses it:** |
| -- It calls `AddImage` for each image file in the Notion export, puts `image.Markdown(caption or alt)` into the page body, and then creates or commits the page through the ordinary verbs as that person. The commit attaches the images (§3.2). |
| -- **Typed refusals** tell the importer what to write in place of the image: `ErrImageType`, `ErrImageTooLarge`, `ErrImageDimensions`, `ErrImageQuota`, `ErrNoImageStore`. A refused image becomes a text line, `(Image not imported: <file name>, <reason>)`, so nothing vanishes silently. |
| -- **Notion's remote images** (an `https://` source not in the export) are not fetched by `AddImage`. Whether the importer fetches them is that spec's call. If it does, it passes the bytes in here. |
| -- A failed import leaves pending images, which are swept after a day (§3.3). The importer needs no cleanup of its own. |
| +**How the importer uses them:** |
| +- **One image per place.** |
| + - An `Image` attaches to the first page whose commit introduces it. |
| + - When a Notion file appears on two pages, the importer calls `AddImage` once and `CopyImage` for each further page. |
| + - It puts `image.Markdown(caption or alt)` in each body, then creates or commits each page through the ordinary verbs as that person. The commit attaches the images (§3.2). |
| +- **Quota.** Images imported into team pages count against the team's allowance (`MAPA_IMAGE_QUOTA_TEAM`, default 10 GiB). Images in private pages count against the importing person's allowance. |
| + - Both are checked at `AddImage` and `CopyImage`. |
| + - The importer spec should check the export's total against them before it starts, and say so to the person. |
| +- **Typed refusals** tell the importer what to write in place of an image: `ErrImageType`, `ErrImageTooLarge`, `ErrImageDimensions`, `ErrImageQuota` and `ErrNoImageStore`. |
| + - A refused image becomes a text line: `(Image not imported: <file name>, <reason>)`. Nothing vanishes silently. |
| +- **Notion's remote images** (an `https://` source that is not in the export) are not fetched by `AddImage`. Whether the importer fetches them is that spec's call. If it does, it passes the bytes in here. |
| +- **A failed import** leaves pending images, which are swept after seven days (§3.3). The importer needs no cleanup of its own. |
| --- |
| ## 8. CARLOS setup for the live instance |
| -The live instance is the lone app `mapa` on account `oficina` (`bds`), at mapa.oficina.works. On 2026-11-17, `carlos store status --app mapa --account oficina` answered "no store is declared for this app". Paul, or the agent with Paul's say-so, runs these steps **after** the build is merged and deployed. Until then, upload answers 503 (I4). |
| +The live instance is the lone app `mapa`, on account `oficina` (`bds`), at mapa.oficina.works. On 2026-11-17, `carlos store status --app mapa --account oficina` answered "no store is declared for this app". |
| + |
| +Paul runs these steps, or the agent runs them with his say-so, **after** the build is merged and deployed. Until then, upload answers 503 (decision 4). |
| -1. **Check the account's plan does not force scanning.** Slides' store has scanning "not requested" today, so the plan does not force it now. |
| - - If the account is ever on a plan with `storage_scan_required`, the sealed store would be refused (`store.scan_required.encrypted`). |
| - - Keep oficina on a plan, or a house account, that does not force scanning (Q5). |
| -2. **Declare the store** (and provision it, on an approved account): |
| +1. **Read the account's plan directly.** Use the console's Billing page for `oficina`. |
| + - **Stop if the plan has object storage "scanned for viruses"** (`storage_scan_required`). On that plan, `store create` would force scanning onto ciphertext (§1.1). |
| + - Move the account to a plan that does not force scanning, or make it a house account (Q5). |
| + - Slides' store is not evidence either way: it was granted before the 2026-11-15 catalog. |
| +2. **Declare the store.** On an approved account, this also provisions it: |
| ```sh |
| carlos store create --app mapa --account oficina |
| ``` |
| -3. **If step 2 left it declared but not provisioned,** an operator (Paul) grants it: |
| +3. **Check that scanning is off:** |
| + ```sh |
| + carlos store scan status --app mapa --account oficina |
| + ``` |
| + It should say "not requested". If scanning is on, stop and bring it to Paul. Do not upload anything until it is off: `carlos store scan revoke --app mapa --account oficina` is an operator verb. |
| +4. **If step 2 left the store declared but not provisioned,** an operator (Paul) grants it: |
| ```sh |
| carlos store grant --app mapa --account oficina |
| ``` |
| -4. **Check what was delivered:** |
| +5. **Check what was delivered:** |
| ```sh |
| carlos store status --app mapa --account oficina |
| ``` |
| - It should name bucket `carlos-store-bds-mapa`, and `delivers: CARLOS_STORE_BUCKET, CARLOS_STORE_REGION, CARLOS_STORE_ACCESS_KEY, CARLOS_STORE_SECRET_KEY`, with nothing still to reach the app's config. |
| -5. **Restart, so the process reads the new config,** then check: |
| + - It should name a bucket, presumably `carlos-store-bds-mapa`. |
| + - It should list `delivers: CARLOS_STORE_BUCKET, CARLOS_STORE_REGION, CARLOS_STORE_ACCESS_KEY, CARLOS_STORE_SECRET_KEY`. |
| + - Nothing should still be waiting to reach the app's config. |
| +6. **Restart, so the process reads its new config, then check:** |
| ```sh |
| carlos restart --app mapa --account oficina |
| curl -s https://mapa.oficina.works/api/version |
| carlos logs --app mapa --account oficina |
| ``` |
| - The log should say "mapa: object store bound". |
| -6. **Do not request scanning.** If anyone ever does, the honest attestation is: |
| - ```sh |
| - carlos store scan request --app mapa --client-encrypted |
| - ``` |
| - That claims no coverage. |
| -7. **No CORS rule is needed:** no browser ever talks to the bucket. |
| -8. **Later, for team instances through Alta:** |
| + The log says "mapa: object store bound". Upload one image and open it. |
| +7. **Never request scanning.** If anyone ever does, the honest attestation is `carlos store scan request --app mapa --client-encrypted`. It claims no coverage. |
| +8. **No CORS rule is needed.** No browser ever talks to the bucket. |
| +9. **Later, for team instances through Alta:** |
| - Paul runs `carlos instances enable --app mapa --private-storage`. |
| - - Alta's `provision/apps.go` gains Mapa, with `Store: true`, as Slides has (Alta `916aac3`). |
| - - Under the new catalog, a plan that forces scanning refuses per-instance stores outright. |
| + - Alta's `provision/apps.go` gains Mapa with `Store: true`, as Slides has (Alta `916aac3`). |
| + - A plan that forces scanning refuses per-instance stores outright. |
| --- |
| @@ -439,26 +675,57 @@ The live instance is the lone app `mapa` on account `oficina` (`bds`), at mapa.o |
| | Thing | Trigger | |
| |---|---| |
| -| Resized display copies (thumbnails, `srcset`) | Pages with photos feel slow on a phone. Today a 10 MiB photo is sent whole | |
| +| Display copies made on the server (thumbnails, `srcset`) | Pages with photos feel slow on a phone even after §4.1's scaling | |
| | A width per image | People ask for a smaller picture beside text | |
| | Captions | People write captions under images and want them tied to the image | |
| | SVG, behind Slides' sanitiser | Paul rules yes on Q1 | |
| | AVIF and HEIC | A browser hands Mapa one. iOS converts HEIC today | |
| | Presigned direct reads | Never, while images are sealed | |
| -| A bucket reconcile (list the bucket, delete unknown keys) | `image_trash` misses something. Today only a crash between `Put` and its transaction can leave an orphan object | |
| +| Streaming, chunked sealing | §1.4's semaphore makes pages wait in real use | |
| +| A bucket reconcile: list the bucket, delete unknown keys | `image_trash` misses something. Today only a crash between `Put` and the transaction's cleanup can leave an orphan object | |
| ## 10. Open questions for Paul |
| -1. **SVG: refused or sanitised?** *Recommended: refused.* An SVG is a script-capable document served from Mapa's own origin. Slides' sanitiser exists, but it would be a second copy to keep safe. Notion pages rarely hold SVG. |
| -2. **The per-person quota.** *Recommended: 1 GiB per person and 10 MiB per image.* A team-wide quota would leak a count of private images. |
| -3. **Captions and sizing.** *Recommended: neither in v1.* Images show at natural size, capped at the column. |
| -4. **External image Markdown** (``). *Recommended: render as today*, a `!` and a link. It is never fetched. |
| -5. **The oficina account's plan.** *Recommended: keep it on a plan that does not force scanning,* because a sealed store cannot be scanned. Turn on `--private-storage` for Mapa when it joins Alta. |
| -6. **Who may remove an image on a team page.** *Recommended: any member*, as with deleting a page, with a confirm page and an event naming them. |
| -7. **The sweep's events.** *Recommended: keep retention exempt from gate 8 by name*, as it is today. Removal by a person logs an event, but the sweep would have to name Mapa as the actor. |
| +1. **SVG: refused or sanitised?** *Recommended: refused.* An SVG is a script-capable document on Mapa's own origin. Slides' sanitiser exists, but it would be a second copy to keep safe. Notion pages rarely hold SVG. |
| +2. **Quotas.** *Recommended: 1 GiB per person, for pending images and images on private pages; 10 GiB for the team, for images on team pages; and 10 MiB per image.* A single team-wide total over everything would leak a count of private images. |
| +3. **Captions, sizing and scaling.** *Recommended:* no captions and no resizing in v1. With script, JPEGs over 4,096 px on the long side are scaled down before upload (§4.1). So a 48 MP photo becomes about 12 MP, and the original is not kept. |
| +4. **External image Markdown** (``). *Recommended: render as today,* a `!` and a link. It is never fetched. |
| +5. **The oficina account's plan.** *Recommended:* keep it on a plan that does not force scanning, because a sealed store cannot be scanned. Turn on `--private-storage` for Mapa when it joins Alta. |
| +6. **Who may remove an image on a team page.** *Recommended: any member,* as with deleting a page, with a confirm page and an event that names them. |
| +7. **The sweep's events.** *Recommended: keep retention exempt from gate 8 by name,* as it is today. A person's removal logs an event. An event for the sweep would have to name Mapa as the actor. |
| --- |
| ## 11. Findings and what changed |
| -*(Filled in by each review round.)* |
| +### Round 1: Fable on revision 1 (`4d40e4e`), CHANGES REQUIRED, answered in revision 2 |
| + |
| +| Finding | Change | Where | |
| +|---|---|---| |
| +| **H1** Make team page copied every image the moved blocks named, with no scope, and did S3 work inside its SQLite write | Copies only images attached to the source page. Copies are made before the transaction, as pending images owned by the actor, through `CopyImage`. `tx.commit` attaches them. A failed write leaves pending copies for the sweep. A mutant was added | §2.4, §3.2, §6, IMG7 | |
| +| **H2** The JPEG keep-list omitted DRI, corrupting photos with restart intervals for good | The rule is inverted: drop named APPn and COM, keep every other marker. DRI, progressive and CMYK fixtures were added | §5, IMG5 | |
| +| **M1** Attach at commit was a confused deputy: a typed pending id was published by its owner's next commit, bulk verbs included | Attach only ids the commit introduces. Bulk verbs attach nothing. Added to IMG1, IMG7 and a mutant | §3.2, §6 | |
| +| **M2** Exact `stored_bytes` showed the same picture across rungs, undoing decision 3 | Plaintext is padded to 64 KiB before sealing. The gate-4 row says what remains | §1.2 decision 1, §1.3, IMG2 | |
| +| **M3** Trailing data and JFIF thumbnails survived | Each format is cut at its end. JFIF APP0 is kept with no thumbnail, and JFXX goes. ICC kept and stated. A trailer canary was added | §5, IMG2, IMG5 | |
| +| **M4** The sweep would unseal every revision at boot, and bucket deletes could block boot | `unreferenced_at` is stamped by `tx.commit`. Candidates are chosen by SQL, and only the drafts that could keep a candidate are unsealed. The trash is emptied off the boot path | §1.3, §3.3, IMG7 | |
| +| **M5** The memory bound covered uploads only | One semaphore over every blob operation. Waiters queue. The figure is measured on the real instance | §1.4, IMG6 | |
| +| **M6** A per-person quota blocked the importer, and gate 1 does not need it for team images | Two quotas: a person's (pending and private images) and the team's (team-page images) | §3.4, §7, Q2 | |
| +| **M7** The hook had no copy function and was silent on reuse and waiting | `CopyImage` exported. One `AddImage` per file, copies for each further place. `AddImage` waits on the semaphore | §7 | |
| +| **M8** The alt field took focus whenever an upload finished | Focus moves only if the selection is unchanged. Otherwise the live region speaks. Added to L10 | §4.3, §4.6 | |
| +| **M9** Slides' store was no evidence about the plan, and a scan-required plan forces scanning onto the store | Step 1 reads the plan directly. A `scan status` check comes after create. §1.1 corrected | §1.1, §8 | |
| +| **L1** `display: block` for a lone image cannot be done in CSS | Go and `toDOM` emit the class `alone`, pinned in L4 | §2.1, §2.3 | |
| +| **L2** Alt text in unlinked mentions could never be linked | Mentions skip alt text; search keeps it | §2.1 | |
| +| **L3** "No JPEG magic anywhere" would flake on ciphertext | Only offset 0 is checked, plus the canaries | IMG2 | |
| +| **L4** No scriptless way to reach Remove; its 404 was ungated | The Markdown screen gains "Images on this page" with Open and Remove. Both remove routes are in IMG1 | §3.3, §4.4, IMG1 | |
| +| **L5** The clipboard slice had no source page | The slice carries the source page. Any id not attached here is copied | §2.2 | |
| +| **L6** Copied and typed images had no size, so the page shifted | The copy reply carries width and height. `/links/resolve` answers image ids | §2.2, §4.5, §6 | |
| +| **L7** No rule for a placeholder across a rebuild | The decoration maps through every transaction. A lost position puts the image at the end, with a notice | §4.2, L9 | |
| +| **L8** A deleted page's draft became a scratch page with unavailable images | `draftToScratch` copies them and writes the new addresses | §3.2, IMG7 | |
| +| **L9** A one-day pending window lost images in open forms and undo | The window is seven days, applied by reads before the sweep, and stated | §3.1, §3.3 | |
| +| **L10** `MaxBytesReader` covered the textarea too; where the line goes was unsaid | The bound is the text plus 10 MiB, with the file part held to 10 MiB. The line goes at the end | §4.4 | |
| +| **L11** 40 MP refused 48 MP phone photos, and huge images cost readers' browsers | The cap is 50 MP. With script, JPEGs are scaled to 4,096 px on the long side (Q3) | §4.1, §5 | |
| +| **L12** HDR colour chunks were dropped | `cICP`, `mDCV` and `cLLI` are kept | §5 | |
| +| **L13** A partial store refused boot | It boots with uploads at 503 and a loud log | decision 4, §6 | |
| +| **L14** Decision and gate ids collided | The gates are IMG1–IMG7 | throughout | |
| +| **L15** Corpus gaps | Added: image in a heading and a task item, inside emphasis and a link label, and alt at the byte limit in multi-byte characters | §2.3 | |
| +| **L16** History hid an image replaced under the same alt | The diff treats the span as one token, id included | §2.1 | |