VSCode Remote Code Execution advisory
An undocumented VS Code setting allowed an untrusted workspace to specify a URL for experiments, which could display a prompt that installs an attacker-controlled extension, leading to remote code execution. The attacker could also steal OAuth tokens on github.dev.
Published on blog.ammaraskar.com
tl;dr I found a remote code execution bug in VSCode that can be triggered from untrusted workspaces. Microsoft fixed it but marked it as moderate severity and ineligible under their bug bounty program.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the setting '_workbench.experimentsUrl' was not registered with the configuration service, so it was not marked as restricted and could be set in an untrusted workspace.
Impact
An attacker could execute arbitrary code on the victim's machine after they open a malicious folder and interact with a prompt; on github.dev, this could also lead to theft of an OAuth token with repo scope.
What the attacker needed
Victim opens a malicious folder in VS Code; victim clicks on the prompt
The fix
The bug was fixed in a VS Code commit on May 24, 2023.
How it was found
- Create a .vscode/settings.json file that sets the experiments URL to an attacker-controlled location.
- Host a malicious experiments.json file at that URL containing a prompt with a codeCommand that installs an extension.
- Open the folder in VS Code; a prompt appears with attacker-controlled text and buttons.
- Click the prompt text or the button to trigger the command, which installs the attacker's extension.
- The installed extension runs arbitrary code using Node.js APIs.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
VS Code has a feature called Workspace Trust that asks if you trust the files in a folder. If you say no, it disables features that could run code automatically. The researcher found a hidden setting that was not protected by this trust check, so a malicious folder could make VS Code download a fake experiment that tricks you into installing a bad extension, which can then run any command on your computer.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.