mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-24 05:43:51 +00:00
fix(security): escape backslashes and cmd metacharacters in hook executor
Backslashes were not escaped before double-quotes in the PowerShell command wrapper, so paths like C:\foo\" would terminate the string early and allow injection. cmd /c wrapper had no escaping at all. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9062273ef5
commit
315e29a2d1
1 changed files with 6 additions and 2 deletions
|
|
@ -71,9 +71,13 @@ async function executeCommandHook(
|
|||
|
||||
// Wrap command for different shells
|
||||
if (shell === "powershell") {
|
||||
command = `powershell -Command "${command.replace(/"/g, '\\"')}"`
|
||||
// Escape backslashes first, then double-quotes, to prevent shell injection
|
||||
const escaped = command.replace(/\\/g, "\\\\").replace(/"/g, '\\"')
|
||||
command = `powershell -Command "${escaped}"`
|
||||
} else if (shell === "cmd") {
|
||||
command = `cmd /c "${command}"`
|
||||
// Escape % (variable expansion) and ^ (cmd escape char) to prevent injection
|
||||
const escaped = command.replace(/\^/g, "^^").replace(/%/g, "%%")
|
||||
command = `cmd /c "${escaped}"`
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue