Skip to content

feat: expose maxMemory option to prevent OOM from untrusted input#1075

Merged
chaliy merged 1 commit intomainfrom
claude/process-issue-1072-4hJtv
Apr 6, 2026
Merged

feat: expose maxMemory option to prevent OOM from untrusted input#1075
chaliy merged 1 commit intomainfrom
claude/process-issue-1072-4hJtv

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 5, 2026

Summary

  • Adds BashBuilder::max_memory(bytes) convenience method in the Rust core that caps max_total_variable_bytes and clamps max_function_body_bytes, preventing OOM from untrusted input like exponential string doubling
  • JS bindings: BashOptions.maxMemory (number, bytes) on Bash and BashTool
  • Python bindings: max_memory (int, bytes) on Bash and BashTool
  • The underlying MemoryLimits + MemoryBudget enforcement already existed — this change exposes the knob through all public APIs

Test plan

  • Rust unit test: test_max_memory_caps_string_growth — verifies 25 doublings of 10-byte string capped at ≤1024 bytes
  • Rust doctest: BashBuilder::max_memory example compiles and runs
  • JS security tests (5 new, 104 total): exponential doubling cap, small scripts within budget, recovery after limit, BashTool enforcement, default limit behavior
  • cargo test -p bashkit --lib — 2020 tests pass
  • cargo fmt --check — clean
  • ruff check + ruff format --check — Python lint clean
  • CI green

Closes #1072

@chaliy chaliy force-pushed the claude/process-issue-1072-4hJtv branch from 8aa0e4e to 40f7bf6 Compare April 6, 2026 00:16
@chaliy chaliy changed the title feat(js): expose maxMemory option to prevent OOM feat: expose maxMemory option to prevent OOM from untrusted input Apr 6, 2026
Adds `BashBuilder::max_memory(bytes)` in the Rust core that caps
`max_total_variable_bytes` and clamps `max_function_body_bytes`.
Exposed through JS bindings (`maxMemory`) and Python bindings
(`max_memory`) on both `Bash` and `BashTool` classes.

Includes Rust unit test + doctest and 5 JS security tests.

Closes #1072
@chaliy chaliy force-pushed the claude/process-issue-1072-4hJtv branch from 40f7bf6 to 4934d80 Compare April 6, 2026 00:40
@chaliy chaliy merged commit 4563ab5 into main Apr 6, 2026
27 checks passed
@chaliy chaliy deleted the claude/process-issue-1072-4hJtv branch April 6, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS bindings: expose memory limit to prevent OOM from untrusted input

1 participant