The npm CLI tool has a very convenient and effective mechanism for protecting against vulnerable packages - automatic package verification during installation (using npm install), which can be run manually using the npm audit command. However, researchers at JFrog found that this protection mechanism can be easily bypassed by adding a hyphen to the package version (for example, 1.2.3-a), which is usually used to indicate a pre-release package. This is because the Bulk Advisory endpoint is unable to obtain security advisories for packages whose version contains a hyphen (-) followed by additional characters.
While the maintainers of the project consider adding a hyphen to the name as a necessary piece of functionality to distinguish between normal and pre-release versions of packages, this opens up a new attack vector for attackers who seek to attack users of the npm ecosystem. Hackers can exploit this loophole by deliberately embedding vulnerable or malicious code into packages of useful functionality that unsuspecting developers can then install, the researchers say.
As an example, the researchers cited the cruddl package, which had a critical vulnerability (CVE-2022-36084) in one of its previous versions. When installing this version of the CLI, npm warns the developer that the package contains a critical vulnerability.
However, if you try to install a pre-release version of cruddl 2.0.0 CLI, npm will not display any warning, even though this version of the package is also affected.
At the conclusion of the report, JFrog recommended that developers and DevOps engineers should never install pre-release npm packages unless they are sure the source is 100% reliable. It is worth noting that even in this case, it is recommended to revert to a non-preview version of the package as soon as possible.