feat(chain): cap JSON-RPC response size before lowering into the guest#309
Open
lgahdl wants to merge 1 commit into
Open
feat(chain): cap JSON-RPC response size before lowering into the guest#309lgahdl wants to merge 1 commit into
lgahdl wants to merge 1 commit into
Conversation
a8bb9ba to
4acf3ed
Compare
#154) Adds a configurable `[limits.chain] response_max_bytes` knob (default 1 MiB) that is enforced host-side in `chain::request()` before the response string is copied into the guest heap. Oversized responses are rejected with an `InvalidInput` fault, a `WARN` log, and a dedicated `shepherd_chain_response_capped_total` metric. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TfSsJPYDQ1GQGbnSVFxATx
4acf3ed to
fa79d01
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #154
What
Adds a host-side cap on chain JSON-RPC response bodies so a misbehaving or adversarial node cannot saturate the guest heap via a single large reply.
Changes
engine_config.rs: New[limits.chain]TOML section with aresponse_max_bytesknob (default 1 MiB). Resolver methodModuleLimits::chain_response_max_bytes().host/state.rs:HostStategainschain_response_max_bytes: usize— threaded from config at boot and preserved across restarts.supervisor.rs: Field threaded throughLoadedModule→build_store()→HostStateconstruction, at both initial boot and reinstantiation.host/impls/chain.rs:request()appliescheck_response_cap()after receiving the provider response. Rejection emits aWARNlog, increments a dedicatedshepherd_chain_response_capped_totalmetric, and returnsChainError::Fault(InvalidInput). Batch requests inherit the cap via the per-entryrequest()dispatch path.Tests
Two new unit tests in
host::impls::chain::tests:response_at_cap_is_accepted— body exactly at the cap passesresponse_over_cap_returns_invalid_input— body one byte over the cap returnsInvalidInputConfig
🤖 Generated with Claude Code
https://claude.ai/code/session_01TfSsJPYDQ1GQGbnSVFxATx