Skip to content

fix(media-core): keep prototype-named Content-Type values out of MIME lookup tables - #144458

Closed
Finn763 wants to merge 1 commit into
openclaw:mainfrom
Finn763:fix/oc-143673-descr
Closed

Finn763 wants to merge 1 commit into
openclaw:mainfrom
Finn763:fix/oc-143673-descr

Conversation

@Finn763

@Finn763 Finn763 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #143673

What Problem This Solves

A remote sender controls a media response's Content-Type header, and that raw value flows
into the MIME normalization tables in packages/media-core/src/mime.ts. Both value-returning
tables were plain object literals indexed with the untrusted string:

return MIME_SYNONYMS[cleaned] ?? cleaned;   // normalizeMimeType
return EXT_BY_MIME[normalized];             // extensionForMime

So a header value that happens to name an Object.prototype member resolved to the inherited
member instead of a string:

  • Content-Type: __proto__ -> normalizeMimeType returned [object Object]
  • Content-Type: constructor -> normalizeMimeType returned Object (a function)

Every consumer that then treats the result as a string crashed deterministically:
store.ts isImageHeaderMime (TypeError: ... .startsWith is not a function),
mediaKindFromMime (TypeError: mime.startsWith is not a function), and the remote fetch
path where extensionForMime is called for an extensionless filename
(src/media/fetch.ts). One hostile header killed that media operation on every trigger
across web fetch, channel attachments, and file.fetch payloads.

Evidence

Real run against the unpatched source, driving the same functions the production callers use
(normalizeMimeType, extensionForMime, kindFromMime, detectMime, plus the
store.ts:isImageHeaderMime shape normalizeMimeType(ct)?.startsWith("image/")):

node --import ./scripts/tsx.mjs <repro>.mts

Before the patch:

Content-Type: "__proto__"
  normalizeMimeType -> [object] [object Object]
  isImageHeaderMime THREW TypeError: normalizeMimeType(...)?.startsWith is not a function
  extensionForMime -> [undefined] undefined
  kindFromMime THREW TypeError: mime.startsWith is not a function
  detectMime -> [object] [object Object]

Content-Type: "constructor"
  normalizeMimeType -> [function] function Object() { [native code] }
  isImageHeaderMime THREW TypeError: normalizeMimeType(...)?.startsWith is not a function
  kindFromMime THREW TypeError: mime.startsWith is not a function
  detectMime -> [function] function Object() { [native code] }

Content-Type: "text/html; charset=utf-8"
  normalizeMimeType -> "text/html"   extensionForMime -> ".html"   kindFromMime -> document
Content-Type: "image/png"
  normalizeMimeType -> "image/png"   extensionForMime -> ".png"    kindFromMime -> image

After the patch, the identical script:

Content-Type: "__proto__"
  normalizeMimeType -> [string] "__proto__"
  isImageHeaderMime -> false
  extensionForMime -> undefined
  kindFromMime -> undefined
  detectMime -> [string] "__proto__"

Content-Type: "constructor"
  normalizeMimeType -> [string] "constructor"
  isImageHeaderMime -> false
  extensionForMime -> undefined
  kindFromMime -> undefined
  detectMime -> [string] "constructor"

Content-Type: constructorxxxxxxxxxxxxx…(71691 chars)   -> plain unknown type, no throw
Content-Type: ""  /  "   "                             -> undefined, no throw

Known types are byte-for-byte identical to before (text/html -> .html/document,
image/png -> .png/image, application/pdf -> .pdf/document).

Regression tests, run through the repo's pnpm:

pnpm exec vitest run --config test/vitest/vitest.unit-fast.config.ts packages/media-core/src/mime.test.ts
  • Pre-fix (new tests in place): Tests 5 failed | 214 passed (219) — failures are the
    prototype-named cases returning [object Object] / Function Object.
  • Post-fix: Tests 219 passed (219).
  • Whole package project: pnpm exec vitest run --config test/vitest/vitest.unit-fast.config.ts packages/media-core/src
    -> Test Files 7 passed (7), Tests 325 passed (325).

