event-stream 3.3.6 on npm added the dependency flatmap-stream, whose hidden code was built to steal bitcoin from Copay wallet users, from September 2018.
Versions 3.3.4 and 3.3.5 of event-stream were clean. The attacker got publish rights by gaining the trust of the original maintainer.
What happened
A new contributor took over event-stream, added a malicious dependency, and waited about a month to arm it.
- 9 September 2018: event-stream 3.3.6 added the flatmap-stream dependency.
- 5 October 2018: flatmap-stream 0.1.1 was released with the injected code.
- The code decrypted a hidden blob. It used the
npm_package_descriptionenvironment variable as the key. - The payload ran only during build commands for iOS, Android or desktop.
- It injected JavaScript into
@zxing/librarythat collected data from wallets with more than 100 BTC or 1000 BCH.
event-stream 4.0.0 removed the dependency on 16 September 2018. npm removed flatmap-stream on 26 November 2018.
Affected versions
- event-stream 3.3.6: the release that added the flatmap-stream dependency.
- flatmap-stream 0.1.1: the version with the injected code. The GitHub advisory GHSA-9x64-5r7x-2q53 lists no patched version.
- Copay 5.0.2 to 5.1.0: Snyk reports these app versions as compromised.
- event-stream 3.3.4 and 3.3.5 were clean.
Indicators of compromise
- The package name
flatmap-streamat version0.1.1innode_modulesor in a lockfile. - The file
flatmap-stream/index.min.js, which contained the decryption code. - event-stream at version
3.3.6in a lockfile. - Copay builds 5.0.2 through 5.1.0.
How to check
Search your dependency tree and lockfiles for flatmap-stream and for event-stream 3.3.6.
npm ls event-stream flatmap-stream
grep -rn "flatmap-stream" package-lock.json yarn.lock
The code ran only in builds of the target app. Check the build history for Copay as well.
What to do now
- Remove flatmap-stream from the project. Move event-stream to 4.0.0 or later, or remove it.
- Delete
node_modulesand the lockfile entries for flatmap-stream, then reinstall. - If you build or use Copay 5.0.2 to 5.1.0, update to 5.2.0 and treat private keys as stolen, as Copay advised.
- Move funds to a new wallet with new keys if the old wallet used an affected version.
What Vigilance would show
These examples show an install hold and the corresponding owner report.
Example install message
Vigilance blocked `event-stream` 3.3.6. This version is too new or changed in a way Vigilance must check first.
Example owner report
Bad update
event-stream 3.3.6
The library can now unscramble a hidden blob, run it, and plant extra code inside a bitcoin wallet app.
No security team? See who reads the alert.
Frequently asked questions
Which event-stream version was malicious?
event-stream 3.3.6 added the flatmap-stream dependency. The injected code was in flatmap-stream 0.1.1.
How do I check if I installed flatmap-stream?
Run npm ls event-stream flatmap-stream and search your lockfiles for flatmap-stream. Version 0.1.1 is the bad one.
Sources
Send this page to the person who looks after AI at your company.