Skip to content

fix(media): case-sensitive Content-Type checks bypass header extension and image-header safety rules#111184

Merged
steipete merged 2 commits into
openclaw:mainfrom
YangManBOBO:fix/media-store-case-sensitive
Jul 20, 2026
Merged

fix(media): case-sensitive Content-Type checks bypass header extension and image-header safety rules#111184
steipete merged 2 commits into
openclaw:mainfrom
YangManBOBO:fix/media-store-case-sensitive

Conversation

@YangManBOBO

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where mixed-case HTTP Content-Type headers such as IMAGE/PNG or Application/Zip bypass the media store's header-extension safety rules. RFC 9110 defines Content-Type as case-insensitive, but the store's helper functions used normalizeOptionalString (trim-only) instead of normalizeMimeType (lowercase), so case-mismatched values skipped the exclusion gates and produced inconsistent extensions.

Two concrete divergences from pinned behavior:

  • isImageHeaderMime(IMAGE/PNG) returns false — the image-header detection fails and a trusted header .png extension is kept for a generic ZIP container, whereas the lowercase equivalent is pinned to .zip by an existing test.
  • extensionForAuthoritativeHeaderMime(Application/Zip) returns .zip instead of skipping — the ZIP exclusion at line 253 misses because the string comparison is case-sensitive.

Why This Change Was Made

Both extensionForAuthoritativeHeaderMime and isImageHeaderMime now use normalizeMimeType instead of normalizeOptionalString(contentType?.split(";")[0]). normalizeMimeType lowercases, strips parameters, and folds APNG to PNG — exactly the same normalizer used by detectMime, extensionForMime, and the rest of the media-core MIME pipeline. The fix adds one import and changes two call sites.

User Impact

Mixed-case Content-Type headers (rare but valid per RFC 9110) produce the same safe extensions and header decisions as their lowercase equivalents. No config, schema, storage format, or dependency changes.

Evidence

Live behavior proof (before/after)

Before (current main) — mixed-case Application/Zip bypasses the ZIP exclusion and produces the wrong extension:

FAIl  media store > detects docx from mixed-case application/zip header via buffer sniffing

After (this patch) — both mixed-case tests pass identically to their lowercase counterparts:

✓ media store > does not preserve image header extensions for mixed-case header mime
✓ media store > detects docx from mixed-case application/zip header via buffer sniffing

Regression coverage

  • src/media/store.test.ts (2 new): IMAGE/PNG + ZIP bytes → correctly rejected as image header → .zip extension; Application/Zip + ZIP bytes + .docx filename → correctly excluded as ZIP header → .docx extension.
  • Against unfixed main, the Application/Zip test fails (ZIP exclusion missed → .zip extension returned instead of .docx). The 48 existing tests pass unchanged.
  • node scripts/run-vitest.mjs src/media/store.test.ts → 48 passed (+ 2 new).
  • Scoped oxlint and oxfmt pass on the two changed files.

Sibling-surface context

The two helpers changed are the only call sites in src/media/store.ts that parse Content-Type without lowercasing. The three callers — saveMediaBuffer, saveMediaStream, and saveMediaSource — all pass the raw content type through these helpers; no other file reads Content-Type in this module. The broader MIME pipeline in packages/media-core already lowercases via normalizeMimeType at entry (the detectMime flow called at lines 495-498 calls normalizeMimeType itself).

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 20, 2026, 12:47 AM ET / 04:47 UTC.

Summary
The branch replaces trim-only Content-Type parsing with canonical MIME normalization in media-store header decisions and updates two regression cases to use mixed-case MIME headers.

PR surface: Source -1, Tests 0. Total -1 across 2 files.

Reproducibility: yes. Current main's two trim-only helper calls leave Application/Zip and IMAGE/PNG unnormalized; the focused mixed-case cases in src/media/store.test.ts provide a high-confidence reproduction path without needing configuration or external services.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • [P2] No mechanical repair is indicated; the remaining action is normal maintainer merge review after the current exact-head required checks complete.

Security
Cleared: The two-file diff adds no dependency, workflow, permission, secret, package-resolution, or code-execution surface and tightens consistent MIME handling in an existing media-safety path.

Review details

Best possible solution:

Merge this narrow normalization fix after the current exact-head checks finish, keeping media-store header decisions on the established media-core MIME normalization contract.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main's two trim-only helper calls leave Application/Zip and IMAGE/PNG unnormalized; the focused mixed-case cases in src/media/store.test.ts provide a high-confidence reproduction path without needing configuration or external services.

Is this the best way to solve the issue?

Yes. Reusing media-core's existing normalizeMimeType at the two raw-header decision points is the narrowest maintainable fix and avoids a competing MIME-normalization rule in the media store.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ce9e39319640.

Label changes

Label justifications:

  • P2: This is a bounded media filename-safety correctness fix for uncommon but standards-valid mixed-case HTTP headers, with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes direct before/after terminal output for the changed media-store behavior and identifies the focused regression cases; no sensitive runtime data is shown.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes direct before/after terminal output for the changed media-store behavior and identifies the focused regression cases; no sensitive runtime data is shown.
Evidence reviewed

PR surface:

Source -1, Tests 0. Total -1 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 4 -1
Tests 1 4 4 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 7 8 -1

What I checked:

  • Current-main behavior: Current main uses normalizeOptionalString(contentType?.split("; ")[0]) at the authoritative-header extension and image-header checks, leaving MIME comparison case-sensitive at both decision points. (src/media/store.ts:245, ce9e39319640)
  • Canonical MIME contract: normalizeMimeType strips parameters, trims, lowercases, and is already used by detectMime and extensionForMime, so routing the two header decisions through it keeps the media-store path consistent with the rest of media-core. (packages/media-core/src/mime.ts:2, ce9e39319640)
  • Caller and sibling-path coverage: saveMediaBuffer and saveMediaStream both compute headerExt through extensionForAuthoritativeHeaderMime, then call detectMime and resolveSavedMediaExtension; the changed image-header predicate is consumed by resolveSavedMediaExtension before the stored filename is built. (src/media/store.ts:260, ce9e39319640)
  • Focused regression cases: The PR-head tests exercise Application/Zip through saveMediaStream and IMAGE/PNG with ZIP bytes through the image-header safeguard, covering the two changed functions and their distinct extension decisions. (src/media/store.test.ts:458, 1070f1032ba3)
  • Patch provenance: The behavioral normalization was introduced by ccb6195; the current head includes steipete's follow-up test consolidation commit 1070f10. (src/media/store.ts:245, 1070f1032ba3)
  • Real behavior proof: The PR body provides copied before/after terminal output for the mixed-case ZIP failure on unfixed main and passing mixed-case ZIP/image-header cases after the patch, plus a focused media-store test run. (src/media/store.test.ts:458, 1070f1032ba3)

Likely related people:

  • steipete: Authored the current-head follow-up that consolidates the MIME case regression coverage, connecting them to the reviewed media-store behavior on the branch. (role: recent area contributor; confidence: medium; commits: 1070f1032ba3; files: src/media/store.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-19T04:03:55.546Z sha ccb6195 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-19T04:46:27.015Z sha ccb6195 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 1508a58 into openclaw:main Jul 20, 2026
117 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 20, 2026
…n and image-header safety rules (openclaw#111184)

* fix(media): normalize Content-Type casing in header extension and image-header checks

* test(media): consolidate MIME case coverage

Co-authored-by: 潘晓波0668000512 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants