Skip to content

fix(browser): reject malformed proxy file base64 - #115045

Merged
steipete merged 3 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/browser-proxy-base64-validation
Jul 29, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/browser-proxy-base64-validation

Conversation

@sunlit-deng

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Browser proxy users could receive corrupted saved files when the node-hosted browser proxy returned malformed base64 file data.

Why This Change Was Made

Browser proxy files now use the shared media-runtime base64 validation before decoding, while keeping the existing per-file and aggregate byte limits. Invalid file payloads are rejected before any additional media file is persisted.

User Impact

Browser screenshots and downloads saved through the proxy no longer silently accept malformed base64 payloads as corrupted files.

Evidence

  • Production module proof: pnpm exec tsx proof-live.ts imports extensions/browser/src/browser/proxy-files.ts, saves a valid proxy file, rejects a malformed negative control, and leaves the persisted file count unchanged after rejection.
  • Focused test: node scripts/run-vitest.mjs run extensions/browser/src/browser/proxy-files.test.ts
$ pnpm exec tsx proof-live.ts
entrypoint: extensions/browser/src/browser/proxy-files.ts
valid: saved=true path=true
negative-control: browser proxy file contains malformed base64 data
post-reject-file-count: before=1 after=1

$ node scripts/run-vitest.mjs run extensions/browser/src/browser/proxy-files.test.ts
Test Files  1 passed (1)
Tests  7 passed (7)
proof-live.ts
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";

async function main() {
  const tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-browser-proxy-proof-"));
  process.env.OPENCLAW_STATE_DIR = tempStateDir;

  const moduleUrl = pathToFileURL(
    path.join(process.cwd(), "extensions/browser/src/browser/proxy-files.ts"),
  ).href;
  const { persistBrowserProxyFiles } = await import(moduleUrl);

  const validMapping = await persistBrowserProxyFiles([
    {
      path: "/node/valid.txt",
      base64: Buffer.from("browser proxy proof").toString("base64"),
      mimeType: "text/plain",
    },
  ]);
  const savedPath = validMapping.get("/node/valid.txt");
  if (!savedPath) {
    throw new Error("valid file did not return a saved media path");
  }
  const savedText = await fs.readFile(savedPath, "utf8");
  const browserMediaDir = path.join(tempStateDir, "media", "browser");
  const beforeRejectEntries = await fs.readdir(browserMediaDir);

  const malformedError = await persistBrowserProxyFiles([
    {
      path: "/node/malformed.txt",
      base64: "YnJvd3Nlcg$",
      mimeType: "text/plain",
    },
  ]).then(
    () => null,
    (err: unknown) => (err instanceof Error ? err.message : String(err)),
  );
  const afterRejectEntries = await fs.readdir(browserMediaDir);

  console.log("entrypoint: extensions/browser/src/browser/proxy-files.ts");
  console.log(
    `valid: saved=${savedText === "browser proxy proof"} path=${savedPath.includes("/media/browser/")}`,
  );
  console.log(`negative-control: ${malformedError}`);
  console.log(
    `post-reject-file-count: before=${beforeRejectEntries.length} after=${afterRejectEntries.length}`,
  );

  await fs.rm(tempStateDir, { recursive: true, force: true });
}

main().catch((err: unknown) => {
  console.error(err);
  process.exitCode = 1;
});

AI-assisted: built with Codex

@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, 3:32 AM ET / 07:32 UTC.

ClawSweeper review

What this changes

The branch validates browser-proxy file base64 before decoding or persisting it, with a regression test for malformed payloads.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open for normal maintainer merge review. The focused patch replaces Node’s permissive base64 decode with the shared plugin-SDK validator, retains both pre-decode and post-decode byte-limit checks, and includes convincing live module output showing malformed input is rejected without creating another saved file.

Priority: P2
Reviewed head: 933bb61acf7b5493a85aba261844d6383292f978

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, contract-aligned bug fix with direct live behavior evidence and regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides copied live production-module output showing both a successful valid save and a malformed-input rejection with no additional persisted file; redact private paths or endpoints if future proof is added.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides copied live production-module output showing both a successful valid save and a malformed-input rejection with no additional persisted file; redact private paths or endpoints if future proof is added.
Evidence reviewed 4 items Validation occurs before media persistence: The PR decodes through the shared canonicalizeBase64 helper, throws for malformed input, and only then places decoded buffers into the collection later sent to the media store.
Existing byte-limit invariant remains protected: The helper checks the estimated decoded size before canonicalization and checks the actual decoded buffer size again before returning it, preserving per-file and aggregate limits against both early allocation and decoded output.
Focused regression coverage: The added test supplies malformed base64, expects the explicit rejection message, and verifies that the browser media directory was never created.
Findings None None.
Security None None.

How this fits together

