fix(codegen,core): close DoS and charset gaps in generated bridge validator - #485
Merged
Conversation
…idator The generated TypeScript runtime bridge mirrored the Rust command validator's injection checks but omitted its DoS size/count ceilings entirely, and validateEnvName lacked the ASCII-charset restriction its Rust counterpart already enforced. Both gaps let a config edited after generation reach spawn() with unbounded argv/env/headers or a Unicode-ambiguous env name. Render the size/count constants and charset pattern from mcp-execution-core into BridgeContext instead of hand-copying them, so the generated checks cannot silently drift from their Rust source of truth again. Reject non-string and non-object env/header values outright rather than skipping their length checks. Closes #471, #467
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.
Summary
MAX_ARG_COUNT,MAX_ARG_LEN,MAX_ENV_COUNT,MAX_ENV_VALUE_LEN,MAX_URL_LEN,MAX_HEADER_COUNT,MAX_HEADER_VALUE_LEN) frommcp-execution-coreintoBridgeContextand enforce them in the generated TypeScript runtime bridge, mirroringvalidate_stdio_size_bounds/validate_network_size_boundsand their ordering ahead of injection-specific checks.[A-Za-z_][A-Za-z0-9_]*charset restriction fromvalidate_env_nameinto the generated bridge'svalidateEnvName, rendered from a shared pattern (escaped viasanitize_ts_string_literal) instead of hand-copied.env/headersfields outright at the bridge boundary, closing the CWE-400 gap where a config edited after generation could bypass the new ceilings entirely.Fixes
Closes #471, closes #467
Test plan
cargo +nightly fmt --checkcargo clippy --all-targets --all-features --workspace -- -D warningscargo nextest run --all-features --workspace --no-fail-fast(1397 passed)cargo test --doc --all-features --workspaceRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace)tsc --noEmit --strict, real spawn-path assertions), including boundary/at-cap and multi-byte UTF-8 cases