Yarn transfers npm credentials over unencrypted http connection
Yarn sends the npm authentication token over plain HTTP when a yarn.lock file contains a resolved URL for a scoped package that starts with http://registry.npmjs.org. A man-in-the-middle attacker can capture the token and then impersonate the affected npm account.
- Triaged in under an hour
- Fixed in 3 days
- Disclosed after 33 days
Module
module name: yarn
version: 1.16.0
npm page: https://www.npmjs.com/package/yarn
Module Description
Fast, reliable, and secure dependency management.
Module Stats
Replace stats below with numbers from npm’s module page:
166 703 downloads in the last day 849 928 downloads in the last week 3 772 290 downloads in the last month
Vulnerability
Vulnerability Description
For scoped packages that are listed as resolved "http://registry.npmjs.org/@... in yarn.lock, yarn trasfers npm credentials (i.e. _authToken) over unencrypted http connection. This allows any MitM (for example, a proxy or a VPN) to sniff out npm credentials, given that the developer in question performs yarn install on such a yarn.lock file.
A quick search shows that there is a number of yarn.lock files affected by this on GitHub, some examples:
- https://github.com/EC-Nordbund/ec-verwaltungs-app/blob/ab961352d5dd53834a51793d6e2c4bc69a2b22d4/packages/api/yarn.lock#L36
- https://github.com/nujabes403/boilerplate2/blob/61613e526aec02c5dd4227457deb8676d66780d0/yarn.lock#L7
There seem to be many of those on GitHub.
Looks like not only it was possible to craft a yarn.lock with a malicious intent, but also this seems to be a common pattern that yarn created itself at some point or under some circumstances and that gets persistent from older versions.
Steps To Reproduce:
-
Perform an
npm loginor just write//registry.npmjs.org/:_authToken=38bb8d1f-a39b-47d1-a78e-3bf0626ff77e(which is the format npm uses) to ~/.npmrc. Doing this from your own account would leak your npm credentials on next steps, so better just use a placeholder. -
Create an empty package with a single dependency on
"@babel/core": "^7.5.4" -
Perform
yarn install -
Replace all occurances of
https://registry.yarnpkg.comwithhttp://registry.npmjs.org/in the generatedyarn.lockAlternatively to steps 2-4 -- just use an already existing yarn.lock with
resolved "http://registry.npmjs.org/@in it (lots of those on GitHub), but be careful with that. -
Clear yarn cache and node_modules:
rm -rf ~/.cache/yarn/ node_modules. Let's assume you just downloaded an affected yarn.lock on your clean machine. -
Start wireshark with
tcp dst port 80filter. -
Run
yarn install
Observed result is attached on a screenshot.
Supporting Material/References:
Linux yoga 5.1.5-arch1-2-ARCH #1 SMP PREEMPT Mon May 27 03:37:39 UTC 2019 x86_64 GNU/Linux- Node.js v12.6.0
- npm 6.10.1
Wrap up
Select Y or N for the following statements:
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
Attacker (MitM) being able to:
- Impersonate the affected account
- Publish packages from the affected account that could also get used by the affected account/company in the future (for protected packages) and by anyone in the ecosystem (for public packages)
- Perform logout and break installs of protected packages
Attachments

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, yarn does not enforce HTTPS for registry URLs in yarn.lock and sends the npm auth token to whatever scheme is specified.
Impact
A man-in-the-middle attacker could impersonate the affected npm account, publish packages, and disrupt installs of protected packages.
What the attacker needed
Victim runs yarn install; yarn.lock has http resolved URL; attacker on network path
How it was found
- Add an npm auth token to the npm configuration file.
- Create a package that depends on a scoped package.
- Run yarn install to generate a lock file.
- Change the resolved URLs in the lock file from https to http.
- Clear the yarn cache and node_modules.
- Capture traffic on port 80 and run yarn install again.
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 report has not been written yet. The Original tab links to the source.
When you install packages with yarn, it sometimes needs to prove who you are to the npm registry by sending a secret token. This report shows that if a project's lock file points to an insecure web address, yarn sends that token without encryption, so anyone listening on the network can steal it and act as you.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.