Skip to content

Escape backslashes in quoteShellArg so pasted hints cannot run commands - #450

Merged
jancurn merged 1 commit into
mainfrom
claude/wizardly-mendel-exv678
Oct 15, 2026
Merged

jancurn merged 1 commit into
mainfrom
claude/wizardly-mendel-exv678

Conversation

@jancurn

@jancurn jancurn commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

quoteShellArg double-quoted server-chosen values (skill names, resource URIs, prompt names) in the run: mcpc ... hints but never escaped a backslash. Inside POSIX double quotes \$(id) therefore rendered as "\\$(id)": a literal backslash followed by a live command substitution, and a trailing backslash escaped the closing quote. A malicious MCP server could make a pasted hint run a command.

  • Escape \ on POSIX alongside ", backtick and $; Windows keeps backslashes as path separators.
  • Unit tests for the reported payloads, plus one that round-trips hostile values through a real sh.
  • Changelog entry under Security.

Fixes GHSA-wmqm-r8wm-9f34

🤖 Generated with Claude Code

https://claude.ai/code/session_01WMAPaE5empDFSAWVKwxmPE

Inside POSIX double quotes a backslash is itself special, so a
server-chosen value like `\$(id)` was rendered as `"\\$(id)"`: a literal
backslash followed by a live command substitution. A trailing backslash
likewise escaped the closing quote. Backslashes are now escaped on POSIX
(Windows keeps them as path separators), with a unit test that round-trips
hostile values through a real shell.

Fixes GHSA-wmqm-r8wm-9f34

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WMAPaE5empDFSAWVKwxmPE
@jancurn jancurn changed the title Fix shell injection vulnerability in quoteShellArg for POSIX systems Escape backslashes in quoteShellArg so pasted hints cannot run commands Oct 15, 2026
@jancurn
jancurn requested a balanced review from Copilot October 15, 2026 21:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow fix addresses the reported injection vectors with targeted regression coverage and no identified blocking issues.

0 open findings

What changed in this PR

Fixes POSIX shell injection in mcpc’s copy-paste hints by escaping backslashes in quoted arguments.

Changes:

  • Escapes POSIX backslashes while preserving Windows behavior.
  • Adds hostile-input regression tests, including real-shell round trips.
  • Documents the security fix.
File Description
test/​unit/​cli/​output.test.ts Tests escaping and literal argument preservation.
src/​cli/​output.ts Escapes backslashes inside POSIX double quotes.
CHANGELOG.md Records the security fix and advisory.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jancurn
jancurn merged commit 9c95f08 into main Oct 15, 2026
8 checks passed
@jancurn
jancurn deleted the claude/wizardly-mendel-exv678 branch October 15, 2026 21:17
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.

4 participants