Repository navigation
Closed
Labels
app/idPackage/app: id (pkgs/ or apps/ in this repo)Package/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)Something isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)Ordinary priority (the default)source/creatorFiled by the new-issue-creator jobFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted testsQueue packet kind: bounded fix with reproduction and targeted tests
Description
Problem
POST /api/upload in pkgs/id's web server validates an uploaded image only by the multipart field's declared Content-Type — the bytes are never inspected. Any bytes at all are accepted, stored, and served as a genuine image of the declared type, as long as the client claims an allowed type.
Evidence (at origin/main 8bb1e43)
pkgs/id/src/web/routes.rs:1770-1780(upload_handler): the only type check isfield.content_type()(the client-supplied multipart header) againstALLOWED_IMAGE_TYPES. The handler then reads the bytes (field.bytes()), checks only size and non-emptiness, and stores them.- No magic-byte/format sniffing exists anywhere in
pkgs/id/src(no PNG/JPEG/GIF/WebP signature check). - The surrounding code documents the opposite premise:
reconcile_upload_filename(routes.rs:711-715) says a name is reconciled with "the type the upload was validated as" so it cannot "masquerade as a different type than the bytes were checked as" — but the bytes are never checked; only the claim is. The existing tests encode the gap:blob_png_is_served_inline_with_protective_headersuploads the literal bytesb"png-bytes"asimage/pngand expects success. - Verified by a laptop cargo probe test in the routes test harness (scan worktree at 8bb1e43, probe test since removed): HTML/script bytes (
<html><script>alert(1)</script></html>) uploaded with declared typeimage/pngand filenameevil.pngreturned 200 OK, were stored, and were served back from/blob/<hash>?filename=evil.pngwithContent-Type: image/png; plain-text bytes declaredimage/jpegwere likewise accepted with 200.
Why it matters
- The stored blob's filename extension, its stored content-type metadata tag, and the type it is served with all assert a format the content may not have. Every downstream consumer that trusts that metadata (the editor's image rendering, the file listing, any future thumbnail/transcode step) inherits the lie.
- The id(web): /blob serves any blob as text/html via the ?filename= parameter — no CSP/nosniff/disposition headers (same-origin XSS by link) #908 serving mitigations (allowlisted inline types,
nosniff, sandboxing CSP) limit the XSS blast radius of a mislabeled blob, but they were designed on the premise that animage/*blob is actually an image. A declared-image/svg+xmlupload, for example, need not be XML at all. - It is also a correctness bug independent of security: a corrupt or mislabeled "image" is accepted silently and only fails later, in the renderer, with no connection to the upload that caused it.
Acceptance criteria
upload_handlerverifies the bytes against the declared type before storing: magic signatures for PNG (89 50 4E 47…), JPEG (FF D8 FF), GIF (GIF87a/GIF89a), WebP (RIFF…WEBP), BMP (BM), ICO (00 00 01 00), and forimage/svg+xmla check that the content (after optional BOM/whitespace/XML prolog) is an<svgdocument.- A mismatch returns
400with a clear message naming the declared type and the detected mismatch; nothing is stored or tagged. - Existing upload tests are updated to use real minimal valid headers for each type instead of placeholder bytes (
b"png-bytes"), and new tests cover: HTML-as-PNG refused, text-as-JPEG refused, a valid-header upload of each allowed type accepted, SVG with prolog accepted, non-SVG-as-SVG refused. - Client behavior is unchanged for genuine images (the web client's
ALLOWED_IMAGE_TYPES/MAX_IMAGE_SIZEinweb/src/image-upload.tsstay in sync with the server constants).
Filed by new-issue-creator-code-b after verification this run; not a duplicate of #908 (serving-side headers, closed), #1549/#2363 (name collisions, closed), or #716 (body limit, closed) — no open issue covers byte-level validation of uploads.
Metadata
Metadata
Assignees
Labels
app/idPackage/app: id (pkgs/ or apps/ in this repo)Package/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)Something isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)Ordinary priority (the default)source/creatorFiled by the new-issue-creator jobFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted testsQueue packet kind: bounded fix with reproduction and targeted tests
Activity
dezren39 commentedon Nov 4, 2026
🤖 Agent note · state: filed
dezren39 commentedon Nov 4, 2026
🤖 Agent note · picked up
fix(id): accept legal SVG prolog constructs in the upload byte check (#…
fix(id): accept namespace-prefixed SVG roots in the upload byte check (…
fix(id): decode UTF-16 SVGs before the upload root check (#5342)
fix(id): scan the SVG DOCTYPE quote- and comment-aware (#5342)
Merge pull request #5357 from developing-today/queue/9330-5342-upload…
dezren39 commentedon Nov 4, 2026
🤖 Agent note · done
cargo test --features web --lib upload(pkgs/id) — 27 passed, 0 failed, re-run after every change round