Verification

  • Root cause, not symptom: git grep over the whole tree shows the only indexed lookup tables
    reached by an untrusted MIME string are MIME_SYNONYMS (via normalizeMimeType) and
    EXT_BY_MIME (via extensionForMime). Both are now own-key-only, so the roughly 100 call
    sites of those two helpers outside tests (across src/ and extensions/) get the string
    contract back. Two sibling tables need no guard
    and were left alone: MIME_BY_EXT is only keyed by a path extension (always "" or
    .something), and AMBIGUOUS_VIDEO_MIME_BY_AUDIO_MIME feeds a strict-equality comparison
    and never returns the looked-up value.
  • Two-way regression tests in packages/media-core/src/mime.test.ts: prototype-named values
    (__proto__, constructor, __defineGetter__, __lookupSetter__, toString, valueOf,
    hasOwnProperty, isPrototypeOf, propertyIsEnumerable), parameterized/empty/whitespace
    values, an oversized (64 KiB) value, detectMime header hints, and the known-type matrix
    (image/png, text/html, text/html; charset=utf-8, application/pdf, text/csv,
    text/plain, image/apng, plus .html/.txt/.csv/.pdf path mapping).
  • Sabotage checks: reverting only the normalizeMimeType guard -> 5 failed | 214 passed;
    reverting only the extensionForMime guard -> 5 failed | 214 passed (the lookup returns
    the inherited Object.prototype/Function, which is why both guards are required). Both
    files restored byte-identical (sha256 verified) after each revert.
  • pnpm exec oxfmt --check packages/media-core/src/mime.ts packages/media-core/src/mime.test.ts
    -> "All matched files use the correct format."
  • pnpm exec oxlint --config .oxlintrc.json packages/media-core/src/mime.ts packages/media-core/src/mime.test.ts
    -> exit 0, no findings.
  • No new dependency, no API/config change: two lookups are guarded with Object.hasOwn, the
    same pattern already used for alias tables (extensions/a2a/src/protocol.ts). Diff is
    2 files changed, 84 insertions(+), 2 deletions(-).

PR #144458 — real remote-media reader/storage entry proof (before/after)

Repo: openclaw/openclaw @ worktree D:/code/wt-oc-143673 (branch fix/oc-143673-descr)
HEAD (after): ca7576db80b6dd2da1119d7dc414c03f10109203 — "fix(media-core): keep prototype-named Content-Type values out of MIME tables"
Parent (before): 28589e76ead3876ef73c5675d0fce19f1bbf6e16
Host: Windows, git-bash, node v26.4.0, harness run through the repo's own tsx preload (node --import ./scripts/tsx.mjs).

