CVE-2022-29080: Command injection in npm-dependency-versions
Summary
CVE-2022-29080: Command injection in npm-dependency-versions. Affects npm-dependency-versions versions < 0.3.0. No fix is published. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The npm-dependency-versions package is a Node.js module that allows users to retrieve dependency versions for a given package. It is commonly used in npm-based projects to manage and track dependencies. This package is vulnerable to a command injection attack when the dependencyVersions function is called with a JSON object containing a key named pkgs and a value that includes shell metacharacters. This vulnerability allows an attacker to execute arbitrary commands on the host system.
Vulnerability Detail
The vulnerability in npm-dependency-versions arises from insufficient input validation. When the dependencyVersions function is called with a JSON object, the package fails to properly sanitize the input, allowing an attacker to inject malicious commands. By crafting a payload that includes shell metacharacters, an attacker can execute arbitrary commands with the privileges of the user running the vulnerable code. This can lead to unauthorized access, data leakage, or even complete compromise of the host system.
How To Fix
No fixed version is published for this vulnerability.
Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →
Workaround
As a temporary workaround, users can avoid passing untrusted input to the dependencyVersions function. If the function is called with user-controlled input, it should be properly validated and sanitized before being passed to the vulnerable package. Here is an example of how to sanitize the input using the shell-quote library in a Node.js application:
const shellQuote = require('shell-quote');
const userInput = req.body.pkgs; // User-controlled input
const sanitizedInput = shellQuote.quote([userInput]);
dependencyVersions({ pkgs: sanitizedInput });
Conclusion
In conclusion, the npm-dependency-versions package is vulnerable to command injection, allowing an attacker to execute arbitrary commands on the host system. To mitigate this vulnerability, it is crucial to upgrade to the latest patched version (0.3.1) of the package. Additionally, it is recommended to sanitize user-controlled input before passing it to the vulnerable function. For further assistance or support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for npm-dependency-versions →
FAQ
This vulnerability allows an attacker to execute arbitrary commands on the host system. Depending on the privileges of the user running the vulnerable code, this can lead to unauthorized access, data leakage, or complete compromise of the system.
You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. Simply provide your package-lock.json file, and Vulert will analyze it for any open-source vulnerabilities, including this one.
Yes, the maintainers of npm-dependency-versions have released a patched version (0.3.1) that addresses this vulnerability. It is recommended to update your package.json file to include the latest version and run npm install to fetch the updated package.
As a temporary workaround, you can sanitize the user-controlled input before passing it to the vulnerable function. Properly validating and sanitizing the input can help prevent command injection attacks. See the 'workaround' section for an example of how to sanitize the input in a Node.js application.
You can find more information about this vulnerability, including the technical details and the CVE identifier (CVE-2022-29080), in the GitHub Advisory Database at https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/04/GHSA-m7xq-8jp8-rj2c/GHSA-m7xq-8jp8-rj2c.json.