Skip to content

feat(claims): station photo backend (#1017 M5) - #1100

Open
dborup wants to merge 1 commit into
masterfrom
feat/1017-m5-photo-backend
Open

dborup wants to merge 1 commit into
masterfrom
feat/1017-m5-photo-backend

Conversation

@dborup

@dborup dborup commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Relates to #1017

Status: M5 (station photo backend) is complete and ready for review. Every requirement has a test that is green here, and 45 of 46 mutants are killed. The one survivor is equivalent; it is explained below. An end-to-end smoke with the real binaries passes 13/13. The Go suites are green, apart from wall-clock perf budgets that fail identically on origin/master on the test machine.

Evidence labels: [T] I ran it here (test, benchmark or command). [K] I read it in the code, the docs or the issue. [A] It is assumed and not verified.

What this PR does (the M5 row of the revised M0 plan)

An owner can add photos of the installation to a claim that sets station details. Photos are never approved automatically: an administrator reviews every one, whatever the switches say. The server stays read-only for SQLite (Kpa-clawbot#1283). It writes files only under station-photos/inbox/, and the ingestor owns the table, the caps, the moves and every deletion.

Part Where
Shared rules: ops photo-submit / photo-approve / photo-reject, PhotoFiles, ValidPhotoID (exactly 16 hex), PhotoLiveSQL / PhotoServableSQL / PhotoUploadSQL, PhotoConfig and PhotoLimits, Command.KeepPhotos internal/channelregistry/antennaclaim/photo.go, antennaclaim.go
Migration antenna_claim_photos_v1, in the ingestor's Apply: node_claim_photos (CHECKs mirror PhotoFiles.Valid, FK ON DELETE CASCADE, 2 indexes) and node_antenna_claims.keep_photos; an AssertReady item (transient while the ingestor migrates) internal/dbschema/dbschema.go
Upload route: content-type and magic-byte sniffing, size and pixel caps checked before decode, decode semaphore of 2, re-encode, atomic inbox write, queue command cmd/server/station_photos.go, cmd/server/station_photo_image.go
Ingestor: re-check of the claim, the files (size, sha256, JPEG header, dimensions) and the caps; move inbox → store; insert as pending; approve with per-node eviction; reject; deletions on every claim transition; orphan sweep at every prune cmd/ingestor/station_photos.go, cmd/ingestor/antenna_claims.go
Public: GET /api/nodes/{pubkey}/photo/{id}.jpg?size=thumb|full (immutable cache) and photos on /station cmd/server/station_photos.go, cmd/server/antenna_claims.go
Owner: POST /api/antenna-claims/requests/{requestId}/photo and GET /api/antenna-claims/photos/{photoId}; "photo": "keep" on a claim same
Admin: GET /api/admin/antenna-claims/photos, GET …/photos/{photoId} (the image, no-store, key in a header), POST …/photos/{photoId}/approve|reject same
Operator config antennaClaims.photos.* (not the customizer, rule 8), docs, OpenAPI config.example.json, docs/user-guide/configuration.md, docs/user-guide/antenna-height-claims.md, docs/deployment.md, cmd/server/openapi.go

There is no frontend change. M6 builds the UI.

Decisions I made where the plan left a choice (smallest change that keeps existing behaviour)

  1. 3 approved photos per node (owner decision 14). Approving a 4th deletes the oldest approved photo in the same transaction. That is the plan's "replaced" deletion trigger. Each node can have 1 pending photo, and a new upload replaces it. [K][T]
  2. A photo can be approved only when its claim's details are approved and in force. Otherwise the server answers 409 and the ingestor refuses. So every approved photo belongs to the details that are shown, and the per-node cap counts only shown photos. [T]
  3. The photo list is on NodeStationResponse.photos, not on StationDetails. StationDetails is embedded in DetailsInput, so a field there would also become a claim input. [K]
  4. The upload command's request id is the photo id. The owner polls one id at GET /api/antenna-claims/photos/{id}. [T]
  5. "photo": "keep" (open question 12) is stored as keep_photos. When the claim is approved, the replaced claim's photos (pending and approved) move to it. Without keep, they are deleted. [T]
  6. No golang.org/x/image. Its kernel scalers allocate a dw × sh × [4]float64 temporary buffer: about 205 MB for a 16 MP source scaled to 1600 px. Instead, a small area-average resampler reads one source row at a time. So go.mod is unchanged and nothing is added to the module graph. [K][T]
  7. Decode budget: 4 bytes per allowed pixel (64 MB at 16 MP). It is estimated from the header before decoding: JPEG component planes, plus the int32 coefficients of a progressive JPEG and the CMYK conversion; PNG bytes per pixel by bit depth, doubled when interlaced. So a 16-bit or interlaced 16 MP PNG, or a progressive 4:4:4 16 MP JPEG, is refused at the header. Baseline JPEGs and 8-bit PNGs up to 16 MP pass. [T]
  8. Only JPEG EXIF orientation is applied. A PNG eXIf chunk is ignored and stripped. [T]
  9. Reject works while photos are off, so an administrator can always take a photo down. Approve and upload answer 403 while photos are off. [T]
  10. Photos default to on with detailsEnabled (owner decision 16). Only a canonical "enabled": false turns them off; a case variant is ignored, as for the other gates (Config: feature gates and the base-map token must only accept canonical key spellings #884). [T]

Requirements, tests and mutants

Each mutant was applied to a copy of the tree, the named tests were run, and the source was restored. KILLED means the tests went red. The tests are green on the branch [T]. On origin/master every new test fails to build, because the code they test does not exist there [K].

Security first

Requirement Test Mutant (all KILLED [T])
Decompression bombs and oversize refused before decode: a 30000² header-only JPEG, a 30000² PNG bomb, 8193 px a side, 4001×4000, a progressive 4:4:4 16 MP JPEG, a 16-bit 16 MP PNG, an interlaced 16 MP PNG, and a 0xFFFFFFFF PNG width are all refused while a decode counter stays at 0 TestStationPhoto1017M5_BombsRefusedBeforeDecode, …_ConfiguredPixelCap M19 pixel cap removed; M20 decode budget removed
Oversize body: Content-Length over the cap gives 413 without reading the body; a chunked body gives 413 through MaxBytesReader; neither reaches decode TestStationPhotos1017M5_UploadRefusals M25 Content-Length precheck removed
Content-type sniffing: the declared type must be image/jpeg or image/png and match the magic bytes; html, svg, gif and a png/jpeg swap give 415 TestStationPhotos1017M5_UploadRefusals, TestStationPhoto1017M5_Sniff M24 mismatch check weakened to "any image"
No path traversal: paths come only from a server-made 16-hex id and constant file names; the CHECK enforces photo_id shape; ../, %2f, %5c, upper case, .png, inbox and another node's id never serve a file …_Public404Identical, TestPhoto1017M5_ValidPhotoID, TestAntennaClaimPhotos1017M5_Checks M01 ValidPhotoID accepts longer ids; M37 bytes CHECK removed
Public 404 identical (status, Content-Type, Cache-Control, nosniff, body) across hidden, stale, pending, off, details off, claim not in force, files gone, unknown photo, another node's photo, bad size, bad pubkey TestStationPhotos1017M5_Public404Identical M28 stale check removed; M29 pending served; M30c photos switch ignored in the route and in nodePhotos
Ingestor trusts neither the queue nor the inbox: hash, size, dimensions, JPEG type and symlinks re-checked TestPhoto1017M5_SubmitRefusals M16 sha256 check removed

M5 row of the plan

Requirement Test Mutant (all KILLED [T])
EXIF, XMP, GPS and comment fixtures come out without metadata (only DQT, SOF0, DHT and SOS markers) TestStationPhoto1017M5_StripsMetadataAndAppliesOrientation, …_PNGChunksStripped M22 the input's Exif APP1 is spliced into the output
Orientation applied: orientation 6 turns 200×100 into an upright 100×200; all 8 orientations map exactly same, plus …_OrientAllEight, …_ExifOrientationParse M21 orientation ignored
Transparent PNG pixels composed onto white …_TransparentPNGOnWhite M39 every source treated as opaque
Never auto-approved, in all 4 combinations of autoApproveProven × autoApproveDetails TestPhoto1017M5_NeverAutoApproved M04 the photo is approved after submit when a switch is on
Each deletion trigger removes the row and the files: replaced pending, replaced approved (4th), photo rejected (pending and approved), claim revoked, claim rejected, details cleared (owner clear), superseded by newer details, pruned (cascade, then sweep); a height-only claim keeps them TestPhoto1017M5_DeletionTriggers M05 no delete on reject/revoke; M06 no delete on replace/clear; M08 no unlink; M09 cap off by one; M10 pending not replaced
photo: "keep" moves the photos; the files stay TestPhoto1017M5_KeepMovesPhotos, TestStationPhotos1017M5_ClaimKeepPhotos M07 keep ignored
The sweep heals a crash between commit and unlink (directory without a row), a crash between move and commit, a row without files (database restored alone), and stale inbox and .tmp- entries; it leaves foreign files alone; it drops photos of dead claims TestPhoto1017M5_SweepHeals, …_SweepDropsPhotosOfDeadClaims M11 dir pass off; M12 inbox TTL ×1000; M13 rows without files kept; M18 dead-claim pass off
Ingestor caps: 32 pending in all (the node's own pending photo does not count), 512 MiB stored TestPhoto1017M5_Caps M14 >= → >; M15 store cap removed
Approve only with servable details (ingestor and server) TestPhoto1017M5_ApproveNeedsServableClaim, TestStationPhotos1017M5_AdminApproveNeedsServableClaim M17 ingestor check off; M35 server check off
Upload gates: off, details off, weak key → 403; unknown or hidden → 404; pending, height-only, details not in force, rejected, outside the 7-day window → 409; proven inside the window → 202 TestStationPhotos1017M5_UploadGates M27 upload window ignored
Server writes only under inbox/: behaviour (the file tree diff after an upload and after a refused one, no row written, raw upload never on disk, mode 0700) and source (an AST scan: every file-writing os call in station_photo*.go sits in the 3 inbox writers; no other file names the photo store) TestStationPhotos1017M5_UploadWritesOnlyTheInbox, …_QueueFullLeavesNothing, TestServerPhotoWritesOnlyInbox M32 files written to the store root; M33 a full queue removes the wrong path; M33b an os.Chtimes in a reader
Read-only invariant extended: node_claim_photos joins the forbidden-write tables TestServerHasNoPacketTableWrites, …IsSensitive M34 table dropped from the pattern
Schema: CHECKs, cascade, idempotent migration, old rows unchanged, AssertReady transient before and permanent after internal/dbschema/antenna_claim_photos_test.go (4 tests) M37 bytes CHECK; M38 mustTable removed
Config: defaults, bounds, on by default, exact-key gate, example and guide rows photo_1017_m5_test.go (8 tests) M02 1 MiB total removed; M03 default off
Owner status route: queued, pending, error, gone, hidden TestStationPhotos1017M5_Status M42 hidden node's status shown
Admin routes: key required, list and filter, hidden node left out, image no-store, decisions queued TestStationPhotos1017M5_AdminRoutes M36 hidden filter off
/station lists approved photos only, and only while photos are on and the station is not stale TestStationPhotos1017M5_StationPhotosGate, …_PublicServesImmutable M40 photos not attached; M30b switch ignored in nodePhotos

Survivors, and what they changed [T]:

  • M30 (photos switch removed from the public route only) survives, and is equivalent. nodePhotos checks the switch again, so the route still answers 404. I kept the early check: it skips the node lookup while photos are off. M30b and M30c (the inner check removed, and both removed) are killed.
  • The first M33 (an extra write inside removePhotoInbox) survived. It exposed that the full-queue branch was untested. I added …_QueueFullLeavesNothing, and the redefined M33 is killed.
  • The first run of M41 (a full-size RGBA copy before scaling) survived under a 1.5 × 64 MB bound: it measured 94.0 MB, against 39.0 MB for the real code. I tightened the bound to the 64 MB decode budget, and M41 is now killed.

Perf (rule 0)

Requirement Test Mutant (all KILLED [T])
Decode semaphore at 2: two uploads held inside the decoder; a third answers 503 with Retry-After: 5 at once, never reaches the decoder and spends no per-IP budget; a freed slot is reused TestStationPhotos1017M5_DecodeSemaphoreAtTwo M23 constant 2 → 3; M23b channel capacity +1
16 MP worst case, time and peak heap: a 4000×4000 noise JPEG, just under the 8 MiB upload cap (7.2 MB) TestStationPhoto1017M5_16MPPeakHeap (bound 1.5 × the 64 MB budget), BenchmarkStationPhoto16MP M41 a full-size RGBA copy before scaling
Public route serves with an immutable cache: public, max-age=31536000, immutable, ETag, 304 on If-None-Match, nosniff TestStationPhotos1017M5_PublicServesImmutable M31 Cache-Control no-store
Per-IP budget refunded on every refusal TestStationPhotos1017M5_UploadRefusals M26 refund removed

Measured on the test machine (4 vCPU, i7-1260P; [T]). The test machine is much slower than typical hardware: stdlib decode alone takes 3.5 s [A].

Step, 16 MP noise JPEG (7.2 MB) Time
stdlib jpeg.Decode 3.5 s
scaleDown to 1600 px 5.0 s → 1.55 s (opaque sources skip the white fill; branch-free inner loop)
thumbnail 1600 → 480 0.67 s → 0.11 s
orient + 2 × encode 0.08 s + 0.9 s
Peak live-heap growth 39.6 MB (test); 49.9 MB (benchmark, with EXIF orientation 6)
  • With 2 slots, the worst case is about 2 × (8 MiB body + 50 MB), roughly 116 MB, well inside the planned 2 × 64 MB decode budget. [T][K]
  • A refused bomb costs one header walk: no decode, no allocation of the frame. [T]
  • A slow uploader holds a slot at most for the server's ReadTimeout (30 s, cmd/server/main.go). [K]
  • The public route is O(1): one snapshot lookup by public key, then a scan of at most 10 ids (maxApprovedPerNode ≤ 10), then one file open.
  • The snapshot is one indexed SELECT every 30 s, at most 65536 × 10 rows. [K]
  • The sweep is O(photo rows + store entries) once per prune (hourly). [K]

Suites run here

Command Result
cd internal/channelregistry && go test ./... ok [T]
cd internal/dbschema && go test ./... ok [T]
cd cmd/ingestor && go test -timeout 60m ./... ok, 1461 s [T]. CI uses -timeout 20m; the first run here hit the default 10 min on the test machine.
cd cmd/server && go test -timeout 90m ./... 6 failures, measured before the last test edits; the targeted re-run after them is green [T]. 1 failure was mine: TestAntennaClaims898_NoPerPartDecisionRoute pinned the routes under /api/admin/antenna-claims/. I updated it on purpose: it still pins exactly the 3 claim decision routes, and now also pins the 4 photo routes separately. It is green [T]. 5 failures are wall-clock perf budgets: TestAdvertIntervalAnalytics_AggregatePerf, TestDagiAreaStatsWithinBudget, TestProfileCard_Cost, TestCoverage941_PerfBudget, TestCoverage941M2_PerfBudget. They fail identically on origin/master b7db1738 on the test machine, run isolated [T]. None of them touches photo code.
node scripts/run-go-server-shard.js --validate 4132 runnable entries … (15 / 15 / 4102); the new tests run in the catch-all shard [T]
sh test-all.sh 396 of 408 files pass. The 12 failures are wall-clock perf budgets (test-live-heard-filter.js, test-live-scope-color.js, test-issue-724/728/730/941-…, test-1055-live-dagi.js, test-1055-m3-area-rule.js, test-dagi-filter.js, test-issue-598-hop-path-inference.js), plus test-channel-proposals.js (51.2 ms against a 50 ms budget) and test-backup-sqlite-safety.js, under load. Run alone, those last two pass. 9 of the remaining 10 fail the same way on origin/master; test-dagi-filter.js passed there once and failed here once, so it is unstable at its budget. This branch changes no file under public/ and no test-*.js [T].
node test-frontend-helpers.js 746 passed, 0 failed [T]
bash scripts/check-xss-sinks.sh --diff origin/master clean: there are no public/ changes [T]
map[string]interface{} added outside tests 0 [T]
Fork guards unchanged: 9 in deploy.yml, 1 in release-fast-path.yml; .github/ is not touched [T]
Local server and ingestor on a copy of e2e-fixture.db 13/13 [T]. This was a scratch script, not committed, using the fake-broker pattern of test-channel-proposals-e2e.js. The ingestor migrates the fixture (antenna_claim_photos_v1) and the server passes AssertReady. photosEnabled is true by default. The script inserts the node and an approved details claim as fixtures. Then: upload 202 → the ingestor moves inbox → store as pending → public 404 → the admin list requires the key and lists the photo; the image is served no-store → approve → /station lists it → the public thumbnail answers 200 image/jpeg, immutable, nosniff, with no Exif and no tEXt → reject → row and files gone → public 404. Both processes were stopped afterwards.
E2E (Playwright) none affected: no frontend change in M5 [K]

CI per job

What I expect per CI job:

  • Go unit tests (ingestor, internal packages): green, as here. [A]
  • Go server shards 1–3: green. The perf budgets that fail on the test machine pass on CI's runners for origin/master today. [A]
  • Frontend unit, E2E, XSS preflight: unaffected, because nothing under public/ changes. [A]

Rest (follow-ups, not in M5)

  • M6 (UI):
    • owner upload with canvas downscale and preview;
    • admin review with the checklist and blob fetch;
    • node-page thumbnail;
    • Playwright at 375×560.
  • Caches after a rejection. The immutable cache is the plan's choice (§8.7). A rejection removes the photo from this site, but not from a browser or CDN that already holds it. This is documented in configuration.md and in the owner guide.
  • Owner self-delete of an approved photo. There is no owner route. An owner removes photos by clearing or replacing the details, or by asking an administrator. Not in the plan.
  • PNG eXIf orientation is not applied (decision 8).
  • Time on slow hardware. On the test machine a 16 MP upload takes about 6 s, of which 3.5 s is stdlib decode. The client downscale to 2048 px in M6 cuts that to well under a second. [A]
  • M3 review nits 1 and 3 stay with M4, as planned (not touched here).

🤖 Generated with Claude Code

Owners add photos of the installation to a claim that sets station
details, within the upload window after its proof. A photo is never
approved automatically, whatever the switches say.

- Server (read-only for SQLite, Kpa-clawbot#1283): POST
  /api/antenna-claims/requests/{requestId}/photo sniffs the type, refuses
  oversize bodies and headers that would decode too large before any
  decode, decodes in at most 2 slots, re-encodes without metadata and
  upright, and writes only station-photos/inbox/. Owner status, public
  photo route (immutable cache, one 404 for hidden, stale, pending and
  off), admin list, image and decisions; /station lists approved photos.
- Ingestor: node_claim_photos (migration antenna_claim_photos_v1 with
  keep_photos), re-check of claim, files and caps, inbox move, approve
  with per-node eviction, reject, deletion on every claim transition,
  orphan sweep at every prune.
- Operator config antennaClaims.photos.*, docs, OpenAPI. The read-only
  invariant forbids writes to node_claim_photos and pins the server's
  file writes to the inbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dborup

dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Review — CS-Minimax PR#1100 — head bc66757

Dom: REQUEST CHANGES

This is an independent, read-only review. The design follows the revised M0 plan (§8, §10 M5 row) and the owner decisions (3 approved photos, photos on by default). The tests are thorough: my 5 mutants were all killed, and the real binaries pass 27/27 in my own end-to-end smoke. One finding breaks a security invariant the PR claims. It is a small fix, but it must come with a test, so the verdict is REQUEST CHANGES.

Evidence labels: [T] I ran it. [K] I read it in the code, the docs or the issue. [A] I assume it and did not verify it.

Findings

# Severity Where Finding
F1 Important (must fix) cmd/server/station_photo_image.go probeJPEG/jpegFrame An RGB-coded JPEG decodes to about 1.6× the decode budget, even though the probe passed it. Go's decoder converts a 3-component JPEG to a full *image.RGBA after it has decoded the planes, when isRGB() is true: there is no JFIF APP0, and either the Adobe APP14 transform is 0 or the component ids are 'R','G','B' ($GOROOT/src/image/jpeg/reader.go, isRGB/convertToRGB) [K]. jpegFrame counts only the planes. I took the PR's own noisy16MP fixture (4:2:0) and changed the component ids to R,G,B. Result: probe estimate 24.0 MB, so it is accepted under the 64 MB budget. Decode alone peaks at 88.3 MB, and reencodePhoto peaks at 100.5 MB of live heap [T]. For a 4:4:4 RGB frame at 16 MP, the arithmetic gives 48 MB of planes + 64 MB of RGBA ≈ 112 MB before scaling [K]. With 2 slots that is about 200–250 MB, against the ~128 MB the plan and the PR description promise. Any holder of a proven claim can craft such a file, and no test covers it (TestStationPhoto1017M5_BombsRefusedBeforeDecode has no RGB case). Fix: in probeJPEG, record whether a JFIF APP0 was seen and the Adobe APP14 transform. In jpegFrame, read the component ids. When nc == 3 and Go's isRGB rule holds, add 4*w*h. Add the RGB case (ids R,G,B, and also Adobe transform 0) to the before-decode bomb table, plus a peak-heap assertion.
N1 nit antennaclaim.PhotoLiveSQL, sweepPhotoRows Pending photos do not expire with the upload window. Plan §8.6 says "Pending photos expire with the 7-day window and the 24 h inbox rule". The sweep keeps a pending photo for as long as its claim is live: a proven claim lasts until retention prunes it (created_at < cutoff, retentionDays default 30), and an approved, in-force claim keeps it forever [K]. Such photos count against the global cap of 32 pending. The admin can reject them, so this is not a blocker. Either fix the code or state the deviation in the PR and the docs.
N2 nit handleStationPhotoUpload The per-IP budget is refunded on every refusal, including refusals after a full decode (errPhotoDetailed and errPhotoUnread from reencodePhoto). A claim holder can repeat expensive uploads that end in a refusal and never spend budget; only the 2 slots bound the cost, and those uploads also push legitimate ones into 503 [K]. Suggest refunding only for refusals before decode. This is bounded and needs a valid claim id.
N3 nit jpegFrame (progressive) A progressive 4:2:0 JPEG above about 8.5 MP is refused (for example 12 MP: 18 M samples × 5 = 90 MB > 64 MB) [K]. The refusal is 413 with "at most the configured megapixels and 8192 px a side", which is misleading for a 12 MP photo. Suggest a separate message, such as "save it as a baseline JPEG or smaller". This matters less once the M6 client downscale exists.
N4 nit visiblePhoto → handleAdminStationPhotoDecision "Reject always works" is not quite true: an administrator cannot reject (or view) a photo once its node is hidden, because the route answers 404 [K]. Nothing is served publicly in that state, but the files stay until the claim changes. Document this, or let reject skip the hidden check.

No other findings. Upload gates, stripping, orientation, traversal, never-auto-approve, the deletion triggers, the sweep, inbox-only writes, the read-only invariant, the identical 404, the immutable cache and the semaphore all check out (details below).

Answers to the checklist

  • Upload gates.
    • Photos off, details off or a weak key give 403: the gate is svc.enabled (strong key) → detailsEnabled → photos.init [K]. TestStationPhotos1017M5_UploadGates covers every case [T].
    • An unknown or hidden node gives 404 through visibleClaim [K][T].
    • A pending claim, a height-only claim, details not in force, a rejected claim, or a claim outside the 7-day window gives 409 [T]. My mutant MR3 (upload allowed when approved but details not in force) is killed by UploadGates/details_no_longer_in_force [T].
  • Re-encode strips EXIF, XMP and GPS, and applies orientation. exiftool was not available on the test machine, so I used my own fixtures, independent of the PR's helpers: big-endian MM Exif with the GPS IFD and an Artist tag, orientations 1/3/6/8, JFIF APP0, ICC APP2, Photoshop/IPTC APP13, XMP APP1 and COM. I inspected the outputs with my own Python marker walker. The outputs carry only DB C0 C4 DA (DQT, SOF0, DHT, SOS), and none of Exif, http://ns.adobe.com, xmpmeta, GPS, ICC_PROFILE, 8BIM, JFIF or my secret strings appear [T]. The pixel checks pass: orientation 6 gives 100×200 with red on top, 8 gives red at the bottom, 3 gives red on the right [T]. Through the real server, the stored full.jpg/thumb.jpg are clean in the same way [T].
  • Bombs and oversize refused before decode. The 30000² header-only JPEG, the PNG bomb, 8193 px a side, the 16-bit and interlaced PNGs and the progressive 4:4:4 JPEG are all refused with the decode counter at 0 [T, PR test]. My mutant MR5 (progressive not detected) is killed [T]. A 9 MiB body gives 413 on the real server [T]. Gap: F1.
  • Content sniffing. A PNG declared with a JPEG body, a GIF, and an SVG declared as image/jpeg all give 415 on the real server [T].
  • No path traversal. Every path comes from ValidPhotoID (exactly 16 lowercase hex characters) and two constant file names, and the store CHECK on photo_id enforces the same shape [K]. On the real server, ..%2f..%2fmeshcore.db, inbox.jpg, an upper-case id and ?size=../full each give exactly the unknown-node 404 [T]. openStoredPhoto and the ingestor's readBounded refuse symlinks [K].
  • Photos are never approved automatically. TestPhoto1017M5_NeverAutoApproved covers all 4 combinations of the switches [T]. On the real stack, with autoApproveProven and autoApproveDetails both true, the upload lands as pending [T].
  • Reject works while photos are off. rejectPhoto has no p.on check, and the server's reject has no enabled check [K][T]. Caveat: N4.
  • Deletion triggers remove the row and the files. TestPhoto1017M5_DeletionTriggers covers replaced pending, the 4th approved photo, reject, revoke, claim reject, clear, supersede and prune [T]. My mutant MR1 (the eviction order reversed, so the newest photo is evicted) is killed [T]. On the real stack, a reject removes the row and the directory [T].
  • The orphan sweep heals a crash between commit and unlink. TestPhoto1017M5_SweepHeals [T]. The sweep runs in the same goroutine as RunOnce (antennaClaimRunner.Start), so it cannot race a submit's rename-then-commit [K].
  • The server writes only under inbox/, and the read-only invariant is extended. The AST scan TestServerPhotoWritesOnlyInbox passes, and the behaviour test diffs the file tree [T]. On the real stack the new paths after an upload were station-photos/inbox/ (0700) plus what the ingestor moved and wrote [T]. node_claim_photos is in txTableWritePattern, with sensitivity cases [K][T].
  • The public 404 is identical across hidden, stale, pending and off. TestStationPhotos1017M5_Public404Identical [T]. My mutant MR4 (the snapshot ignores details_in_force) is killed there [T]. On the real server, the pending 404 and the 404 after a reject equal the unknown-node 404 byte for byte, across status, Content-Type, Cache-Control, nosniff and body [T].
  • The public files have an immutable cache. On the real server: public, max-age=31536000, immutable, nosniff, image/jpeg; the bytes equal the stored thumb; If-None-Match gives 304 [T]. The admin image is no-store, and the admin list without the key gives 401 [T].
  • The decode semaphore is at 2. The constant is 2 [K], and TestStationPhotos1017M5_DecodeSemaphoreAtTwo passes [T].
  • 16 MP benchmark (Apple arm64, 12 cores): TestStationPhoto1017M5_16MPPeakHeap takes 501 ms with a peak heap growth of 37.9 MB, and the output is 953 KB + 34 KB. BenchmarkStationPhoto16MP gives 501 ms/op, 48.1 MB peak heap (with EXIF orientation 6) and 48.3 MB/op [T]. The RGB-coded variant gives a 100.5 MB peak (F1).
  • No new map[string]interface{} outside tests: 0 [T]. go.mod is unchanged [K].
  • Behaviour change beyond the purpose: none found. newIPRateLimiter delegates to newIPRateLimiterPer with the same interval and burst [K]. /station gains only an omitempty field, and /config gains photosEnabled [K].

Tests and mutants

Merged tree: git merge-tree --write-tree origin/master bc667578… = 3a8fa7a9, on origin/master 644576a6. I ran everything from a git archive export.

Command Result
cd cmd/ingestor && go test -count=1 ./... ok (150 s) [T]
cd cmd/server && go test -count=1 ./... ok (158 s), no failures. No perf budget failed on this machine, so I have none to name as failing on master as well [T]
internal/channelregistry, internal/dbschema go test ./... ok [T]
node scripts/run-go-server-shard.js --validate 4139 runnable entries, each in exactly one shard (15 / 15 / 4109) [T]
sh test-all.sh 407 / 409. The 2 failures are test-issue-628-vendor-gitattributes.js and test-issue-715-og-denmark.js. Both shell out to git (git check-attr, git ls-files) and fail identically on the origin/master export, because an archive has no .git [T]
node test-frontend-helpers.js 746 passed, 0 failed [T]
XSS sinks no public/ changes in the diff, so there is nothing to scan [T]
E2E against a local Go server on 13700 with e2e-fixture.db prepared as in CI (freshen, seed SQL, corescope-migrate, seeds 2073/199/245/122) test-e2e-playwright.js 156/159 (3 skipped), test-antenna-claims-e2e.js 11/11, test-issue-898-m2-e2e.js 22/22, test-issue-1017-m2-e2e.js 12/12 [T]
Real-stack smoke (my own script, not committed): real corescope-server on 13701 and real corescope-ingestor against a fake MQTT broker, on a copy of the migrated fixture with an approved details claim 27/27: the photo switch is on by default, 415 ×3, 202 with upright 100×200 dimensions, pending with both auto switches on, inbox → store move, clean markers, the pending 404 equal to the unknown 404, 4 traversal probes, admin 401/list/no-store, approve → /station → public 200 immutable/nosniff with the same bytes as stored, 304, reject → files and row gone → 404, a 9 MiB body → 413 [T]

Own mutants (each applied to a copy of head, then the PR's tests run, then restored and checked with cmp against git show):

Mutant Result
MR1: the ingestor evicts the newest approved photo instead of the oldest KILLED, DeletionTriggers/replaced_approved_beyond_the_per-node_cap [T]
MR2: the node's own pending photo counts against the global pending cap KILLED, Caps/pending_in_all [T]
MR3: upload allowed to an approved claim whose details are not in force KILLED, UploadGates/details_no_longer_in_force [T]
MR4: the public photo snapshot ignores details_in_force KILLED, Public404Identical ("claim not in force: 200") [T]
MR5: probeJPEG treats progressive frames as baseline KILLED, BombsRefusedBeforeDecode (progressive 4:4:4) [T]
Reviewer test TestReviewer1100_RGBJPEGBudget FAILS on head: an RGB-coded 16 MP JPEG peaks at 100.5 MB against the 64 MB budget (F1) [T]

Red before, green after: every new test references code that does not exist on origin/master, so it fails to build there [K]. All of them are green on head and on the merged tree [T].

Hygiene: commit author is the required one (dborup) [T]; fork guards 9 in deploy.yml and 1 in release-fast-path.yml, unchanged [T]; no closing keywords in the commit or the PR [T]; no hardcoded theme colours (the only colour is the white JPEG background, as pixel data) [K]. Head was bc667578 in git ls-remote before and after the review [T].

CI per job (run 46970174645, head bc66757)

All jobs green [T]:

Job Result
Verify Go Test Assignments pass (1m38s)
Go Build & Test pass (52s)
Go Ingestor Tests pass (4m45s)
Go Libraries & CLI pass (8m0s)
Go Server Tests 1/3, 2/3, 3/3 pass (14m34s, 14m4s, 17m32s)
JavaScript Unit Tests & Lint pass (3m37s)
Script & Container Unit Checks pass (1m16s)
Validate Docker Image pass (1m0s)
Playwright E2E 1/3, 2/3, 3/3 pass (41m0s, 47m45s, 46m20s)
Verify E2E Shards & Coverage pass (27s)
Build & Publish Docker Image pass (10s)
Release Artifacts, Publish Badges, Deploy Staging skipped (PR run)

The known flakes (#256 Hash Stats sort, #267 backfill write-hold) did not occur.

What I did not verify

  • exiftool itself. It is not installed on the test machine and I did not install it. I inspected stripping with my own marker parser, byte searches and decode-based pixel checks instead.
  • Real phone photos (HEIC converted to JPEG, MPF/APP2 multi-picture JPEGs from phones). I used only synthetic fixtures.
  • A 4:4:4 RGB 16 MP JPEG. Go's encoder cannot produce one, so F1's 112 MB figure for 4:4:4 is arithmetic [K]. The 4:2:0 figure was measured [T].
  • Server and ingestor under different OS users. The server creates station-photos/ and inbox/ with mode 0700, and the ingestor must be able to rename out of them. I assume both run as the same user, as in the Docker image [A].
  • Mobile and UI flow: not applicable, since M5 changes nothing under public/. The 375×560 check belongs to M6.
  • Slow hardware timing. The author's figure of about 6 s on a 4 vCPU i7 was not reproduced; I measured 0.5 s on Apple arm64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant