GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): reject image uploads declared with the wrong media type by liwenjie200543 · Pull Request #44903 · pingdotgg/t3code

Conversation

@liwenjie200543

@liwenjie200543 liwenjie200543 commented Nov 28, 2026

Copy link
Copy Markdown

Fixes #44885

What the bug is

storeAttachmentUpload takes the stored extension and the media type from what the client declared when it asked for the upload URL (claims.mimeType), and never looks at the bytes. A PNG posted as image/jpeg is stored as <id>.jpg and later sent to Claude with media_type: "image/jpeg" (ClaudeAdapterV2.ts:3635), so Anthropic answers 400. The attachment stays in the thread history, and every later turn replays it and fails the same way.

What changed

apps/server/src/imageMime.ts gains detectImageMimeType, which matches the signature of the first bytes for png, jpeg, gif and webp.

storeAttachmentUpload keeps the first 12 bytes while it streams to the .part file. When the declared type is an image, a signature is recognised, and it names a different type, the upload returns 400 with the real type and the file is never published; the existing cleanup removes the part file. Types without an unambiguous signature here (svg, tiff, heic, avif) keep the current behaviour, because there is nothing to compare against.

How I found it, and what I saw

The report in #44885 covers both the MCP attachments path and the composer. I traced the path in AttachmentUpload.ts and drove the real upload path — signed token, real filesystem, no mocks — with 14 PNG bytes declared as image/jpeg:

  • on ea481850 (main): storeAttachmentUpload returns { ok: true } and writes <attachmentId>.jpg;
  • with this change: the same call returns 400 Image bytes are image/png, but the upload was declared as image/jpeg. and neither the file nor a .part file is left in the attachments directory. The same bytes declared as image/png still store as <attachmentId>.png;
  • streamed bodies are covered too: the signature is checked across chunk boundaries (3-byte first chunk).

Verification

  • vp test run src/assets/AttachmentUpload.test.ts — 12 passed. Reverting the source change leaves 2 failed / 10 passed with expected { ok: true } to match object { ok: false, status: 400 } for the two new cases, so they fail on the bug rather than on the new code.
  • vp test run src/assets — 15 passed. AssetAccess.test.ts fails to load on this machine because remark-cjk-friendly is missing from my install; unrelated to this diff.
  • vp fmt --check on the three files — clean.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@liwenjie200543
fix(server): reject image uploads declared with the wrong media type
5b86a25
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 28, 2026
@juliusmarminge

juliusmarminge commented Nov 28, 2026

Copy link
Copy Markdown
Member

Thanks for this. #44902 makes the same change and is the one being kept.

#44902 addresses the same media-type failure by sending images with the type detected from their bytes. It also corrects images already in Pi's conversation history, allowing affected threads to recover; this change only prevents new mismatched uploads.

Your upload-time rejection and streamed-body coverage are useful, but the provider-side correction is the more complete fix for the reported problem. Any additional upload validation can build on its shared signature detector.

Closing as a duplicate.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@juliusmarminge juliusmarminge closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug]: Image attachment media type is trusted as declared; PNG sent as image/jpeg makes every turn fail with 400

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@liwenjie200543 @juliusmarminge
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.