Answer to the ClawSweeper request ("real behavior proof through the remote-media reader or storage
entrypoint; direct helper calls and a copied predicate do not demonstrate that production flow"):
both real entrypoints below are driven against a real local HTTP endpoint. No helper
(normalizeMimeType / extensionForMime / detectMime) is called by the harness at all.

What the PR changes (before → after)

packages/media-core/src/mime.ts is the only source file in the commit. A remote sender controls
Content-Type, and both lookup tables are plain object literals.

before (parent, lines 174–178):

  const cleaned = mime.split(";")[0]?.trim().toLowerCase();
  if (!cleaned) {
    return undefined;
  }
  return MIME_SYNONYMS[cleaned] ?? cleaned;      // "__proto__" -> Object.prototype (truthy, so ?? never fires)

after (HEAD, lines 175–181 + 291–299):

  return Object.hasOwn(MIME_SYNONYMS, cleaned) ? MIME_SYNONYMS[cleaned] : cleaned;
  ...
  return Object.hasOwn(EXT_BY_MIME, normalized) ? EXT_BY_MIME[normalized] : undefined;

So before the fix normalizeMimeType("__proto__") returned Object.prototype and
normalizeMimeType("constructor") returned the Object constructor — both typed string, neither a
string. The next string operation on the result (mime.split) throws TypeError: mime.split is not a function.

Real entrypoints driven (production callers, not helpers)

flow entrypoint source production callers
storage (URL → media store on disk) saveRemoteMedia() src/media/fetch.ts:667 extensions/slack/src/monitor/media.ts:126, extensions/telegram/src/bot/delivery.resolve-media.ts:350, extensions/discord/src/monitor/message-media.ts, extensions/msteams/src/attachments/remote-media.ts, extensions/sms/src/media.ts, extensions/tlon/src/monitor/media.ts, src/media/store.remote.runtime.ts:46 (saveRemoteMediaForStore) — 22 call sites in total
reader (URL → in-memory media result) loadWebMediaRaw() src/media/web-media.ts:1211 src/agents/tools/image-tool.ts, src/agents/tools/pdf-tool.ts, src/plugin-sdk/web-media.ts, discord/matrix/msteams/telegram/whatsapp extensions

The failing call chain the harness exercises (unchanged by the PR, only its input changes):
saveRemoteMedia → saveOkMediaResponse → saveMediaStream → extensionForAuthoritativeHeaderMime
(src/media/store.ts:376) → extensionForMime; and loadWebMediaRaw → readRemoteMediaBuffer →
detectMime header fallback (packages/media-core/src/mime.ts:287) → kindFromMime
(src/media/web-media.ts:1080).

Harness (outside the repo, re-runnable)

  • %LOCALAPPDATA%/Temp/ocproof-144458/prove.mts — starts a real node:http server on
    127.0.0.1:0 and serves three routes with the raw header values
    Content-Type: __proto__ (body PROTO-BODY), Content-Type: constructor (body CTOR-BODY) and a
    control Content-Type: image/png (a real 70-byte 1x1 PNG). Real TCP, real header bytes; the
    harness passes no fetchImpl, installs no interceptor and imports no @openclaw/media-core
    symbol — it only imports the two entry modules.
    Each case runs the storage entry and then the reader entry and prints the returned values, the
    bytes, and the media-store directory listing (OPENCLAW_STATE_DIR points the store at the proof
    workspace, so ~/.openclaw is not touched).
    Loopback is exempted from the SSRF guard with ssrfPolicy: { allowedHostnames: ["127.0.0.1"] } —
    the same knob production config uses for local gateways (buildTelegramMediaSsrfPolicy).
  • %LOCALAPPDATA%/Temp/ocproof-144458/run-both.sh — after run, then
    git checkout 28589e76ead3876ef73c5675d0fce19f1bbf6e16 -- packages/media-core/src/mime.ts
    (that one file, nothing else), before run, then git checkout HEAD -- the same file and prints the
    porcelain state.
cd /d/code/wt-oc-143673
bash "$LOCALAPPDATA/Temp/ocproof-144458/run-both.sh" 2>&1 | tee "$LOCALAPPDATA/Temp/ocproof-144458/run-both.log"

sha256: prove.mts ff8b425ee498dddf2bb60a99bff44e9a2abdd7b93dbcd45ad9daa8bba8ac7281,
run-both.sh cb0832f7a4a8f480974cc3e60d63d75b17b3e2cf09ac2e7d1db27af6a368ddf3,
run-both.log 6c88cbba79f26294d0c8138f7a1e2ea8334ebe5b809693169493787fd31db50b.

Raw output (exact, from run-both.log)

### repo=/d/code/wt-oc-143673
### branch=fix/oc-143673-descr head=ca7576db80b6dd2da1119d7dc414c03f10109203
### porcelain before: <clean>

############ AFTER (HEAD) ############
=== AFTER ===
local server: http://127.0.0.1:6351 (real node:http, 127.0.0.1, header Content-Type sent per case)

--- case /proto  Content-Type: "__proto__"  url=http://127.0.0.1:6351/proto
[storage saveRemoteMedia] OK id=d74ecae0-1d9a-4974-b99e-ede8ca198618 size=10 contentType="__proto__" (typeof string)
[storage on-disk] media\inbound\d74ecae0-1d9a-4974-b99e-ede8ca198618 bytes=10 hex=50524f544f2d424f4459 content="PROTO-BODY"
[storage media/inbound dir] ["d74ecae0-1d9a-4974-b99e-ede8ca198618"]
[reader loadWebMediaRaw] OK bytes=10 hex=50524f544f2d424f4459 contentType="__proto__" (typeof string) kind=undefined fileName="proto"

--- case /ctor  Content-Type: "constructor"  url=http://127.0.0.1:6351/ctor
[storage saveRemoteMedia] OK id=c20450a1-5a9a-4cad-9b35-7de0008d74aa size=9 contentType="constructor" (typeof string)
[storage on-disk] media\inbound\c20450a1-5a9a-4cad-9b35-7de0008d74aa bytes=9 hex=43544f522d424f4459 content="CTOR-BODY"
[storage media/inbound dir] ["c20450a1-5a9a-4cad-9b35-7de0008d74aa","d74ecae0-1d9a-4974-b99e-ede8ca198618"]
[reader loadWebMediaRaw] OK bytes=9 hex=43544f522d424f4459 contentType="constructor" (typeof string) kind=undefined fileName="ctor"

--- case /png  Content-Type: "image/png"  url=http://127.0.0.1:6351/png
[storage saveRemoteMedia] OK id=89cbda19-fcc8-4724-936d-055842a48561.png size=70 contentType="image/png" (typeof string)
[storage on-disk] media\inbound\89cbda19-fcc8-4724-936d-055842a48561.png bytes=70 hex=89504e470d0a1a0a0000 content="<PNG…>"
[storage media/inbound dir] ["89cbda19-fcc8-4724-936d-055842a48561.png","c20450a1-5a9a-4cad-9b35-7de0008d74aa","d74ecae0-1d9a-4974-b99e-ede8ca198618"]
[reader loadWebMediaRaw] OK bytes=70 hex=89504e470d0a1a0a0000 contentType="image/png" (typeof string) kind="image" fileName="png.png"

=== end AFTER ===

############ BEFORE (parent 28589e76ead3876ef73c5675d0fce19f1bbf6e16 source only) ############
### reverted source: M  packages/media-core/src/mime.ts
=== BEFORE ===
local server: http://127.0.0.1:6359 (real node:http, 127.0.0.1, header Content-Type sent per case)

--- case /proto  Content-Type: "__proto__"  url=http://127.0.0.1:6359/proto
[storage saveRemoteMedia] FAIL {"name":"MediaFetchError","code":"fetch_failed","message":"Failed to fetch media from http://127.0.0.1:6359/proto: mime.split is not a function","cause":{"name":"TypeError","message":"mime.split is not a function"}}
[storage media/inbound dir] []
[reader loadWebMediaRaw] FAIL {"name":"TypeError","message":"mime.split is not a function"}

--- case /ctor  Content-Type: "constructor"  url=http://127.0.0.1:6359/ctor
[storage saveRemoteMedia] FAIL {"name":"MediaFetchError","code":"fetch_failed","message":"Failed to fetch media from http://127.0.0.1:6359/ctor: mime.split is not a function","cause":{"name":"TypeError","message":"mime.split is not a function"}}
[storage media/inbound dir] []
[reader loadWebMediaRaw] FAIL {"name":"TypeError","message":"mime.split is not a function"}

--- case /png  Content-Type: "image/png"  url=http://127.0.0.1:6359/png
[storage saveRemoteMedia] OK id=4b931453-1d89-4494-a5a3-0d4e4232eadd.png size=70 contentType="image/png" (typeof string)
[storage on-disk] media\inbound\4b931453-1d89-4494-a5a3-0d4e4232eadd.png bytes=70 hex=89504e470d0a1a0a0000 content="<PNG…>"
[storage media/inbound dir] ["4b931453-1d89-4494-a5a3-0d4e4232eadd.png"]
[reader loadWebMediaRaw] OK bytes=70 hex=89504e470d0a1a0a0000 contentType="image/png" (typeof string) kind="image" fileName="png.png"

=== end BEFORE ===

############ RESTORE ############
### porcelain after restore: <clean>

(<PNG…> abbreviates the truncated PNG text rendering; the full log keeps the original bytes line.)

Result

case (real Content-Type) before (parent mime.ts) after (HEAD)
__proto__ — storage saveRemoteMedia FAIL MediaFetchError{fetch_failed}, cause TypeError: mime.split is not a function; 0 bytes written to media/inbound OK, contentType is a plain string "__proto__", 10 bytes on disk
__proto__ — reader loadWebMediaRaw FAIL TypeError: mime.split is not a function OK, bytes=10, kind=undefined, fileName="proto"
constructor — storage FAIL, same TypeError, 0 bytes written OK, "constructor", 9 bytes on disk
constructor — reader FAIL, same TypeError OK, bytes=9, kind=undefined
image/png (control) OK OK (identical: .png suffix, kind="image")

Both prototype-named headers break both production flows before the fix (a remote-controlled
Content-Type turns a normal inbound media save/download into a hard failure), and both classify as
unknown types after it, while normal MIME types are byte-for-byte unchanged (control case).

True / false claims

True:

  • The endpoint is a real node:http server on 127.0.0.1 with an ephemeral port; the harness fetches
    it over real TCP through the production SSRF-guarded fetch (no fetchImpl, no interceptor, no
    replay of captured bytes).
  • The entrypoints are the unmodified production exports saveRemoteMedia (src/media/fetch.ts) and
    loadWebMediaRaw (src/media/web-media.ts), loaded from the live TypeScript sources through the
    repo's own tsx preload; the harness contains no @openclaw/media-core import and no direct helper
    call.
  • The "on-disk" lines are files read back from the media store directory (OPENCLAW_STATE_DIR →
    %LOCALAPPDATA%/Temp/ocproof-144458/state/<after|before>/media/inbound); the bytes match the served
    bodies.
  • "before" is exactly the parent commit's packages/media-core/src/mime.ts applied to that single
    file; the log records the reverted file and the clean porcelain after restore
    (### porcelain after restore: <clean>). Nothing was pushed or committed; PR fix(media-core): keep prototype-named Content-Type values out of MIME lookup tables #144458 untouched.

False / limits (stated plainly):

  • This is not a full product run: no Slack/Telegram transport, no agent turn, no CLI session. It is
    the library entrypoints those callers invoke, driven with production-shaped options.
  • Only Content-Type headers are exercised (one header per case); the PR's unit tests cover the
    remaining prototype member names (__defineGetter__, toString, valueOf, …) and oversized values.
  • Loopback needs the allowedHostnames: ["127.0.0.1"] SSRF exemption to be reachable at all; the
    guard is configured, not mocked or bypassed.
  • Windows/git-bash host; a Linux run should be identical but was not executed here.

Conclusion

The fix is observable end-to-end at the production boundary: a hostile Content-Type of __proto__
or constructor used to make the remote-media storage entry fail (MediaFetchError/TypeError, no
file persisted) and the remote-media reader throw, and after the fix both entries classify it as an
unknown type, return a plain string, and persist/return the real bytes. The before/after difference is
attributable solely to packages/media-core/src/mime.ts, and the worktree was restored to a clean
state afterwards.

Re-ran by the author

bash run-both.sh was re-run by hand on this branch (143673 tree). AFTER: Content-Type: __proto__ → storage saveRemoteMedia OK (contentType="__proto__", typeof string, 10 bytes written) and reader loadWebMediaRaw OK (kind=undefined); constructor likewise; image/png control unchanged. BEFORE (only packages/media-core/src/mime.ts reverted): both entries fail with TypeError: mime.split is not a function at both entrypoints, 0 bytes persisted. porcelain clean after restore.

… tables

normalizeMimeType and extensionForMime indexed plain object-literal tables with a
remote-controlled Content-Type value, so a header of "__proto__" or "constructor"
resolved to an inherited Object.prototype member instead of a string and the next
string operation on the result threw (e.g. store.ts isImageHeaderMime,
mediaKindFromMime). Guard both lookups with Object.hasOwn so the returning tables
only resolve their own keys and prototype-named headers classify as unknown types,
matching the existing A2A method-alias guard. Unknown and prototype-named values now
fall back to the default (no extension, no media kind) instead of crashing.
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 14, 2026, 11:49 PM ET / September 15, 2026, 03:49 UTC.

ClawSweeper review

What this changes

Guards shared MIME lookup tables and adds regression coverage so prototype-named Content-Type headers behave as unknown types instead of crashing media handling.

Merge readiness

⛔ Blocked before merge - 1 item remains

The patch is correct and sufficiently proven, and main still needs the repair. The equivalent earlier PR has positive proof, but successive GitHub reads changed its mergeability from clean to unknown, so duplicate closure is not currently safe.

Priority: P2
Reviewed head: ca7576db80b6dd2da1119d7dc414c03f10109203

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with useful regression coverage and sufficient production-path proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The source-matched Windows transcript exercises real HTTP responses through saveRemoteMedia and loadWebMediaRaw: both hostile headers fail before the repair, then return plain strings and preserve bytes afterward, with an unchanged PNG control.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The source-matched Windows transcript exercises real HTTP responses through saveRemoteMedia and loadWebMediaRaw: both hostile headers fail before the repair, then return plain strings and preserve bytes afterward, with an unchanged PNG control.
Evidence reviewed 8 items Verified introduced change: The complete host-pinned merge-base-to-head patch changes only the two value-returning MIME lookups and their tests. Both guards preserve existing own entries and prevent inherited values from escaping; no authority, dependency, configuration, or persistence contract changes.
Current main remains affected: Main retains direct MIME_SYNONYMS and EXT_BY_MIME indexing. Comparing this module with the reviewed head shows only the proposed guards and explanatory comments; prototype-named headers still reach inherited non-string values on main.
Latest release remains affected: The v2026.9.4 tag peels to this commit, whose MIME module retains both unguarded lookups. This is not an implemented-on-main or shipped-fix outcome.
Findings None None.
Security None None.

How this fits together

Media Core classifies attachments from bytes, filenames, and response headers. Remote media readers and storage consume its MIME strings and preferred extensions when returning or saving attachments.

flowchart TD
  A[Remote media response] --> B[Bounded media fetch]
  B --> C[Bytes and response headers]
  C --> D[MIME normalization]
  D --> E{Own table entry?}
  E -->|Yes| F[Known MIME or extension]
  E -->|No| G[Unknown type fallback]
  F --> H[Read or save attachment]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - The equivalent earlier PR's current landing viability remains unresolved because GitHub returned inconsistent mergeability results.
Agent review details

Security

None.

PR surface

Source +5, Tests +77. Total +82 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 2 +5
Tests 1 77 0 +77
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 84 2 +82

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land one shared own-key lookup repair with the existing MIME precedence preserved, retaining both contributors' useful regression and production-proof context.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land one shared own-key lookup repair with the existing MIME precedence preserved, retaining both contributors' useful regression and production-proof context.

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

Yes: current source exposes inherited non-string values for proto and constructor, and the supplied real HTTP traces demonstrate the failure through production entrypoints. This read-only review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: guarding both producer lookups restores the existing string contract without changing supported MIME mappings or adding downstream workarounds.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a4790958b284.

Labels

Label justifications:

  • P2: Malformed remote headers can fail individual media operations; the evidence does not establish a process-wide outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 source-matched Windows transcript exercises real HTTP responses through saveRemoteMedia and loadWebMediaRaw: both hostile headers fail before the repair, then return plain strings and preserve bytes afterward, with an unchanged PNG control.
  • proof: sufficient: Contributor real behavior proof is sufficient. The source-matched Windows transcript exercises real HTTP responses through saveRemoteMedia and loadWebMediaRaw: both hostile headers fail before the repair, then return plain strings and preserve bytes afterward, with an unchanged PNG control.

Evidence

What I checked:

  • Verified introduced change: The complete host-pinned merge-base-to-head patch changes only the two value-returning MIME lookups and their tests. Both guards preserve existing own entries and prevent inherited values from escaping; no authority, dependency, configuration, or persistence contract changes. (packages/media-core/src/mime.ts:181, ca7576db80b6)
  • Current main remains affected: Main retains direct MIME_SYNONYMS and EXT_BY_MIME indexing. Comparing this module with the reviewed head shows only the proposed guards and explanatory comments; prototype-named headers still reach inherited non-string values on main. (packages/media-core/src/mime.ts:178, a4790958b284)
  • Latest release remains affected: The v2026.9.4 tag peels to this commit, whose MIME module retains both unguarded lookups. This is not an implemented-on-main or shipped-fix outcome. (packages/media-core/src/mime.ts:178, 3a9d69db306c)
  • Production boundary matches the proof: readRemoteMediaBuffer passes response headers into detectMime and then extensionForMime for extensionless filenames. saveRemoteMedia feeds response metadata into media storage, while loadWebMediaRaw consumes the real reader and classifies its result. (src/media/fetch.ts:745, ca7576db80b6)
  • Complete captured-body proof inspected: The retrieved complete body matches captured SHA-256 9fff307219d3c3f5c46c5294a4c2ddcce34d3f8d25239009521926738d1ebfc0. Its Windows Node 26.4.0 transcript exercises saveRemoteMedia and loadWebMediaRaw against a real HTTP server: prototype-named headers fail with parent MIME source, then return strings and preserve the served bytes after the fix; the PNG control remains unchanged. This addresses the earlier helper-only proof gap. Embedded scripts were read, not executed. (ca7576db80b6)
  • Equivalent earlier candidate: fix: preserve attachments with prototype-named content types #143673 remains open and unmerged at this head. Its inspected patch applies the same two guards and covers both dangerous names; its body supplies real HTTP reader before/after proof. This PR's additional cases broaden coverage without establishing a separate root cause. (packages/media-core/src/mime.ts:180, d90d1e1594d6)

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

@Finn763

Finn763 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

PR body updated with the requested proof through the real entrypoints: a real local HTTP server returns prototype-named Content-Type values; saveRemoteMedia (src/media/fetch.ts, the shared storage entrypoint) and loadWebMediaRaw (src/media/web-media.ts) now return them as plain strings and persist the bytes, while the image/png control is byte-identical; on the parent source both entrypoints throw mime.split is not a function. Both legs re-run by the author (bash run-both.sh).

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 13, 2026
obviyus added a commit that referenced this pull request Sep 16, 2026
## What Problem This Solves
Remote attachments with `Content-Type: __proto__` or `constructor` crash media handling before upload.

## Why This Change Was Made
Both MIME lookups now accept only their own entries. Unknown types remain strings, with no preferred extension. No shared state is written. The MIME module changes by +6/-2 to enforce these contracts.
Growth accepted under the owner's standing acceptance (2026-09-15).
Alternative: #144458 applies the same guards.

## User Impact
Malformed headers no longer prevent attachment delivery. Ordinary types keep their behavior.

## Evidence
`openclaw message send --channel discord --target channel:<qa-channel> --media <fixture-url>`
Before: both headers fail with `mime.split is not a function`, before upload.
After: recipient downloads contain the exact 31 fixture bytes for both headers and a normal unknown type. An ordinary PNG also arrives byte-for-byte.

## Compatibility
No configuration, schema, protocol, dependency or public signature changes.

## Consumers
Shared remote readers and channel attachment sends use the repaired MIME results.

## Invalidation
No cache or persistent state changes.

## Tests
290 tests passed on a fresh merge: `packages/media-core/src/mime.test.ts`, `src/media/fetch.test.ts`, and `src/media/fetch.prototype-headers.test.ts`. The hosted runner selects the new HTTP test once; all three cases pass.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…w#143673)

## What Problem This Solves
Remote attachments with `Content-Type: __proto__` or `constructor` crash media handling before upload.

## Why This Change Was Made
Both MIME lookups now accept only their own entries. Unknown types remain strings, with no preferred extension. No shared state is written. The MIME module changes by +6/-2 to enforce these contracts.
Growth accepted under the owner's standing acceptance (2026-09-15).
Alternative: openclaw#144458 applies the same guards.

## User Impact
Malformed headers no longer prevent attachment delivery. Ordinary types keep their behavior.

## Evidence
`openclaw message send --channel discord --target channel:<qa-channel> --media <fixture-url>`
Before: both headers fail with `mime.split is not a function`, before upload.
After: recipient downloads contain the exact 31 fixture bytes for both headers and a normal unknown type. An ordinary PNG also arrives byte-for-byte.

## Compatibility
No configuration, schema, protocol, dependency or public signature changes.

## Consumers
Shared remote readers and channel attachment sends use the repaired MIME results.

## Invalidation
No cache or persistent state changes.

## Tests
290 tests passed on a fresh merge: `packages/media-core/src/mime.test.ts`, `src/media/fetch.test.ts`, and `src/media/fetch.prototype-headers.test.ts`. The hosted runner selects the new HTTP test once; all three cases pass.

Co-authored-by: Ayaan Zaidi <[email protected]>
@Finn763

Finn763 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #143673 is already fixed on main by 6a85e4c8 ("fix: preserve attachments with prototype-named content types (#143673)", 2026-09-16) — the issue itself was closed the same day, and main's packages/media-core/src/mime.ts carries that fix. Nothing here needs to land on top of it.

@Finn763 Finn763 closed this Sep 17, 2026
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: S 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.

1 participant