Repository navigation
Description
Problem
id(web/image-upload): the image upload flow shape-trusts the /api/upload response — a wrong-shape 200 response silently inserts an image node with src: undefined (or a numeric src) into the document, and a null body is misreported as an insertion failure for an upload that "succeeded".
pkgs/id/web/src/image-upload.ts:
:109—return (await response.json()) as UploadResponse;inuploadImageFile()is a bare cast; any 200 body is resolved as a well-formed{ hash: string; name: string; url: string }with no validation. The!response.okguard at:104only covers non-200 statuses.:277-283— the caller (handleImageUpload) treats any resolution as success (outcome.ok = true); only a rejection takes the upload-failure path.:312-315— on "success" the caller creates the image node withsrc: outcome.result.urlandalt: outcome.result.name || fileName. With a wrong-shape body,result.urlisundefined, so a src-less image node is inserted into the real document and dispatched. With anullbody,result.urlthrows a rawTypeErrorinside the insertiontry, which the catch at:320-328reports as "Insertion failed" — the wrong diagnosis (the upload response was malformed; nothing about the document insertion was at fault), and the placeholder is removed with no accurate feedback anywhere.- A wrong-typed body is worse:
{ url: 123 }inserts an image node withsrc: 123.
The server contract is three required strings (pkgs/id/src/web/routes.rs:1564 UploadResponse { hash: String, name: String, url: String }, returned at :2226), so a wrong-shape 200 requires deploy skew, a proxy/error envelope with a 200, or a future contract change — exactly the boundary this cast refuses to check. Siblings: #7812 (image-browser /api/images, same src-less-insert outcome via a different module), #7811 (home feed).
Evidence (verified this run, laptop @ origin/main af4e603, image-upload.ts md5 41fa9f0a3ba46a56452fd5c3608fef75)
Probe ~/git/fleet/probe-upload-shape/probe.ts (bun, real module imported from a clean git archive origin/main snapshot at ~/git/fleet/probe-main-c, fetch stubbed per case; caller effect mirrors image-upload.ts:312-315):
- control (well-formed
{hash:"abc123", name:"cat.png", url:"/blob/abc123?filename=cat.png"}): resolves the object — image node attrssrc="/blob/abc123?filename=cat.png",alt="cat.png"— OK nullbody: RESOLVESnull(not rejected) → caller deref throwsTypeError: null is not an object (evaluating 'result.url'), caught and misreported as "Insertion failed"{}body: resolves{}→ image node created withsrc=undefined"abc"body: resolves"abc"→ image node created withsrc=undefined[]body: resolves[]→ image node created withsrc=undefined{hash:42, name:null, url:123}: resolves → image node created withsrc=123{hash:"abc123", name:"cat.png"}(missingurl): resolves → image node created withsrc=undefined
The existing tests (pkgs/id/web/src/image-upload.test.ts, uploadImageFile describe at :231) mock only the well-formed success body, a non-ok response, and a network error — no malformed-200 cases.
Why it matters
Paste/drop image upload is a primary editing path. The upload itself succeeded server-side (the blob is stored), so a wrong-shape response today either corrupts the document with a broken src-less image node that then gets saved, or misdiagnoses the failure as an insertion problem — making the real contract break undebuggable from user reports. Failing closed is cheap: validate the shape at the fetch boundary and let the existing upload-failure path (warn + placeholder removal, :279-282) handle it.
Acceptance criteria
- A malformed
/api/upload200 payload (null/non-object body, missinghash/name/url, or wrong-typed fields) makesuploadImageFileREJECT with a clear upload error — it never resolves a malformed value. - On a malformed payload, no image node is inserted, and the failure is reported through the existing upload-failure path ("Upload failed for …"), never as "Insertion failed" and never as a raw TypeError.
- Well-formed payloads behave exactly as today (existing
uploadImageFiletests unchanged and green). - New regression tests in
pkgs/id/web/src/image-upload.test.tscover the malformed cases above and fail pre-fix. - Web suite + typecheck green.
Activity
developing-today commentedon Nov 8, 2026
CODE-2328
dezren39 commentedon Nov 8, 2026
🤖 Agent note · filed
developing-today commentedon Nov 8, 2026
Lane code-m picked up task 14000 (small_fix, issue #7823, direct lane). Issue #7823 revalidated fresh: OPEN, no hard-stop labels. Branch queue/14000-7823-upload-shape-validation created on the laptop (worktree ~/git/fleet/14000-7823-upload-shape, base origin/main 6b94b29). Implementing: validate the /api/upload payload (object with string hash/name/url) at the fetch boundary in uploadImageFile, reject malformed payloads with a clear upload error, plus regression tests in image-upload.test.ts.
fix(id/web): validate /api/upload response shape before inserting (#7823
developing-today commentedon Nov 8, 2026
Lane code-m completed task 14000 (small_fix, issue #7823): PR #7827 merged as fb84378 (squash), closing this issue. Fix: parseUploadResponse() validates the /api/upload payload at the fetch boundary in uploadImageFile (object with string hash/name/url); malformed payloads now reject with a clear upload error through the existing upload-failure path — no image node inserted, no misreported Insertion failed. Verification: image-upload tests 58/58 pass (9 new malformed-payload regression tests all fail pre-fix, 49 pass); typecheck pass; full web suite 678 pass with 1 pre-existing search-panel failure proven on clean main. Codex: no findings posted on PR #7827 after repeated checks. Remaining PR checks were still queued at merge time (fleet CI stall); merge was made under the standing verified-merge criteria. Claim labels removed.