Description
The Copilot agent caused catastrophic data loss (completely wiping the real WSL /home/user directory) while attempting to run what it thought was a safely sandboxed command.
The issue stems from a fatal interaction between how the Agent structures inline bash commands and how Windows/PowerShell passes arguments to wsl.exe. When the agent attempts to isolate destructive commands (like rm -rf "$HOME") using an inline string, the quoting fails during the transit between the Windows host and the WSL guest.
Steps to Reproduce
- On a Windows 11 host with VS Code and WSL 2 enabled.
- Engage the Copilot agent in a task that involves temporary WSL operations.
- The agent attempts to sandbox a command using the following pattern:
wsl bash -lc 'set -euo pipefail; export HOME=/tmp/repro_env; rm -rf "$HOME/test_dir"; mkdir -p "$HOME/test_dir2"'
- The Failure: Observe that even though
$HOME is exported to /tmp/repro_env in the same line, the rm -rf command targets the user's actual home directory (/home/username/test_dir).
Technical Analysis
The vulnerability is a Sandbox Escape via Quoting Corruption.
When a command wrapped in single quotes ('...') is passed from a Windows shell (like PowerShell or the VS Code terminal runner) to a native executable (wsl.exe), the Windows execution context often strips the outer single quotes and attempts to re-wrap arguments in double quotes for the CreateProcess Win32 API.
This process fails to escape internal double quotes (like those in "$HOME"). Consequently, the bash shell inside WSL receives a fragmented string where $HOME is evaluated against the pre-existing environment (the real home) before the inline export command can take effect or isolate the scope.
Impact
- Data Loss: Irreversible deletion of files in the WSL home directory.
- Security Risk: Deletion of sensitive configurations, SSH keys, and uncommitted source code.
Environment
- Copilot Chat Extension Version: 0.47.1
- VS Code Version: 1.119.1
- OS Version: Windows 11 (Build 10.0.26200.0)
- Feature: agent
- Selected model: GPT-5.4
Suggested Mitigation / Guardrail
Agents must be strictly prohibited from using inline shell execution (wsl bash -lc '...') for complex or destructive strings across the Windows-WSL boundary.
Safe Pattern: The agent should write the payload to a temporary .sh file on the Windows host and execute it via:
wsl bash /mnt/c/path/to/temp_script.sh
Description
The Copilot agent caused catastrophic data loss (completely wiping the real WSL
/home/userdirectory) while attempting to run what it thought was a safely sandboxed command.The issue stems from a fatal interaction between how the Agent structures inline bash commands and how Windows/PowerShell passes arguments to
wsl.exe. When the agent attempts to isolate destructive commands (likerm -rf "$HOME") using an inline string, the quoting fails during the transit between the Windows host and the WSL guest.Steps to Reproduce
wsl bash -lc 'set -euo pipefail; export HOME=/tmp/repro_env; rm -rf "$HOME/test_dir"; mkdir -p "$HOME/test_dir2"'$HOMEis exported to/tmp/repro_envin the same line, therm -rfcommand targets the user's actual home directory (/home/username/test_dir).Technical Analysis
The vulnerability is a Sandbox Escape via Quoting Corruption.
When a command wrapped in single quotes (
'...') is passed from a Windows shell (like PowerShell or the VS Code terminal runner) to a native executable (wsl.exe), the Windows execution context often strips the outer single quotes and attempts to re-wrap arguments in double quotes for theCreateProcessWin32 API.This process fails to escape internal double quotes (like those in
"$HOME"). Consequently, the bash shell inside WSL receives a fragmented string where$HOMEis evaluated against the pre-existing environment (the real home) before the inlineexportcommand can take effect or isolate the scope.Impact
Environment
Suggested Mitigation / Guardrail
Agents must be strictly prohibited from using inline shell execution (
wsl bash -lc '...') for complex or destructive strings across the Windows-WSL boundary.Safe Pattern: The agent should write the payload to a temporary
.shfile on the Windows host and execute it via: