Skip to content

id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document #7823

Closed

Description

@dezren39

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; in uploadImageFile() is a bare cast; any 200 body is resolved as a well-formed { hash: string; name: string; url: string } with no validation. The !response.ok guard at :104 only 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 with src: outcome.result.url and alt: outcome.result.name || fileName. With a wrong-shape body, result.url is undefined, so a src-less image node is inserted into the real document and dispatched. With a null body, result.url throws a raw TypeError inside the insertion try, which the catch at :320-328 reports 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 with src: 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 attrs src="/blob/abc123?filename=cat.png", alt="cat.png" — OK
  • null body: RESOLVES null (not rejected) → caller deref throws TypeError: null is not an object (evaluating 'result.url'), caught and misreported as "Insertion failed"
  • {} body: resolves {} → image node created with src=undefined
  • "abc" body: resolves "abc" → image node created with src=undefined
  • [] body: resolves [] → image node created with src=undefined
  • {hash:42, name:null, url:123}: resolves → image node created with src=123
  • {hash:"abc123", name:"cat.png"} (missing url): resolves → image node created with src=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/upload 200 payload (null/non-object body, missing hash/name/url, or wrong-typed fields) makes uploadImageFile REJECT 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 uploadImageFile tests unchanged and green).
  • New regression tests in pkgs/id/web/src/image-upload.test.ts cover the malformed cases above and fail pre-fix.
  • Web suite + typecheck green.

Activity

  1. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor
  2. added
    source/creatorFiled by the new-issue-creator job
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    effort/sSmall: expected under 2 hours of work
    on Nov 8, 2026
  3. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 8, 2026
  5. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    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.

  6. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions