Skip to content

fix(canvas): validate snapshot response formats [AI]#81881

Merged
pgondhi987 merged 5 commits into
openclaw:mainfrom
pgondhi987:fix/fix-651
May 15, 2026
Merged

fix(canvas): validate snapshot response formats [AI]#81881
pgondhi987 merged 5 commits into
openclaw:mainfrom
pgondhi987:fix/fix-651

Conversation

@pgondhi987

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Canvas snapshot responses could return unexpected format strings that were reused when constructing snapshot filenames.
  • Why it matters: Snapshot output should only use the image formats OpenClaw requests and supports.
  • What changed: Validated returned snapshot formats against png/jpg/jpeg, normalized jpeg file extensions to jpg, and rejected invalid snapshot path parts before file creation.
  • What did NOT change (scope boundary): No Canvas protocol, network, config, or snapshot image-processing behavior changed beyond response validation.
  • AI-assisted: Yes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related: N/A
  • This PR addresses a bug or regression

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Canvas snapshot response formats are validated before being used for snapshot file paths.
  • Real environment tested: Not tested against a live Canvas node; targeted repository tests were run locally.
  • Exact steps or command run after this patch: node scripts/run-vitest.mjs extensions/canvas/src/cli-helpers.test.ts extensions/canvas/src/cli.test.ts extensions/canvas/src/tool.test.ts
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): Test Files 3 passed (3); Tests 14 passed (14)
  • Observed result after fix: Invalid returned snapshot formats are rejected before CLI writes or tool image result creation.
  • What was not tested: Live paired Canvas node snapshot flow.
  • Before evidence (optional but encouraged): Not captured.

Root Cause (if applicable)

  • Root cause: Canvas snapshot response parsing accepted any non-empty format string, and the temp path helper accepted arbitrary extension strings.
  • Missing detection / guardrail: There was no regression coverage for path-like returned format values in CLI or tool snapshot paths.
  • Contributing context (if known): Outbound snapshot format values were constrained, but inbound response values were handled separately.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/canvas/src/cli-helpers.test.ts, extensions/canvas/src/cli.test.ts, extensions/canvas/src/tool.test.ts
  • Scenario the test should lock in: Path-like returned snapshot formats are rejected before snapshot file writes or image result creation.
  • Why this is the smallest reliable guardrail: The regression is in response parsing and temp path construction, so focused helper plus CLI/tool tests cover both affected call paths without requiring a live node.
  • Existing test that already covers this (if any): Existing snapshot tests covered supported png output only.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Canvas snapshot responses with unsupported image formats now fail instead of producing a snapshot file.

Diagram (if applicable)

Before:
[canvas.snapshot response] -> [returned format string] -> [snapshot file path]

After:
[canvas.snapshot response] -> [format allowlist] -> [snapshot file path or validation error]

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: Node-based repository test wrapper
  • Model/provider: N/A
  • Integration/channel (if any): Canvas plugin
  • Relevant config (redacted): N/A

Steps

  1. Run the targeted Canvas helper, CLI, and tool tests.
  2. Confirm invalid returned snapshot formats are rejected.
  3. Confirm supported png snapshot behavior still passes.

Expected

  • Supported snapshot formats continue to produce temp snapshot paths.
  • Unsupported returned formats throw validation errors before file creation.

Actual

  • Targeted tests passed with the expected validation behavior.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)
Test Files  3 passed (3)
Tests       14 passed (14)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Helper validation, CLI snapshot write guard, and tool snapshot image-result guard via targeted tests.
  • Edge cases checked: Path-like returned formats, unsupported MIME-style formats, supported png/jpg/jpeg extension normalization, and invalid temp path IDs.
  • What you did not verify: Live Canvas node behavior and broad repository checks.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: A non-standard Canvas node returning a format outside png/jpg/jpeg will now fail snapshot handling.
    • Mitigation: The plugin already requests only supported snapshot formats, and tests cover accepted png/jpg/jpeg normalization.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels May 14, 2026
@clawsweeper

clawsweeper Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds Canvas snapshot response format allowlisting, JPEG extension normalization, temp path part validation, and focused Canvas helper/CLI/tool regression tests.

Reproducibility: yes. Source inspection on current main shows a mocked canvas.snapshot response with a path-like format reaches CLI and tool temp-file construction; I did not execute tests in this read-only review.

