Repository navigation
Conversation
… injection Fixes mediar-ai#479 working_directory was interpolated into a single-quoted shell fragment (cd '<cwd>' && <cmd>) without escaping quote characters, allowing a caller-controlled path to close the quote and append arbitrary shell commands. - Unix shells: escape single quotes as '\'' (close, escaped, reopen) - PowerShell: double single quotes ('') - cmd.exe: strip double quotes (legal Windows paths cannot contain them) Added unit tests for the new escape_cwd_single_quotes helper.
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
Fixes #479 —
working_directoryallows shell command injection inrun_command.The
working_directoryargument was interpolated into a single-quoted shell fragment (cd '<cwd>' && <cmd>) without escaping quote characters. A caller-controlled path containing a single quote could close thecdargument early and append arbitrary shell commands.Changes
escape_cwd_single_quotes()helper interminator-rs(shared by both call sites)'\''(close-quote, escaped-quote, reopen)powershell/pwsh): single quotes doubled ('')cmd.exe: double quotes stripped from the path (legal Windows paths cannot contain", so this only affects malicious input and neutralizes it)Desktop::run()(crates/terminator/src/lib.rs) and the MCPrun_commandhandler (crates/terminator-mcp-agent/src/server.rs)Verification
cargo check -p terminator-rs✅cargo check -p terminator-mcp-agent✅cargo test -p terminator-rs --lib escape_cwd_tests✅ 2/2 passed/tmp/a'b→/tmp/a'\''b)C:\a'b→C:\a''b)Notes
cmd.exebranch already wrapped the path in double quotes; stripping embedded"preserves that for all legal Windows paths.