Repository navigation
fix(signal): reject malformed base64 attachment data - #114883
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 28, 2026, 1:26 AM ET / 05:26 UTC. ClawSweeper reviewWhat this changesReject malformed base64 returned by Signal’s attachment RPC before it can be decoded, saved as media, and forwarded to the agent. Merge readiness✅ Ready for maintainer review This PR remains necessary: it closes a concrete Signal attachment-integrity gap by rejecting malformed base64 before Node decodes and persists it. The rebased head addresses the previous review’s only requested follow-up, and the supplied live before/after proof plus focused regression coverage support a normal maintainer merge review once required checks finish. Priority: P2 Review scores
Verification
How this fits togetherThe bundled Signal channel plugin receives attachment metadata and base64 payloads from signal-cli, then decodes and saves media for inbound event handling. This change hardens the validation boundary between the external RPC response and OpenClaw’s persisted attachment file. flowchart LR
A[signal-cli attachment RPC] --> B[Signal channel monitor]
B --> C[Attachment size check]
C --> D[Base64 canonicalization]
D -->|valid| E[Decode and save media]
D -->|malformed| F[Attachment fetch error]
E --> G[Inbound Signal event handler]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests +93. Total +98 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Merge the focused validation boundary and regression test after the required checks complete on the rebased head, preserving the existing size-limit behavior and Signal transport contract. Do we have a high-confidence way to reproduce the issue? Yes, with medium confidence: the PR supplies a concrete signal-cli-compatible RPC/SSE scenario that replaces characters in real PNG base64 and observes saved corrupt media before the patch versus an error and no saved file after it. Is this the best way to solve the issue? Yes: validating at the Signal monitor’s existing decode boundary with the shared media-runtime helper is narrower and less duplicative than adding RPC-wide schema machinery for this attachment-specific payload. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d894a235e88d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
signalRpcRequest returns the JSON-RPC result via a bare cast, so getAttachment data reaches Buffer.from unvalidated. Node drops out-of-alphabet characters instead of throwing, so a damaged payload was silently written to disk as a corrupted attachment. Canonicalize after the existing size guard and fail with the attachment id instead.
6120cd7 to
efe1ad3
Compare
|
Rebased onto current ClawSweeper proof for current head The branch was 56 commits behind. It now sits on Rechecked against the current Signal transport code as requested. if (estimateBase64DecodedBytes(result.data) > params.maxBytes) {
throw new Error(
`Signal attachment ${attachment.id} exceeds ${(params.maxBytes / (1024 * 1024)).toFixed(0)}MB limit`,
);
}
- const buffer = Buffer.from(result.data, "base64");
+ const canonicalData = canonicalizeBase64(result.data);
+ if (!canonicalData) {
+ throw new Error(`Signal attachment ${attachment.id} returned malformed base64 data`);
+ }
+ const buffer = Buffer.from(canonicalData, "base64");Regression test on the rebased head:
The real-behavior proof in the PR body still applies unchanged: the rebase did not touch the decode path, and the local signal-cli-compatible RPC/SSE run showed malformed base64 producing a saved 68-byte corrupted file before the fix and a thrown error with zero saved files after it. @clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
signalRpcRequest returns the JSON-RPC result via a bare cast, so getAttachment data reaches Buffer.from unvalidated. Node drops out-of-alphabet characters instead of throwing, so a damaged payload was silently written to disk as a corrupted attachment. Canonicalize after the existing size guard and fail with the attachment id instead.
…ifecycle-hooks * origin/main: (60 commits) fix(qa): verify paired Ollama nodes over the gateway (#115644) fix(active-memory): share one recall per run across retries (#115627) refactor: reuse doctor migration durability helpers (#115625) docs: fix unsupported pnpm approve-builds -g in global install (#106180) feat(openai): support GA realtime over ChatGPT OAuth (#115623) feat(agents): add code mode model acceptance matrix (#115305) fix(signal): reject malformed base64 attachment data (#114883) fix(onboard): reject remote flags in local mode (#115636) refactor: table-drive retired model migrations (#115618) fix(ui): fall back when profile hero avatar fails (#115600) feat: make self-learning automatic by default (#115576) fix(agents): report embedded deadlines as timeouts (#115319) fix(cli): keep JSON stdout valid through finalization (#115315) fix(agents): clarify code mode contract for small models (#115275) fix(linux): package media codecs for deb and AppImage (#115616) fix(gateway): redact CLI-imported history before dedupe (#115597) fix(gateway): bound stalled plugin shutdown (#115619) refactor(gateway): deduplicate message operation routing (#115615) fix(nodes): cancel paired local inference when callers disconnect (#115624) fix(googlechat): surface failed replies without duplicate sends (#115638) ...
What Problem This Solves
When signal-cli returns a damaged
getAttachmentpayload — a truncated JSON-RPC response, a proxy that mangles the body, or a daemon-side bug — OpenClaw silently saves a corrupted attachment to the media directory and hands it to the agent as a normal image or file. Nothing fails and nothing is logged, so the user just gets a broken attachment and an agent reasoning over garbage bytes.Why This Change Was Made
signalRpcRequestinextensions/signal/src/client.tsends withreturn parsed.result as T— a bare TypeScript cast with no runtime validation (the Signal extension only uses zod inconfig-schema.ts). So infetchAttachment(extensions/signal/src/monitor.ts),result.datais an entirely unvalidated string from the daemon.That string went straight into
Buffer.from(result.data, "base64"). Node's base64 decoder is lenient: it drops characters outside the alphabet instead of throwing, so malformed input decodes into short/misaligned bytes that still look like a real payload. The pre-existing guard on the line above only callsestimateBase64DecodedBytes, which is computed from string length and therefore cannot detect an invalid alphabet or padding.extensions/signal/src/monitor.tsowns this decode step, so the fix lives there and nowhere else: canonicalize with the shared SDK helper, and fail with the attachment id if it rejects.canonicalizeBase64was added to the module's existingopenclaw/plugin-sdk/media-runtimeimport, which already providesdetectMime,estimateBase64DecodedBytes, andsaveMediaBuffer— no new helper, no new import path, no coresrc/**reach-through.This matches the sibling shape already merged across the codebase for the same bug class:
extensions/google/speech-provider.ts,extensions/xai/tts.ts,extensions/volcengine/tts.ts, andsrc/agents/tool-images.tsall canonicalize untrusted base64 before decoding. The Signal attachment path was missed.Non-goals: the existing size guard keeps its behavior and its position ahead of the decode; no other base64 site, no other Signal behavior, and no retry/error-handling machinery is touched.
User Impact
getAttachmentpayload is written to the media directory as a corrupted file and delivered as a valid attachment. No error surfaces.Signal attachment <id> returned malformed base64 dataand nothing is written.Evidence
Real runtime proof. A driver stands up an actual local HTTP server implementing the signal-cli
POST /api/v1/rpccontract plus its SSE stream, returning a real PNG's base64 with three characters replaced by%. The realmonitorSignalProviderruns in a child process against it and the actual media directory is inspected afterwards. No vitest, no test doubles in the decode path.Before (fix stashed, unmodified
monitor.ts):After (fix applied):
The first two lines are the core of it:
canonicalizeBase64rejects the payload, yetBuffer.fromhappily returns 68 bytes that still carry the PNG magic number — which is exactly why the corrupted file looked legitimate on disk.Tests and checks.
monitor.tsthe new regression test failed withAssertionError: promise resolved "{ …(2) }" instead of rejecting, receiving{ contentType: "image/png", path: "/tmp/signal-attachment.png" }.node scripts/run-vitest.mjs extensions/signal/src/monitor.attachment-base64.test.ts— 1 file, 1 test passed.extensions/signal/src/monitor.tsreproduces the exact red failure, confirming the test guards this bug rather than passing incidentally.node scripts/run-vitest.mjs extensions/signal— 731/732 passed. The single failure isextensions/signal/src/install-signal-cli.test.ts(download-temp cleanup expectsresult.ok=true), which is pre-existing onmainand untouched by these files.pnpm tsgo:extensionsandpnpm tsgo:extensions:testpassed.pnpm exec oxfmt --check --threads=1on both changed files passed;git diff --checkclean.The regression test drives the real private
fetchAttachmentthrough the production wiring thatmonitorSignalProviderhands tocreateSignalEventHandler, and it spreadsimportActualfor the media-runtime module so the genuinecanonicalizeBase64executes rather than a stub. Only the network boundary and media persistence are mocked.No changelog entry: this surfaces an error on an already-broken payload rather than changing documented behavior.
AI-assisted (Claude Code); I have reviewed every line and re-ran the regression and both proof runs myself after rebasing onto current
main.