Real behavior proof
Needs real behavior proof before merge: The PR body provides targeted test output only and says live Canvas was not tested; the contributor should add redacted live runtime proof and update the PR body for automatic re-review or ask a maintainer to comment @clawsweeper re-review.

Next step before merge
This focused PR needs contributor real behavior proof and protected-label maintainer handling rather than an automated code repair.

Security
Cleared: The diff narrows Canvas snapshot file-path construction and adds regression coverage without new dependencies, permissions, network calls, secrets handling, or code execution paths.

Review details

Best possible solution:

Land the Canvas-local response validation after maintainer review and redacted real runtime proof that unsupported snapshot response formats fail before file creation in the Canvas flow.

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

Yes. Source inspection on current main shows a mocked canvas.snapshot response with a path-like format reaches CLI and tool temp-file construction; I did not execute tests in this read-only review.

Is this the best way to solve the issue?

Yes for the code direction. Inbound allowlisting plus a shared file-extension normalizer is the narrow maintainable fix, with merge gated on real behavior proof and maintainer handling.

Acceptance criteria:

  • node scripts/run-vitest.mjs extensions/canvas/src/cli-helpers.test.ts extensions/canvas/src/cli.test.ts extensions/canvas/src/tool.test.ts
  • Redacted live paired Canvas node snapshot proof showing invalid returned formats fail before file creation

What I checked:

  • Current main accepts arbitrary Canvas snapshot response formats in the CLI helper: parseCanvasSnapshotPayload accepts any non-empty format, and canvasSnapshotTempPath appends the caller-provided extension into the temp filename. (extensions/canvas/src/cli-helpers.ts:12, 916fc3d09ae1)
  • Current main repeats the permissive path in the Canvas tool: The tool-local parser accepts any string format, then writeBase64ToTempFile turns that value into the snapshot file extension. (extensions/canvas/src/tool.ts:48, 916fc3d09ae1)
  • Documented Canvas snapshot surface is limited to image formats: The docs describe canvas.snapshot as { format, base64 }, and the CLI examples expose --format png and --format jpg snapshot flows. Public docs: docs/nodes/index.md. (docs/nodes/index.md:219, 916fc3d09ae1)
  • PR diff is narrowly scoped to Canvas validation and tests: The diff adds png/jpg/jpeg normalization, rejects invalid snapshot IDs and path-like returned formats, and covers the helper, CLI write guard, and tool image-result guard. (extensions/canvas/src/cli-helpers.ts:11, f6c4996837f2)
  • PR metadata still lacks real behavior proof: The PR body says the live paired Canvas node snapshot flow was not tested and provides targeted repository test output only; the live metadata also shows the protected maintainer label. (f6c4996837f2)
  • Existing review discussion already identified the same blocker: The earlier ClawSweeper comment requested real behavior proof before merge, and the author reply did not add live Canvas proof. (f6c4996837f2)

Likely related people:

  • steipete: Current-main blame attributes the Canvas snapshot helper and CLI snapshot path to 0844e77, and GitHub path history shows earlier Canvas plugin surface work including refactor: move canvas to plugin surfaces. (role: feature owner / recent area contributor; confidence: high; commits: 0844e771a8df, 330ba1fa3194, 827b0de0ce74; files: extensions/canvas/src/cli-helpers.ts, extensions/canvas/src/cli.ts, extensions/canvas/src/tool.ts)
  • samzong: GitHub path history shows recent work touching extensions/canvas/src/tool.ts in refactor(canvas): lazy-load startup modules, which is adjacent to the tool snapshot path changed by this PR. (role: recent area contributor; confidence: medium; commits: a4cd48248812; files: extensions/canvas/src/tool.ts)

Remaining risk / open question:

  • The PR body provides only targeted test output and explicitly says the live paired Canvas node snapshot flow was not tested.
  • The behavior change intentionally rejects non-standard Canvas nodes returning formats outside png/jpg/jpeg; that compatibility boundary should be maintainer-accepted before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 916fc3d09ae1.

@pgondhi987

Copy link
Copy Markdown
Contributor Author

Not applicable to this automation stage; changelog/release-note and external real behavior proof requirements are handled outside auto-pr stages.

Quoted comment from @clawsweeper:

Codex review: needs real behavior proof before merge.

Summary
The PR adds Canvas snapshot response format allowlisting, normalizes JPEG file extensions, rejects unsafe snapshot temp path parts, and adds helper, CLI, and tool regression tests.

