Skip to content

fix(fal): bound JSON response reads to prevent OOM#96321

Closed
lsr911 wants to merge 2 commits into
openclaw:mainfrom
lsr911:fix/fal-bounded-json-response
Closed

fix(fal): bound JSON response reads to prevent OOM#96321
lsr911 wants to merge 2 commits into
openclaw:mainfrom
lsr911:fix/fal-bounded-json-response

Conversation

@lsr911

@lsr911 lsr911 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Replace unbounded await response.json() with readResponseWithLimit (1 MiB cap)
in fal video/music/image generation providers — the symmetric counterpart to the
bound-stream work already merged for OpenRouter (#95420, #95418), Google (#95417),
provider-http (#95218), and other modules.

A malicious or faulty fal API endpoint returning an oversized JSON response body
would previously buffer the entire body in memory before parsing.
readResponseWithLimit cancels the stream once the cap is reached, preventing
unbounded buffering. These modules already use readResponseWithLimit for
video/image downloads, but the JSON API response paths were still unbounded.

Evidence

Summary

Bound 3 unbounded JSON response reads in fal video/music/image generation
providers with 1 MiB cap.

Changes

  • extensions/fal/video-generation-provider.ts — bound fetchFalJson (central
    JSON fetcher covering queue submit, status polling, and result retrieval)
  • extensions/fal/music-generation-provider.ts — bound generateMusic JSON
    response read
  • extensions/fal/image-generation-provider.ts — bound generateImage JSON
    response read
  • extensions/fal/video-generation-provider.test.ts — updated releasedJson
    helper and non-JSON mock to include arrayBuffer() for readResponseWithLimit
  • extensions/fal/music-generation-provider.test.ts — added makeJsonResponse
    helper providing arrayBuffer() on mock Response objects

@clawsweeper

clawsweeper Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the fal hardening target is valid, but this PR is not merge-ready because it reimplements the existing shared provider JSON reader, adds new fail-closed 1 MiB success-response caps without fal payload-size proof, and still lacks contributor real behavior proof.

Canonical path: Close this PR as superseded by #96495.

So I’m closing this here and keeping the remaining discussion on #96495.

Review details

Best possible solution:

Close this PR as superseded by #96495.

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

Yes. Current main calls await response.json() on fal image, music, and video success responses, so oversized streamed 200 OK bodies would be drained before parsing; I did not run a live fal request or local harness in this read-only review.

Is this the best way to solve the issue?

No, not as written. Bounding the reads is the right direction, but the best OpenClaw shape is to route through the existing provider JSON helper instead of creating a second inline JSON-reader policy in fal.

Security review:

Security review cleared: The diff hardens untrusted provider response reads and adds no dependencies, workflow permissions, secret handling, or downloaded-code execution surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • linked superseding PR: fix(image-gen): bound image generation provider JSON response reads #96495 (fix(image-gen): bound image generation provider JSON response reads) is still open as the canonical replacement.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • vincentkoc: Merged fal image-generation provider support in Image generation: add fal provider #49454, which established the fal provider surface involved in this hardening follow-up. (role: fal provider feature introducer; confidence: medium; commits: 6710a2be61f8; files: extensions/fal/image-generation-provider.ts, extensions/fal/openclaw.plugin.json)
  • Alix-007: Authored the merged provider JSON response-limit PR that added the shared readProviderJsonResponse behavior this fal PR should reuse. (role: adjacent shared-helper contributor; confidence: high; commits: 2592f8a51a4e; files: src/agents/provider-http-errors.ts, src/agents/provider-http-errors.test.ts)
  • joshavant: Authored current-main commit 0a14444924e34e031133c997b00d30573353c5a0, which recently maintained provider response helper exports in the same shared area. (role: recent shared response-reader contributor; confidence: medium; commits: 0a14444924e3; files: src/agents/provider-http-errors.ts, src/plugin-sdk/provider-http.ts)

Codex review notes: model internal, reasoning high; reviewed against 643410c1f3c0.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 24, 2026
Replace unbounded await response.json() with readResponseWithLimit
(1 MiB cap) in video/music/image generation providers.

A malicious or faulty fal API endpoint returning an oversized JSON
response body would previously buffer the entire body in memory before
parsing.  readResponseWithLimit cancels the stream once the cap is
reached, preventing unbounded buffering.

- video-generation-provider: bound fetchFalJson (central JSON fetcher)
- music-generation-provider: bound generateMusic response read
- image-generation-provider: bound generateImage response read

Each path uses 1 MiB cap — fal JSON API responses (queue status,
model results) are small metadata payloads.

Co-Authored-By: Claude <[email protected]>
@lsr911

lsr911 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Closing to bring open PR count within fixer limit; remaining bound-JSON PRs cover the same pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: fal merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant