Executive brief
Yarn, a popular Node.js package manager, contains a flaw in how it handles "bin" declarations during package installation. Attackers can craft malicious packages to create symbolic links pointing to arbitrary locations on the filesystem, potentially overwriting existing files. This could allow an attacker to replace legitimate binaries or critical system files with malicious versions during a routine package installation.
Technical details
This is a link-following / path traversal vulnerability (CWE-78) in Yarn's bin installation logic. During package installation, Yarn processes the "bin" field in package.json to create executable entry points. The vulnerability allows an attacker to specify absolute paths or path traversal sequences (e.g., "../../../target/file") in bin declarations, causing Yarn to create symlinks that escape the intended node_modules directory and point to arbitrary filesystem locations. Attack vector is local with no authentication or special privileges required, though user interaction (installing a malicious package) is necessary. An attacker can overwrite files writable by the installing user, potentially replacing legitimate binaries with trojanized versions. The fix, released in Yarn 1.22.0 and backported to 1.21.1, validates bin paths to ensure they remain within the package directory boundaries and rejects escape attempts with warnings.
Affected products
- Yarn yarn before 1.22.0 (including 1.21.1 and earlier)
Timeline
- 2019-12-12: disclosed: Coordinated vulnerability disclosure; vulnerability independently discovered by Daniel Ruf on 2019-10-21
- 2019-12-11: patched: Yarn v1.21.1 and 1.22.0 released with fix (PR #7755)
- 2020-02-14: other: Advisory published in GitHub advisory database
References
- https://github.com/yarnpkg/yarn/issues/7761
- https://github.com/yarnpkg/yarn/pull/7755
- https://github.com/yarnpkg/yarn/commit/039bafd74b7b1a88a53a54f8fa6fa872615e90e7
- https://access.redhat.com/errata/RHSA-2020:0475
- https://blog.daniel-ruf.de/critical-design-flaw-npm-pnpm-yarn
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/3HIZW4NZVV5QY5WWGW2JRP3FHYKZ6ZJ5