Repository navigation
Conversation
… 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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 14, 2026, 11:49 PM ET / September 15, 2026, 03:49 UTC. ClawSweeper reviewWhat this changesGuards 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 Review scores
Verification
How this fits togetherMedia 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource +5, Tests +77. Total +82 across 2 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
@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; |
|
🦞🧹 I asked ClawSweeper to review this item again. |
## 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]>
…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]>
|
Closing as superseded: #143673 is already fixed on main by |
Fixes #143673
What Problem This Solves
A remote sender controls a media response's
Content-Typeheader, and that raw value flowsinto the MIME normalization tables in
packages/media-core/src/mime.ts. Both value-returningtables were plain object literals indexed with the untrusted string:
So a header value that happens to name an
Object.prototypemember resolved to the inheritedmember instead of a string:
Content-Type: __proto__->normalizeMimeTypereturned[object Object]Content-Type: constructor->normalizeMimeTypereturnedObject(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 fetchpath where
extensionForMimeis called for an extensionless filename(
src/media/fetch.ts). One hostile header killed that media operation on every triggeracross web fetch, channel attachments, and
file.fetchpayloads.Evidence
Real run against the unpatched source, driving the same functions the production callers use
(
normalizeMimeType,extensionForMime,kindFromMime,detectMime, plus thestore.ts:isImageHeaderMimeshapenormalizeMimeType(ct)?.startsWith("image/")):Before the patch:
After the patch, the identical script:
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.tsTests 5 failed | 214 passed (219)— failures are theprototype-named cases returning
[object Object]/Function Object.Tests 219 passed (219).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
git grepover the whole tree shows the only indexed lookup tablesreached by an untrusted MIME string are
MIME_SYNONYMS(vianormalizeMimeType) andEXT_BY_MIME(viaextensionForMime). Both are now own-key-only, so the roughly 100 callsites of those two helpers outside tests (across
src/andextensions/) get the stringcontract back. Two sibling tables need no guard
and were left alone:
MIME_BY_EXTis only keyed by a path extension (always""or.something), andAMBIGUOUS_VIDEO_MIME_BY_AUDIO_MIMEfeeds a strict-equality comparisonand never returns the looked-up value.
packages/media-core/src/mime.test.ts: prototype-named values(
__proto__,constructor,__defineGetter__,__lookupSetter__,toString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable), parameterized/empty/whitespacevalues, an oversized (64 KiB) value,
detectMimeheader 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/.pdfpath mapping).normalizeMimeTypeguard ->5 failed | 214 passed;reverting only the
extensionForMimeguard ->5 failed | 214 passed(the lookup returnsthe inherited
Object.prototype/Function, which is why both guards are required). Bothfiles 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.
Object.hasOwn, thesame pattern already used for alias tables (
extensions/a2a/src/protocol.ts). Diff is2 files changed, 84 insertions(+), 2 deletions(-).PR #144458 — real remote-media reader/storage entry proof (before/after)
Repo:
openclaw/openclaw@ worktreeD:/code/wt-oc-143673(branchfix/oc-143673-descr)HEAD (after):
ca7576db80b6dd2da1119d7dc414c03f10109203— "fix(media-core): keep prototype-named Content-Type values out of MIME tables"Parent (before):
28589e76ead3876ef73c5675d0fce19f1bbf6e16Host: 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.tsis the only source file in the commit. A remote sender controlsContent-Type, and both lookup tables are plain object literals.before (parent, lines 174–178):
after (HEAD, lines 175–181 + 291–299):
So before the fix
normalizeMimeType("__proto__")returnedObject.prototypeandnormalizeMimeType("constructor")returned theObjectconstructor — both typedstring, neither astring. The next string operation on the result (
mime.split) throwsTypeError: mime.split is not a function.Real entrypoints driven (production callers, not helpers)
saveRemoteMedia()src/media/fetch.ts:667extensions/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 totalloadWebMediaRaw()src/media/web-media.ts:1211src/agents/tools/image-tool.ts,src/agents/tools/pdf-tool.ts,src/plugin-sdk/web-media.ts, discord/matrix/msteams/telegram/whatsapp extensionsThe failing call chain the harness exercises (unchanged by the PR, only its input changes):
saveRemoteMedia→saveOkMediaResponse→saveMediaStream→extensionForAuthoritativeHeaderMime(
src/media/store.ts:376) →extensionForMime; andloadWebMediaRaw→readRemoteMediaBuffer→detectMimeheader 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 realnode:httpserver on127.0.0.1:0and serves three routes with the raw header valuesContent-Type: __proto__(bodyPROTO-BODY),Content-Type: constructor(bodyCTOR-BODY) and acontrol
Content-Type: image/png(a real 70-byte 1x1 PNG). Real TCP, real header bytes; theharness passes no
fetchImpl, installs no interceptor and imports no@openclaw/media-coresymbol — 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_DIRpoints the store at the proofworkspace, so
~/.openclawis 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, thengit checkout 28589e76ead3876ef73c5675d0fce19f1bbf6e16 -- packages/media-core/src/mime.ts(that one file, nothing else), before run, then
git checkout HEAD --the same file and prints theporcelain state.
sha256:
prove.mts ff8b425ee498dddf2bb60a99bff44e9a2abdd7b93dbcd45ad9daa8bba8ac7281,run-both.sh cb0832f7a4a8f480974cc3e60d63d75b17b3e2cf09ac2e7d1db27af6a368ddf3,run-both.log 6c88cbba79f26294d0c8138f7a1e2ea8334ebe5b809693169493787fd31db50b.Raw output (exact, from
run-both.log)(
<PNG…>abbreviates the truncated PNG text rendering; the full log keeps the original bytes line.)Result
Content-Type)__proto__— storagesaveRemoteMediaMediaFetchError{fetch_failed}, causeTypeError: mime.split is not a function; 0 bytes written tomedia/inboundcontentTypeis a plain string"__proto__", 10 bytes on disk__proto__— readerloadWebMediaRawTypeError: mime.split is not a functionbytes=10,kind=undefined,fileName="proto"constructor— storage"constructor", 9 bytes on diskconstructor— readerbytes=9,kind=undefinedimage/png(control).pngsuffix,kind="image")Both prototype-named headers break both production flows before the fix (a remote-controlled
Content-Typeturns a normal inbound media save/download into a hard failure), and both classify asunknown types after it, while normal MIME types are byte-for-byte unchanged (control case).
True / false claims
True:
node:httpserver on127.0.0.1with an ephemeral port; the harness fetchesit over real TCP through the production SSRF-guarded fetch (no
fetchImpl, no interceptor, noreplay of captured bytes).
saveRemoteMedia(src/media/fetch.ts) andloadWebMediaRaw(src/media/web-media.ts), loaded from the live TypeScript sources through therepo's own tsx preload; the harness contains no
@openclaw/media-coreimport and no direct helpercall.
OPENCLAW_STATE_DIR→%LOCALAPPDATA%/Temp/ocproof-144458/state/<after|before>/media/inbound); the bytes match the servedbodies.
packages/media-core/src/mime.tsapplied to that singlefile; 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):
the library entrypoints those callers invoke, driven with production-shaped options.
Content-Typeheaders are exercised (one header per case); the PR's unit tests cover theremaining prototype member names (
__defineGetter__,toString,valueOf, …) and oversized values.allowedHostnames: ["127.0.0.1"]SSRF exemption to be reachable at all; theguard is configured, not mocked or bypassed.
Conclusion
The fix is observable end-to-end at the production boundary: a hostile
Content-Typeof__proto__or
constructorused to make the remote-media storage entry fail (MediaFetchError/TypeError, nofile 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 cleanstate afterwards.
Re-ran by the author
bash run-both.shwas re-run by hand on this branch (143673tree). AFTER:Content-Type: __proto__→ storagesaveRemoteMediaOK (contentType="__proto__", typeof string, 10 bytes written) and readerloadWebMediaRawOK (kind=undefined);constructorlikewise;image/pngcontrol unchanged. BEFORE (onlypackages/media-core/src/mime.tsreverted): both entries fail withTypeError: mime.split is not a functionat both entrypoints, 0 bytes persisted.porcelainclean after restore.