Visual Studio Code Security: Finding New Vulnerabilities in the NPM Integration (3/3)
The npm integration in Visual Studio Code passed package names from a project's package.json file to the npm command without proper validation, allowing an attacker to inject arguments or a local npm configuration file. This could lead to arbitrary command execution on the victim's system, even in untrusted workspaces.
Published on sonarsource.com
Welcome back to our series on the security of Visual Studio Code! We strongly encourage you reading first Visual Studio Code Security: Deep Dive into Your Favorite Editor (1/3) to refresh your memory on the most common types of vulnerabilities in Visual Studio Code as it will come in very handy today.
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
The npm integration did not properly validate package names before passing them to the npm command, allowing argument injection and loading of local configuration files.
Impact
An attacker could execute arbitrary commands on the victim's system, but practical exploitation is limited because dangerous npm configuration options like onload-script were removed in npm v7, though older versions like npm 6.14.4 on Ubuntu 20.04.6 TLS still process it.
What the attacker needed
Victim opens a malicious project in VS Code; Victim hovers over a dependency name; VS Code version before 1.82.1
The fix
Microsoft patched the argument injection by tightening package name validation and adding the end-of-options argument, and mitigated the local configuration file issue by only enabling the extension in trusted workspaces.
How it was found
- Open a malicious project in Visual Studio Code that contains a crafted package.json file.
- Hover over a dependency name in the package.json file to trigger the npm view command.
- The npm view command is executed with the malicious package name, leading to argument injection or loading of a local .npmrc file.
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.
Visual Studio Code is a popular code editor. It has a built-in feature that shows information about npm packages when you hover over a package name in a package.json file. The problem was that the package name was not properly checked before being used in a command, so a malicious package.json could trick the editor into running harmful commands 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.