BUG DESCRIPTION
Summary
The Copilot extension's conversationFeature.ts sanitizes a generated commit message before embedding it in a git commit -m "..." shell command, but applies the double-quote escape before the backslash escape; this ordering bug causes " characters to become \\" in the final shell string, which a shell parser interprets as an escaped backslash followed by a closing quote, splitting the -m argument and enabling shell argument injection. This finding is tagged known-accepted by the project team (inline CodeQL suppression [SM02383] Backslashes are escaped as part of the second replace). Reporting for awareness and potential hardening.
Details
Affected file: extensions/copilot/src/extension/conversation/vscode-node/conversationFeature.ts
Line: 251
Commit: 39e6e45
The sanitization at line 251 applies replace(/"/g, '\\"') first, then replace(/\\/g, '\\\\'). Step 2 re-escapes the \ introduced by step 1, turning \" into \\". In a double-quoted shell string, \\" means an escaped backslash followed by a closing quote, so the message argument closes early and the remaining content becomes additional shell tokens.
Proof of Concept
The PoC replicates the two-step sanitization, constructs the resulting shell command string, and uses a minimal shell-argument parser to verify that a commit message containing " produces more than four shell tokens, confirming argument splitting.
reproduce.zip
Impact
An attacker who can influence a repository such that Copilot generates a commit message containing " characters could inject additional shell arguments into the git commit command sent to the user's VS Code terminal. Exploitation requires user interaction and local access context. Impact is limited to the user's local terminal session.
STEPS TO REPRODUCE
- Clone Visual Studio Code at commit 39e6e45
- Navigate to
extensions/copilot/src/extension/conversation/vscode-node/conversationFeature.ts
- Observe line 251:
commitMessage.replace(/"/g, '\\"').replace(/\\/g, '\\\\')
- Provide a commit message containing
" (e.g., test" --flag injected): step 1 yields test\", step 2 re-escapes \ to \\, yielding test\\".
- The shell command
git commit -m "test\\"--flag injected" is parsed as more than four arguments, confirming injection.
SECURITY IMPACT
Product: Visual Studio Code
Version: 1.121.0
Component: extensions/copilot (Copilot extension — conversationFeature)
BUG DESCRIPTION
Summary
The Copilot extension's
conversationFeature.tssanitizes a generated commit message before embedding it in agit commit -m "..."shell command, but applies the double-quote escape before the backslash escape; this ordering bug causes"characters to become\\"in the final shell string, which a shell parser interprets as an escaped backslash followed by a closing quote, splitting the-margument and enabling shell argument injection. This finding is taggedknown-acceptedby the project team (inline CodeQL suppression[SM02383] Backslashes are escaped as part of the second replace). Reporting for awareness and potential hardening.Details
Affected file:
extensions/copilot/src/extension/conversation/vscode-node/conversationFeature.tsLine: 251
Commit: 39e6e45
The sanitization at line 251 applies
replace(/"/g, '\\"')first, thenreplace(/\\/g, '\\\\'). Step 2 re-escapes the\introduced by step 1, turning\"into\\". In a double-quoted shell string,\\"means an escaped backslash followed by a closing quote, so the message argument closes early and the remaining content becomes additional shell tokens.Proof of Concept
The PoC replicates the two-step sanitization, constructs the resulting shell command string, and uses a minimal shell-argument parser to verify that a commit message containing
"produces more than four shell tokens, confirming argument splitting.reproduce.zip
Impact
An attacker who can influence a repository such that Copilot generates a commit message containing
"characters could inject additional shell arguments into thegit commitcommand sent to the user's VS Code terminal. Exploitation requires user interaction and local access context. Impact is limited to the user's local terminal session.STEPS TO REPRODUCE
extensions/copilot/src/extension/conversation/vscode-node/conversationFeature.tscommitMessage.replace(/"/g, '\\"').replace(/\\/g, '\\\\')"(e.g.,test" --flag injected): step 1 yieldstest\", step 2 re-escapes\to\\, yieldingtest\\".git commit -m "test\\"--flag injected"is parsed as more than four arguments, confirming injection.SECURITY IMPACT
Product: Visual Studio Code
Version: 1.121.0
Component: extensions/copilot (Copilot extension — conversationFeature)