The Browser plugin receives file payloads from a node-hosted browser proxy and persists them as local media before rewriting returned paths. This validation step sits between proxy output and the local media store so corrupted payloads do not become saved screenshots or downloads.

flowchart LR
  A[Node-hosted browser proxy] --> B[Returned file payloads]
  B --> C[Browser proxy file persistence]
  C --> D[Canonical base64 validation]
  D --> E[Byte-limit checks]
  E --> F[Local browser media files]
  F --> G[Rewritten result paths]
Loading

Before merge

  • Complete next step (P2) - No discrete repair is supported by this review; await the remaining routine CI and normal maintainer merge decision.
Agent review details

Security

None.

PR surface

Source +12, Tests +19. Total +31 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 2 +12
Tests 1 19 0 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 33 2 +31

Review metrics

None.

Technical review

Best possible solution:

Merge the narrow validation change once the remaining required checks complete successfully, keeping browser-proxy decoding on the shared media-runtime contract.

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

Yes, from source and the supplied live module transcript: a malformed base64 string reaches the browser-proxy persistence path, while the patch’s negative control shows rejection before another file is written. The pre-fix behavior was not independently run in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the shared media-runtime canonicalizer at the plugin SDK boundary is narrower and more maintainable than adding a browser-specific base64 parser, while retaining the existing size-limit protections.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0216fbd4e491.

Labels

Label changes:

  • add P2: This corrects a bounded browser-proxy data-integrity bug for affected screenshots and downloads without evidence of a broader runtime outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides copied live production-module output showing both a successful valid save and a malformed-input rejection with no additional persisted file; redact private paths or endpoints if future proof is added.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides copied live production-module output showing both a successful valid save and a malformed-input rejection with no additional persisted file; redact private paths or endpoints if future proof is added.

Label justifications:

  • P2: This corrects a bounded browser-proxy data-integrity bug for affected screenshots and downloads without evidence of a broader runtime 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 (live_output): The PR body provides copied live production-module output showing both a successful valid save and a malformed-input rejection with no additional persisted file; redact private paths or endpoints if future proof is added.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides copied live production-module output showing both a successful valid save and a malformed-input rejection with no additional persisted file; redact private paths or endpoints if future proof is added.

Evidence

What I checked:

Likely related people:

  • unknown: The available review environment could not execute the required read-only git history inspection, so no person is selected solely from this PR’s authorship. (role: current-area history unavailable; confidence: low; files: extensions/browser/src/browser/proxy-files.ts, extensions/browser/src/browser/proxy-files.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.

Copy link
Copy Markdown
Contributor

Thanks @sunlit-deng for the focused fix and for correctly reusing the existing media-runtime base64 contract.

I independently reviewed and reproduced this on your original head and found one important compatibility case: canonicalizeBase64("") intentionally returns undefined, but a zero-byte browser download is a valid file. A real-filesystem regression on your original head failed exactly at that case while the remaining malformed-data tests passed.

I have fast-forwarded this original PR branch, preserving your original commit and authorship, to 70715eb3ca922ec4ce8d8279e136c22945fe35b4. The narrow follow-up accepts an exactly empty file while continuing to reject malformed alphabet, bad padding, impossible lengths, nonzero pad bits, and whitespace-only payloads before allocating or writing files. The complete batch is still validated before any valid earlier file can be persisted.

Verification on the exact refreshed head:

  • 78/78 browser proxy, node-host, gateway, and real-filesystem tests pass across 6 test files.
  • Real zero-byte download is actually written and verified at 0 bytes.
  • Valid unpadded and whitespace-normalized files retain their exact contents.
  • Invalid payloads and invalid later files create no browser media directory or partial file.
  • Existing per-file and aggregate limits still pass.
  • Full path-scoped remote pnpm check:changed --base origin/main -- extensions/browser/src/browser/proxy-files.ts extensions/browser/src/browser/proxy-files.test.ts passes, including both typecheck lanes, zero-warning lint, boundaries, guards, deadcode, and import cycles.
  • Fresh independent extra-high-effort review of the complete refreshed PR patch: clean.

Hosted CI for the new head is running; I will wait for the exact head to turn green before proceeding. Thank you again for the original report and implementation.

@steipete
steipete merged commit da8a220 into openclaw:main Jul 29, 2026
89 of 92 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

pull Bot pushed a commit to yann0001/openclaw that referenced this pull request Jul 29, 2026
* origin/main:
  fix(browser): reject malformed proxy file base64 (openclaw#115045)
  fix(sandbox): repair workspace state without crossing agent owners (openclaw#115784)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
* fix(browser): reject malformed proxy file base64

* fix(browser): preserve empty proxy downloads

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
* origin/main:
  fix(browser): reject malformed proxy file base64 (openclaw#115045)
  fix(sandbox): repair workspace state without crossing agent owners (openclaw#115784)
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.

3 participants