Skip to content

fix(signal): reject malformed base64 attachment data - #114883

Merged
steipete merged 1 commit into
openclaw:mainfrom
MoerAI:fix/signal-attachment-base64
Jul 29, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
MoerAI:fix/signal-attachment-base64

Conversation

@MoerAI

@MoerAI MoerAI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

When signal-cli returns a damaged getAttachment payload — 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

signalRpcRequest in extensions/signal/src/client.ts ends with return parsed.result as T — a bare TypeScript cast with no runtime validation (the Signal extension only uses zod in config-schema.ts). So in fetchAttachment (extensions/signal/src/monitor.ts), result.data is 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 calls estimateBase64DecodedBytes, which is computed from string length and therefore cannot detect an invalid alphabet or padding.

extensions/signal/src/monitor.ts owns 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. canonicalizeBase64 was added to the module's existing openclaw/plugin-sdk/media-runtime import, which already provides detectMime, estimateBase64DecodedBytes, and saveMediaBuffer — no new helper, no new import path, no core src/** 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, and src/agents/tool-images.ts all 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

  • Before: a malformed getAttachment payload is written to the media directory as a corrupted file and delivered as a valid attachment. No error surfaces.
  • After: the fetch fails with Signal attachment <id> returned malformed base64 data and nothing is written.

Evidence

Real runtime proof. A driver stands up an actual local HTTP server implementing the signal-cli POST /api/v1/rpc contract plus its SSE stream, returning a real PNG's base64 with three characters replaced by %. The real monitorSignalProvider runs 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):

v24.18.0
canonicalizeBase64=undefined
Buffer.from(malformed, base64)=byteLength:68 firstBytes:89504e470d0a1a0a0000000d
getAttachment RPC calls=1
attachment error thrown=false
saved media files=1
saved media 21fae819-d493-4c74-ab66-5ac1411f9346.png=byteLength:68 firstBytes:89504e470d0a1a0a0000000d

After (fix applied):

v24.18.0
canonicalizeBase64=undefined
Buffer.from(malformed, base64)=byteLength:68 firstBytes:89504e470d0a1a0a0000000d
getAttachment RPC calls=1
attachment error thrown=true
worker output=worker attachment error=attachment fetch failed: Error: Signal attachment proof-attachment returned malformed base64 data
saved media files=0

The first two lines are the core of it: canonicalizeBase64 rejects the payload, yet Buffer.from happily returns 68 bytes that still carry the PNG magic number — which is exactly why the corrupted file looked legitimate on disk.

Tests and checks.

  • Red first: on unmodified monitor.ts the new regression test failed with AssertionError: promise resolved "{ …(2) }" instead of rejecting, receiving { contentType: "image/png", path: "/tmp/signal-attachment.png" }.
  • Green: node scripts/run-vitest.mjs extensions/signal/src/monitor.attachment-base64.test.ts — 1 file, 1 test passed.
  • Negative control: stashing only extensions/signal/src/monitor.ts reproduces the exact red failure, confirming the test guards this bug rather than passing incidentally.
  • Full extension suite: node scripts/run-vitest.mjs extensions/signal — 731/732 passed. The single failure is extensions/signal/src/install-signal-cli.test.ts (download-temp cleanup expects result.ok=true), which is pre-existing on main and untouched by these files.
  • pnpm tsgo:extensions and pnpm tsgo:extensions:test passed.
  • pnpm exec oxfmt --check --threads=1 on both changed files passed; git diff --check clean.

The regression test drives the real private fetchAttachment through the production wiring that monitorSignalProvider hands to createSignalEventHandler, and it spreads importActual for the media-runtime module so the genuine canonicalizeBase64 executes 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.

@openclaw-barnacle openclaw-barnacle Bot added channel: signal Channel integration: signal size: S labels Jul 28, 2026
@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 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 28, 2026, 1:26 AM ET / 05:26 UTC.

ClawSweeper review

What this changes

