# Drag and Pwnd: Leverage ASCII characters to exploit VS Code

Control characters (SOH, ETX, CR) in VS Code run-config args and drag-dropped filenames are interpreted by node-pty/readline, enabling command injection.

- Payout: Research
- Severity: medium
- Program: Microsoft
- Write-up by: PortSwigger Research
- Disclosed: 2025-04-30
- Write-up quality: 7/10
- Original: https://portswigger.net/research/drag-and-pwnd-leverage-ascii-characters-to-exploit-vs-code
- Library page: https://bugbountylibrary.com/r/blog%3Aportswigger-net-research-drag-and-pwnd-leverage-ascii-characters-to-exploit-vs-code
- Tags: area:os domain:desktop impact:rce kind:research platform:research sev:medium tech:nodejs technique:source-review vuln:command-injection

**Target:** VS Code run configurations and terminal drag-and-drop (node-pty)
**Root cause:** node-pty forwards raw bytes to the shell/readline, which interprets ASCII control characters (SOH=cursor-to-start, ETX=interrupt, CR=execute) as line-editing commands, letting attacker-controlled args or filenames break out and run commands.
**Steps:**
1. Craft run config args containing `\u0001` (SOH) to move cursor to line start and build a payload in reverse: `{"args": ["hello","\u0001\t--args\u0001\tCalculator\u0001\t-a\u0001open\t"]}`
2. Launch the config; VS Code opens Calculator instead of running the script
3. Alternatively name a file `very very very long name \x03 open -a Calculator \x0d.txt`
4. Drag-and-drop the file into the VS Code terminal; ETX interrupts the line, CR executes `open -a Calculator`
**How found:** Prior OS command injection research on VS Code run configs led to noticing that SOH (Ctrl+A) is interpreted by readline as cursor-to-line-start; testing showed control chars in args and filenames get interpreted by node-pty's shell, enabling payload construction in reverse.
**Exploitation:** Attacker supplies a malicious run configuration or a file with control characters in its name; when the victim runs the config or drags the file into the terminal, node-pty passes raw bytes to the shell and the embedded command executes.
**Insight:** When auditing terminal-embedding apps (node-pty, xterm.js), test ASCII control characters (SOH/STX/ETX/EOT/CR) in any user-controlled string reaching the PTY—args, filenames, pasted text—since readline repurposes them as editing commands that can reorder and execute injected text.

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

**Malicious VS Code run configuration args payload**

```
{"args": ["hello","\u0001\t--args\u0001\tCalculator\u0001\t-a\u0001open\t"]}
```

**Malicious filename for drag-and-drop terminal injection**

```
very very very long name \x03 open -a Calculator \x0d.txt
```

