fix: use execFileSync for prettier to avoid shell injection (CodeQL #21)#2546
Merged
mcp-commander[bot] merged 1 commit intomainfrom Apr 9, 2026
Merged
Conversation
CodeQL flagged execSync with interpolated file paths as CWE-78/CWE-88 shell injection. The paths are derived from __dirname and SEP filenames, so direct exploitability requires commit access — but paths with spaces or shell metacharacters would still break the command. Replaced execSync template-string interpolation with execFileSync and an args array. Paths are passed as separate process arguments, never touching a shell. The win32 npx.cmd resolution keeps it cross-platform. Fixed both occurrences (lines 395 and 435 had the identical pattern; the alert only flagged 435). Fixes https://github.com/modelcontextprotocol/modelcontextprotocol/security/code-scanning/21 🏠 Remote-Dev: homespace
Contributor
Author
|
/lgtm force Security update |
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.
Fixes https://github.com/modelcontextprotocol/modelcontextprotocol/security/code-scanning/21
CodeQL flagged
execSyncwith interpolated file paths as CWE-78/CWE-88 shell command injection.The issue
The paths are derived from
__dirname+ SEP filenames, so direct exploitability requires commit access toseps/— at which point you could just modify the script directly. But the bug is real:/home/user/my project/docs/seps/foo.mdxbecomes two args);or$()would execute arbitrary commands (the filename regex^(\\d+)-(.+)\\.md$allows anything in.+)The fix
Paths are passed as separate process arguments — never touch a shell. The
process.platform === "win32" ? "npx.cmd" : "npx"resolution keeps it cross-platform.Tested
Fixed both occurrences — line 395 had the identical pattern but the alert only flagged line 435.
Types of changes
Checklist
check:seps+generate:seps)