Reproducibility: yes. Source inspection gives a high-confidence reproduction path: on current main, a mocked canvas.snapshot response with a path-like format reaches both CLI and tool temp-path construction; I did not execute tests in this read-only review.

Real behavior proof
Needs real behavior proof before merge: The body provides only targeted test output and says live Canvas was not tested; add redacted real runtime proof, then update the PR body to trigger ClawSweeper or ask @clawsweeper re-review.

Next step before merge
No repair job: the patch looks focused, but the protected label and mock-only proof require contributor evidence and maintainer handling rather than automated code repair.

Security
Cleared: The diff narrows Canvas snapshot file-path construction and adds regression coverage without new dependencies, permissions, network calls, secrets handling, or code execution paths.

Review details

Best possible solution:

Land the owner-local Canvas validation after maintainer review and redacted real runtime proof that unsupported snapshot response formats fail before file creation in the Canvas flow.

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

Yes. Source inspection gives a high-confidence reproduction path: on current main, a mocked canvas.snapshot response with a path-like format reaches both CLI and tool temp-path construction; I did not execute tests in this read-only review.

Is this the best way to solve the issue?

Yes for the code direction. Inbound allowlisting plus temp path part validation in the Canvas plugin helper is the narrow maintainable fix, with merge gated on real behavior proof and maintainer handling.

What I checked:

  • Current main accepts arbitrary Canvas snapshot formats in the CLI helper: parseCanvasSnapshotPayload accepts any non-empty string format, and canvasSnapshotTempPath turns the caller-supplied extension into the output suffix without an allowlist. (extensions/canvas/src/cli-helpers.ts:12, 386d321634b3)
  • Current main repeats the permissive path in the Canvas tool: The tool-local parser accepts any string format, writeBase64ToTempFile uses it as the file extension, and the snapshot path passes payload.format into that helper. (extensions/canvas/src/tool.ts:62, 386d321634b3)
  • Documented snapshot surface is a Canvas { format, base64 } response with CLI png/jpg options: Docs describe canvas.snapshot as returning { format, base64 }, while the CLI exposes supported --format png and --format jpg snapshot flows. Public docs: docs/nodes/index.md. (docs/nodes/index.md:219, 386d321634b3)
  • PR diff narrows the affected Canvas helper and test paths: The diff adds png/jpg/jpeg validation, normalizes jpeg to jpg for filenames, validates snapshot IDs, and adds tests that reject path-like returned formats before CLI writes or tool image result creation. (extensions/canvas/src/cli-helpers.ts:5, be904b6fa8eb)
  • PR metadata requires human/proof follow-up: The live PR metadata shows the protected maintainer label; the PR body says the live paired Canvas node flow was not tested and provides only targeted repository test output. (be904b6fa8eb)
  • Feature history points to the current Canvas snapshot helper author: Blame on the current helper/tool lines attributes the Canvas snapshot parsing and temp-file construction code to commit f3f6a86; the GitHub commit API maps that commit to vincentkoc. (extensions/canvas/src/cli-helpers.ts:12, f3f6a866cae1)

Likely related people:

  • vincentkoc: Current-main blame attributes the Canvas snapshot helper and tool parsing/temp-file code to f3f6a86, and the GitHub commit API maps that commit to this login. (role: recent area contributor; confidence: medium; commits: f3f6a866cae1; files: extensions/canvas/src/cli-helpers.ts, extensions/canvas/src/tool.ts)

Remaining risk / open question:

  • Real behavior proof is mock/test-only: the PR body explicitly says a live paired Canvas node snapshot flow was not tested.
  • The PR changes behavior for non-standard Canvas nodes that return formats outside png/jpg/jpeg; that looks intentional but should be maintainer-accepted before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 386d321634b3.

@pgondhi987
pgondhi987 merged commit 238b0fc into openclaw:main May 15, 2026
17 of 18 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix: validate canvas snapshot formats

* addressing codex review

* docs: add changelog entry for PR merge
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix: validate canvas snapshot formats

* addressing codex review

* docs: add changelog entry for PR merge
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
* fix: validate canvas snapshot formats

* addressing codex review

* docs: add changelog entry for PR merge
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix: validate canvas snapshot formats

* addressing codex review

* docs: add changelog entry for PR merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant