Skip to content

fix(tool_def): bound aggregate JSON flag coercion#1598

Merged
chaliy merged 1 commit intomainfrom
2026-05-08-propose-fix-for-json-flag-coercion-vulnerability
May 8, 2026
Merged

fix(tool_def): bound aggregate JSON flag coercion#1598
chaliy merged 1 commit intomainfrom
2026-05-08-propose-fix-for-json-flag-coercion-vulnerability

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 8, 2026

Motivation

  • Parsing attacker-controlled JSON for array/object-typed flags eagerly called serde_json::from_str and could expand a small input token into a very large serde_json::Value tree, bypassing Bashkit memory accounting and allowing an availability attack.

Description

  • Add MAX_AGGREGATE_FLAG_JSON_BYTES = 64 * 1024 to cap eager aggregate JSON coercion in crates/bashkit/src/tool_def.rs.
  • Introduce helper parse_aggregate_json_value(raw: &str) -> Option<serde_json::Value> which returns None when the raw byte length exceeds the cap and otherwise attempts serde_json::from_str.
  • Route aggregate parsing through the helper in coerce_value, consume_array_value, and object-consumption paths so oversized JSON falls back to the existing raw-string behavior instead of being eagerly materialized.
  • Add regression test test_parse_flags_large_json_array_stays_string asserting oversized JSON arrays are preserved as strings (so downstream serde/schema validation still produces type errors without unbounded allocation).

Testing

  • Ran unit tests for the modified module with cargo test --lib tool_def, and the tool_def test suite passed (tests covering array/object coercion and the new regression test all succeeded).

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 8, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 12b0e69 Commit Preview URL May 08 2026, 09:08 AM

@chaliy chaliy force-pushed the 2026-05-08-propose-fix-for-json-flag-coercion-vulnerability branch from b56e4b2 to 12b0e69 Compare May 8, 2026 09:08
@chaliy chaliy merged commit 53f32bb into main May 8, 2026
34 checks passed
@chaliy chaliy deleted the 2026-05-08-propose-fix-for-json-flag-coercion-vulnerability branch May 8, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant