Hacking

Experts found binary planting and arbitrary file overwrite flaws in NPM

NPM, the biggest package manager for JavaScript libraries, has addressed a vulnerability that could be exploited to execute “binary planting” attacks.

NPM maintainers have addressed a vulnerability that could allow a package publisher to modify and/or gain access to arbitrary files on a user’s system when the package is installed, so-called “binary planting” attacks.

The vulnerability affects versions of NP prior to 6.13.3 (and versions of yarn prior to 1.21.1), a specially crafted entry in the package.json bin field would allow a package publisher to modify and/or gain access to arbitrary files the system where the package is installed.

“In versions of npm prior to 6.13.3 (and versions of yarn prior to 1.21.1), a properly constructed entry in the package.json bin field would allow a package publisher to modify and/or gain access to arbitrary files on a user’s system when the package is installed.” reads the advisory published by NPM.

“In versions of npm prior to 6.13.4 (and all versions of yarn as of this announcement), it was possible for a globally-installed package with a binary entry to overwrite an existing binary in the target install location.  (That is, not any arbitrary file on the system, but any file in /usr/local/bin.)”

The vulnerability affects older versions of yarn, an open-source alternative client developed by Facebook for fetching modules from the registry.

NPM maintainers also addressed a separate vulnerability that could be exploited to create arbitrary symlinks to any file.

The experts pointed out that vulnerable NPM versions, and all current versions of yarn allow the arbitrary overwriting of an existing binary in the /usr/local/bin directory with another file.

The vulnerability was reported by the developer Daniel Ruf who shared technical details in a blog post.

“While npm and yarn are most vulnerable, pnpm seems to prevent many of the attack types as my tests concluded.” Ruf wrote.

“pnpm seems to not resolve the path outside of node_modules in most cases. Also as pnpm uses symlinks in general to manage the dependencies, it prevents that symlinks can be overwritten by other packages then with which they were created and are owned by them.”

“The problem is that we can define any (valid) paths for the binary name and the file which is then symlinked.”

To carry out the attack it is required an entry for the “bin” key in package.json, a file that npm uses to contain the metadata about the project and its dependencies.

"bin": { "../some/path": "../some/other/path" }

The expert also created proof-of-concept exploits that write or overwrite arbitrary files and allow unauthorized file access.

The good news is that NPM has not found any module in the registry that use this attack.

“That does not guarantee that it hasn’t been used, but it does mean that it isn’t currently being used in published packages on the registry,” NPM’s security team said.

[adrotate banner=”9″] [adrotate banner=”12″]

Pierluigi Paganini

(SecurityAffairs – NPM, hacking)

[adrotate banner=”5″]

[adrotate banner=”13″]

Pierluigi Paganini

Pierluigi Paganini is member of the ENISA (European Union Agency for Network and Information Security) Threat Landscape Stakeholder Group and Cyber G7 Group, he is also a Security Evangelist, Security Analyst and Freelance Writer. Editor-in-Chief at "Cyber Defense Magazine", Pierluigi is a cyber security expert with over 20 years experience in the field, he is Certified Ethical Hacker at EC Council in London. The passion for writing and a strong belief that security is founded on sharing and awareness led Pierluigi to find the security blog "Security Affairs" recently named a Top National Security Resource for US. Pierluigi is a member of the "The Hacker News" team and he is a writer for some major publications in the field such as Cyber War Zone, ICTTF, Infosec Island, Infosec Institute, The Hacker News Magazine and for many other Security magazines. Author of the Books "The Deep Dark Web" and “Digital Virtual Currency and Bitcoin”.

Recent Posts

U.S. CISA adds Microsoft Windows flaws to its Known Exploited Vulnerabilities catalog

U.S. Cybersecurity and Infrastructure Security Agency (CISA) adds Microsoft Windows flaws to its Known Exploited…

2 hours ago

Ivanti fixed two EPMM flaws exploited in limited attacks

Ivanti addressed two Endpoint Manager Mobile (EPMM) software vulnerabilities that have been exploited in limited…

4 hours ago

Microsoft Patch Tuesday security updates for May 2025 fixed 5 actively exploited zero-days

Microsoft Patch Tuesday security updates for May 2025 addressed 75 security flaws across multiple products, including…

12 hours ago

Fortinet fixed actively exploited FortiVoice zero-day<gwmw style="display:none;"></gwmw><gwmw style="display:none;"></gwmw>

Fortinet fixed a critical remote code execution zero-day vulnerability actively exploited in attacks targeting FortiVoice…

14 hours ago

How Interlock Ransomware Affects the Defense Industrial Base Supply Chain

Interlock Ransomware 's attack on a defense contractor exposed global defense supply chain details, risking…

1 day ago

Marks and Spencer confirms data breach after April cyber attack

Marks and Spencer (M&S) confirms that threat actors stole customer data in the ransomware attack…

1 day ago