Skip to content

[Bug] Incomplete Sanitization in conversationFeature.ts: Double-Escaping Bug Allows Shell Argument Injection in Git Commit Message #316996

@programsurf

Description

@programsurf

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

node poc.js

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

  1. Clone Visual Studio Code at commit 39e6e45
  2. Navigate to extensions/copilot/src/extension/conversation/vscode-node/conversationFeature.ts
  3. Observe line 251: commitMessage.replace(/"/g, '\\"').replace(/\\/g, '\\\\')
  4. Provide a commit message containing " (e.g., test" --flag injected): step 1 yields test\", step 2 re-escapes \ to \\, yielding test\\".
  5. 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)

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions