fix(codegen): sanitize JSDoc strings and add package.json to generated output#91
Merged
Conversation
bug-ops
enabled auto-merge (squash)
May 3, 2026 13:03
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## master #91 +/- ##
==========================================
+ Coverage 88.97% 89.03% +0.06%
==========================================
Files 33 33
Lines 7708 7751 +43
==========================================
+ Hits 6858 6901 +43
Misses 850 850
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
…d output Closes #87: server-controlled strings (name, version, tool name, tool description) are now sanitized before interpolation into JSDoc block comments. The sanitizer replaces "*/" with "*\/", strips CR/LF, and truncates to 256 chars for name/description and 64 chars for version. Closes #86: ProgressiveGenerator::generate() and generate_with_categories() now emit package.json with {"type":"module"} in the server output root, eliminating the Node.js MODULE_TYPELESS_PACKAGE_JSON performance warning on every tool execution.
bug-ops
force-pushed
the
87-86-codegen-sanitize
branch
from
May 3, 2026 13:12
e7dc0b5 to
00cf31d
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.
Summary
name,version, toolname, tooldescription) being interpolated verbatim into JSDoc block comments, allowing malicious MCP servers to inject arbitrary TypeScript via*/sequences (codegen: server-controlled strings interpolated into JSDoc comments without sanitizing comment terminator #87)package.jsonwith{"type":"module"}to generated server output directory, eliminating the Node.jsMODULE_TYPELESS_PACKAGE_JSONperformance warning on every tool execution (generate: missing package.json in output directory causes Node.js ES module warning on every tool execution #86)Changes
crates/mcp-codegen/src/progressive/generator.rssanitize_jsdoc(s: &str, max_len: usize) -> String— replaces*/with*\/, strips CR/LF, truncates tomax_lencharscreate_tool_context(toolname,description) andcreate_index_context(server_name,server_version, each tooldescription)package.jsongeneration ingenerate()andgenerate_with_categories()test_sanitize_jsdoc_*(4 cases) andtest_generate_sanitizes_jsdoc_injectiontest_generate_progressive_filesto expect 5 filescrates/mcp-codegen/tests/progressive_generation.rspackage.jsonassertionsTest plan
cargo +stable clippy --all-targets --all-features --workspace -- -D warnings— cleancargo nextest run --all-features --workspace --no-fail-fast— 641 passedcargo test --doc --all-features --workspace— 9 passedcargo +nightly fmt --check— cleanCloses #87
Closes #86