Skip to content
RCE Write-up Intermediate

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.

Ammar Askar Follow

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.

Ammar Askar, on blog.ammaraskar.com

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

  1. Create a .vscode/settings.json file that sets the experiments URL to an attacker-controlled location.
  2. Host a malicious experiments.json file at that URL containing a prompt with a codeCommand that installs an extension.
  3. Open the folder in VS Code; a prompt appears with attacker-controlled text and buttons.
  4. Click the prompt text or the button to trigger the command, which installs the attacker's extension.
  5. 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.

More by Ammar Askar

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.