# Don't Clone That Repo: Visual Studio Code^2 Execution

VS Code Python extension auto-activates a virtualenv path from a repo's .vscode/settings.json, so opening a Python file in a cloned repo executes attacker code.

- Payout: Research
- Severity: high
- Program: Microsoft
- Write-up by: Doyensec
- Disclosed: 2020-03-15
- Write-up quality: 7/10
- Original: https://blog.doyensec.com/2020/03/16/vscode_codeexec.html
- Library page: https://bugbountylibrary.com/r/blog%3Ablog-doyensec-com-2020-03-16-vscode-codeexec-html
- Tags: area:os domain:desktop impact:rce kind:research platform:research sev:high tech:python technique:source-review vuln:misconfiguration vuln:rce

**Target:** VS Code Python extension virtualenv selection
**Root cause:** The Python extension reads python.pythonPath from a repo's .vscode/settings.json and activates that virtualenv without user confirmation, executing its interpreter/scripts.
**Steps:**
1. Clone a repo containing .vscode/settings.json pointing python.pythonPath at a bundled virtualenv folder
2. Add the cloned repo to the VS Code workspace
3. Open test.py in the editor
4. Extension activates the attacker-controlled virtualenv, executing code (PoC spawns Calculator.app)
**How found:** While reviewing a client Python app, a pylint warning persisted after installing pylint; noticing 'venv-test' auto-selected in the status bar led to the hypothesis that the project's virtualenv was auto-activated, confirmed by adding os.exec to pylint source.
**Exploitation:** Attacker ships a repo with a hidden virtualenv and a .vscode/settings.json selecting it; victim clones, adds to workspace, and opens any Python file, triggering execution of attacker-controlled interpreter code.
**Insight:** Editor/IDE extensions that auto-detect and activate project-local environments (venvs, node_modules, tool configs) from repo files are code-execution vectors; check whether workspace settings like python.pythonPath are trusted without prompting.

## Proof of concept (copied exactly from the original report)

**PoC repo clone and open steps**

```
1) git clone git@github.com:doyensec/VSCode_PoC_Oct2019.git
 
- 2) add the cloned repo to the VSCode workspace
 
- 3) open test.py in VScode
```

