Title: id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document · Issue #7823 · developing-today/code · GitHub
Open Graph Title: id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document · Issue #7823 · developing-today/code
X Title: id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document · Issue #7823 · developing-today/code
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 misreporte...
Open Graph 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...
X 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...
Opengraph URL: https://github.com/developing-today/code/issues/7823
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document","articleBody":"## Problem\n\nid(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\".\n\n`pkgs/id/web/src/image-upload.ts`:\n\n- `: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.\n- `:277-283` — the caller (`handleImageUpload`) treats any resolution as success (`outcome.ok = true`); only a rejection takes the upload-failure path.\n- `: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.\n- A wrong-typed body is worse: `{ url: 123 }` inserts an image node with `src: 123`.\n\nThe 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).\n\n## Evidence (verified this run, laptop @ origin/main af4e603e89, image-upload.ts md5 41fa9f0a3ba46a56452fd5c3608fef75)\n\nProbe `~/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`):\n\n- 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\n- `null` body: RESOLVES `null` (not rejected) → caller deref throws `TypeError: null is not an object (evaluating 'result.url')`, caught and misreported as \"Insertion failed\"\n- `{}` body: resolves `{}` → image node created with `src=undefined`\n- `\"abc\"` body: resolves `\"abc\"` → image node created with `src=undefined`\n- `[]` body: resolves `[]` → image node created with `src=undefined`\n- `{hash:42, name:null, url:123}`: resolves → image node created with `src=123`\n- `{hash:\"abc123\", name:\"cat.png\"}` (missing `url`): resolves → image node created with `src=undefined`\n\nThe 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.\n\n## Why it matters\n\nPaste/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.\n\n## Acceptance criteria\n\n- [ ] 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.\n- [ ] 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.\n- [ ] Well-formed payloads behave exactly as today (existing `uploadImageFile` tests unchanged and green).\n- [ ] New regression tests in `pkgs/id/web/src/image-upload.test.ts` cover the malformed cases above and fail pre-fix.\n- [ ] Web suite + typecheck green.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-11-08T22:09:36Z","url":"https://github.com/developing-today/code/issues/7823"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:74542919-e1d2-9efe-6323-86c2494a2ff3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED94:2046A0:31F475:446A48:6B0763CE |
| html-safe-nonce | 6e962f85e4fecd4474a7493561750727a557fccbbe98e2372cdf4b801bb2ecf3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDk0OjIwNDZBMDozMUY0NzU6NDQ2QTQ4OjZCMDc2M0NFIiwidmlzaXRvcl9pZCI6IjM4MTAyMjYxNzMzOTM3MjQzNjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8fa0b1973d239ad644787eb1537a4f2ffa030682bcdc41e557eaa01b91ffefe3 |
| hovercard-subject-tag | issue:6276197290 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/7823/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab7b5485476cd477b6d8f4120cce5bfe12fa202afa06e758fa4aaf14ee3a5d6f/developing-today/code/issues/7823 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab7b5485476cd477b6d8f4120cce5bfe12fa202afa06e758fa4aaf14ee3a5d6f/developing-today/code/issues/7823 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7a557ecc960a3ae6e299fc66b0bc9132072f8860191648e6749fee5d3ff00d82 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bd845eb7947c1ed8c850f7ab415a51339d162de3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width