Reject 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
Reviewed head: efe1ad3763a3771e8e850281673e4629a68fad30

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused defensive fix with a realistic before/after runtime demonstration and targeted regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR provides redacted live before/after runtime output for the Signal RPC/SSE path, showing malformed data is no longer written to the media directory.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR provides redacted live before/after runtime output for the Signal RPC/SSE path, showing malformed data is no longer written to the media directory.
Evidence reviewed 4 items Patch boundary: The proposed monitor change validates the RPC-provided attachment data with the existing plugin SDK base64 canonicalizer after the established size check and before decoding or media persistence.
Focused regression coverage: The added test captures the production attachment-fetch dependency supplied by the Signal monitor, uses the real media-runtime canonicalizer, and asserts malformed attachment data rejects rather than reaching media persistence.
Re-review continuity: The prior ClawSweeper review had no correctness findings and asked only for a rebase against the Signal transport refactor; the contributor force-pushed the rebased head and reported the focused regression test passing on that head.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +93. Total +98 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 1 +5
Tests 1 93 0 +93
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 99 1 +98

Review metrics

None.

Technical review

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

Labels

Label justifications:

  • P2: Malformed external attachment payloads can otherwise be silently persisted as corrupt Signal media, but the repair is focused and has limited channel-specific blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR provides redacted live before/after runtime output for the Signal RPC/SSE path, showing malformed data is no longer written to the media directory.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides redacted live before/after runtime output for the Signal RPC/SSE path, showing malformed data is no longer written to the media directory.

Evidence

What I checked:

  • Patch boundary: The proposed monitor change validates the RPC-provided attachment data with the existing plugin SDK base64 canonicalizer after the established size check and before decoding or media persistence. (extensions/signal/src/monitor.ts:316, efe1ad3763a3)
  • Focused regression coverage: The added test captures the production attachment-fetch dependency supplied by the Signal monitor, uses the real media-runtime canonicalizer, and asserts malformed attachment data rejects rather than reaching media persistence. (extensions/signal/src/monitor.attachment-base64.test.ts:1, efe1ad3763a3)
  • Re-review continuity: The prior ClawSweeper review had no correctness findings and asked only for a rebase against the Signal transport refactor; the contributor force-pushed the rebased head and reported the focused regression test passing on that head. (extensions/signal/src/monitor.ts:316, efe1ad3763a3)
  • Real behavior proof: The PR body documents a local signal-cli-compatible RPC/SSE run where malformed PNG base64 previously produced a saved 68-byte file, while the patched path throws an attachment error and leaves the media directory empty. (extensions/signal/src/monitor.ts:316, efe1ad3763a3)

Likely related people:

  • MoerAI: The supplied review context identifies this contributor as the author of the focused current-head repair and its proof; no independent local history trail was available in this read-only review environment. (role: current Signal attachment change contributor; confidence: low; commits: efe1ad3763a3; files: extensions/signal/src/monitor.ts, extensions/signal/src/monitor.attachment-base64.test.ts)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-07-28T03:08:16.358Z sha 6120cd7b091a3123e639a91dda3f08d2dd334421 :: needs maintainer review before merge. :: none

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.
@MoerAI
MoerAI force-pushed the fix/signal-attachment-base64 branch from 6120cd7 to efe1ad3 Compare July 28, 2026 05:23
@MoerAI

MoerAI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main — this clears the only remaining before-merge item ("the branch is behind current main; rebase and recheck the small monitor change against the current Signal transport refactor").

ClawSweeper proof for current head efe1ad3763a3771e8e850281673e4629a68fad30:

The branch was 56 commits behind. It now sits on 3ae29adffac. The rebase was conflict-free and the diff is byte-identical to the reviewed head — still 2 files, +99/-1:

 extensions/signal/src/monitor.attachment-base64.test.ts | 93 ++++++++++++++++++++++
 extensions/signal/src/monitor.ts                        |  7 +-
 2 files changed, 99 insertions(+), 1 deletion(-)

Rechecked against the current Signal transport code as requested. fetchAttachment still owns the decode boundary, the pre-existing size guard still runs first, and the validation still sits between that guard and Buffer.from:

   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:

 Test Files  1 passed (1)
      Tests  1 passed (1)
[test] passed 1 Vitest shard in 292.26s
  • node scripts/run-vitest.mjs extensions/signal/src/monitor.attachment-base64.test.ts — 1 test passed on the rebased head
  • pnpm exec oxfmt --check --threads=1 on both changed files — "All matched files use the correct format."
  • git diff --check — clean

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

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 28, 2026
@steipete
steipete merged commit ac09e35 into openclaw:main Jul 29, 2026
136 of 138 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 29, 2026
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.
vincentkoc added a commit that referenced this pull request Jul 29, 2026
…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)
  ...
@MoerAI
MoerAI deleted the fix/signal-attachment-base64 branch July 30, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: signal Channel integration: signal P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants