osec.one case analysis cover: event-stream 2018: a popular npm package handed to a stranger, and a wallet stealer inside

In September 2018 the npm package event-stream was downloaded about 2.2 million times a week and used by 3,931 other packages. Its author, Dominic Tarr, hadn't used it for years. Someone with the npm name right9ctrl emailed him offering to maintain it, and he handed over publish rights. Five weeks later a new dependency of event-stream carried an encrypted payload that did nothing on almost every machine it reached, and stole Bitcoin wallets inside one app: the Copay wallet from BitPay.

Nobody stole a password or broke a build server. A maintainer gave a package away, as open-source maintainers do all the time. This case analysis goes through each step with the npm registry's own records, then shows a check we ran on our own lock file to spot the same kind of handover.

It differs from the XZ Utils backdoor, where an attacker spent two years earning trust, and from Shai-Hulud, which published with stolen tokens. Here the access was simply asked for, and given.

Attack chain: Dominic Tarr gives right9ctrl publish rights and 3.3.5 is published on 5 September; on 9 September 3.3.6 adds flatmap-stream as a dependency; on 5 October flatmap-stream 0.1.1 carries a payload only in its minified file on npm; the payload's key is the description of the package being built, so it decrypts only inside Copay's build; Copay 5.0.2 to 5.1.0 send wallets over 100 BTC or 1,000 BCH out; on 20 November a crypto.createDecipher deprecation warning leads a developer to the code

The timeline, from the registry

npm still keeps the publish time and the publishing account for every version. This is what the registry says today, plus the dates from the GitHub issue and npm's post:

text
event-stream / flatmap-stream (2018, UTC; registry.npmjs.org, npm blog, GitHub #116)

version / event                    date              published by
event-stream 3.3.4                 2016-07-17 07:24  dominictarr   (last release by the author)
(handover by email, date unknown; right9ctrl gets GitHub and npm rights)
event-stream 3.3.5                 2018-09-05 05:27  right9ctrl    (first release by right9ctrl;
                                                                     dependency ranges loosened)
event-stream 3.3.6                 2018-09-09 08:28  right9ctrl    adds flatmap-stream as a dependency
event-stream 4.0.0                 2018-09-16 11:20  right9ctrl    flatmap-stream removed, code inlined
flatmap-stream 0.1.1               2018-10-05        new version with the payload
29 Oct    nodemon issue #1442: "DeprecationWarning: crypto.createDecipher is deprecated"
19 Nov    event-stream issue #115 flags the suspicious versions
20 Nov    Ayrton Sparling (FallingSnow) traces the warning to flatmap-stream/index.min.js,
          opens event-stream issue #116 "I don't know what to say."
26 Nov    npm removes flatmap-stream and event-stream 3.3.6, takes over event-stream;
          GitHub advisory GHSA-mh6f-8j2x-4483 (critical, CVSS 9.8); BitPay confirms Copay
          5.0.2 to 5.1.0 shipped the code, releases 5.2.0
27 Nov    npm's write-up: "Details about the event-stream incident"
29 Nov    flatmap-stream replaced by the 0.0.1-security holder package

Two numbers show the reach. flatmap-stream was downloaded about 8 million times between September and its removal (Snyk's count at the time; the npm API now gives 9,677,100 for 5 September to 27 November 2018). And event-stream itself, now owned by npm, still gets 3,358,983 downloads a week (12 to 18 October 2026, npm API): the old name is still deep in dependency trees.

Step 1: the handover

Tarr explained it in the GitHub issue on 22 November: "he emailed me and said he wanted to maintain the module, so I gave it to him. I don't get any thing from maintaining this module, and I don't even use it anymore, and havn't for years." In a longer statement he wrote: "If it's not fun anymore, you get literally nothing from maintaining a popular package." The new maintainer's first release, 3.3.5, did some real-looking work: it loosened most dependency ranges from ~ to ^, the sort of tidy-up an eager new maintainer does.

What a consumer could have seen: the account that publishes the package changed, and the new account had never published this package before. That is visible in the registry for every version (_npmUser), and it is the one signal that separates this case from routine releases. Our check below looks for exactly that.

Step 2: a new dependency, then a clean major version

On 9 September 3.3.6 added flatmap-stream as a dependency, at a version that was still harmless. A week later 4.0.0 removed it again by inlining the code. That second move matters: projects that took the new major got clean code, while every project that asked for event-stream@^3.3.x, which is most of them, stayed on 3.3.6 and kept pulling in flatmap-stream. A dependency added and removed again in a week looks like churn, not an attack.

Step 3: a payload only in the published file

On 5 October flatmap-stream 0.1.1 was published. The extra code sat at the end of index.min.js, the minified file in the npm tarball; the readable source most people would check didn't contain it. It read an AES-encrypted blob from a file dressed up as a test fixture and tried to decrypt it with a key taken from the environment: npm_package_description, the description of the top-level project being built. In almost every project that key was wrong, decryption failed silently, and nothing happened. That is why millions of installs didn't notice.

Control: what you run is the tarball, not the repository. Compare the two for new versions of small, rarely updated dependencies, and treat a minified file in a package that doesn't need one as a reason to look. npm provenance (public beta April 2023, generally available September 2023) links a published version to the commit and workflow that built it; a 0.1.1 with no provenance, from a package whose earlier versions had it, would stand out. It would not have stopped a willingly appointed maintainer, but it removes the "code only in the tarball" hiding place.

Step 4: a key that only Copay had

The project description that decrypted it was "A Secure Bitcoin Wallet": Copay's. Researchers found the key later by trying the descriptions of every package on npm. The decrypted code then checked that it was running in a release build (npm scripts matching build:*-release) and wrote a second stage into a file of the @zxing/library dependency (ReedSolomonDecoder.js), so that it would end up inside the app BitPay shipped to its users, not on the developer's machine. GitHub's advisory notes copay-dash, with the same description, would likely have triggered it too.

Step 5: the stealer in shipped wallets

In the shipped app (mobile via Cordova, desktop via Electron) the code checked wallet balances and, for wallets holding more than 100 BTC or more than 1,000 BCH, sent the account data and private keys to 111.90.151.134 (npm's description; another analysis adds the host copayapi[.]host). BitPay confirmed that Copay 5.0.2 to 5.1.0 contained it, told users not to open the app, to install 5.2.0 and move funds to a new wallet with Send Max rather than restoring from their 12-word phrase. We found no public figure for coins actually stolen.

BitPay's follow-up list is a good one for any app team: freeze and commit dependencies, lock the lock file per major version and diff it on every upgrade, and from Copay 5.3.0 a Content Security Policy in the app that only allows network connections to listed hosts, which would have blocked the upload to an unknown IP.

Step 6: found by a deprecation warning

The payload used crypto.createDecipher, which Node.js had deprecated. Developers running nodemon (which depended on event-stream through ps-tree) started seeing DeprecationWarning: crypto.createDecipher is deprecated in late October. On 20 November Ayrton Sparling followed the stack trace into flatmap-stream/index.min.js and opened issue #116. A later comment on the nodemon issue said the payload "would've gone undetected for potentially years" without that warning. The defence that worked was luck plus one curious developer.

What breaks each step

text
Step                                Control                                          Cost
1 maintainer hands over publish      flag versions whose publisher never published    5 min (our script)
                                     the package before; read their first diff
2 new dependency in a patch release  lock file + npm ci; review new entries in the     per update
                                     lock file diff, not just version bumps
3 payload only in the tarball        compare tarball with repo for small deps;         10 min per dep
                                     prefer versions with npm provenance
4 runs at build time                 build releases in a clean CI job with no wallet   setup once
                                     keys or signing secrets in env until the last step
5 stealer phones home                CSP / network allow-list in the shipped app       1 hour
6 found by luck                      dependency monitoring (npm audit, GitHub          on by default
                                     Dependabot alerts) so an advisory reaches you
                                     the day it is published

Our check: who published each package in our own lock file?

The registry records the publishing account for every version, so you can list the packages in your lock file whose locked version came from someone who had never published that package before. We wrote a 30-line Python script that reads package-lock.json and the public registry metadata, and ran it on the osec.one site's own lock file (23 October 2026):

bash
$ python3 pubcheck.py package-lock.json
first release by phated: anymatch@3.1.3 (previous version 3.1.2)
first release by phated: convert-source-map@2.0.0 (previous version 1.9.0)
first release by dmitrysharabin: prismjs@1.30.0 (previous version 1.29.0)
first release by phryneas: redux@5.0.1 (previous version 5.0.0)

$ python3 pubcheck.py event-stream-lock.json      # a lock file with event-stream@3.3.5
first release by right9ctrl: event-stream@3.3.5 (previous version 3.3.4)

What the numbers mean: the lock file has 242 packages. In a longer version of the script that also counts plain publisher changes, 14 had a different publisher from the version before, which is normal in projects with several maintainers who take turns. Only 4 were a publisher's first release of that package, and each took a minute to clear by looking at the project's GitHub: the new publisher is one of the project's known maintainers (gulp team members for anymatch and convert-source-map, a Prism core team member, a Redux maintainer). event-stream 3.3.5 shows up on the same rule. A list of 4 names to look up is a review a small team will actually do.

python
"""For each package in package-lock.json: who published the locked version, and is it that
account's first release of the package? Public npm registry metadata only."""
import json, sys, urllib.request
from concurrent.futures import ThreadPoolExecutor

lock = json.load(open(sys.argv[1]))
pkgs = {p.rsplit("node_modules/", 1)[1]: m["version"] for p, m in lock.get("packages", {}).items()
        if "node_modules/" in p and m.get("version") and not m.get("link")}

def look(item):
    name, ver = item
    url = f"https://registry.npmjs.org/{name.replace('/', '%2f')}"
    try:
        d = json.load(urllib.request.urlopen(urllib.request.Request(url, headers={"User-Agent": "pubcheck"}), timeout=60))
    except Exception as e:
        print(f"could not read {name}: {e}", file=sys.stderr)
        return None
    order = [v for _, v in sorted((t, v) for v, t in d["time"].items() if v in d["versions"])]
    if ver not in order:
        return None
    i = order.index(ver)
    who = (d["versions"][ver].get("_npmUser") or {}).get("name")
    before = {(d["versions"][v].get("_npmUser") or {}).get("name") for v in order[:i]}
    return (name, ver, order[i - 1] if i else None, who) if i and who not in before else None

with ThreadPoolExecutor(8) as ex:
    for hit in filter(None, ex.map(look, sorted(pkgs.items()))):
        print("first release by {3}: {0}@{1} (previous version {2})".format(*hit))

Run it when you update the lock file (or in CI on pull requests that change it), and read the diff of anything it lists before merging. It fetches full package metadata, so on a large lock file give it a few minutes.

Why handovers keep working

Most of the packages in a JavaScript project are small, finished and maintained by one unpaid person. Handing one to a volunteer is normal and usually good. Tarr's own conclusion was that the fix is support for maintainers, not suspicion of them: "You can easily share the code, but no one wants to share the responsibility for maintaining that code." On the consumer side, the cheap controls are the ones above: a lock file, a look at new publishers and new dependencies, provenance where it exists, and build jobs that hold no secrets while third-party code runs. The same thinking applies to scripts and binaries a build downloads: pin them to a hash so a changed file stops the build.

Paste the URL of an install script or binary your build downloads: get its SHA-256 and a download-verify-run snippet for shell, GitHub Actions, GitLab CI and Dockerfiles, and a daily watch that emails you when the file changes. Free.

Pin a download

Sources

• npm registry metadata for event-stream and flatmap-stream (publish times, _npmUser): https://registry.npmjs.org/event-stream
• npm: Details about the event-stream incident (27 Nov 2018): https://blog.npmjs.org/post/180565383195/details-about-the-event-stream-incident
• GitHub: dominictarr/event-stream issue #116 "I don't know what to say.": https://github.com/dominictarr/event-stream/issues/116
• Dominic Tarr: statement on event-stream compromise (26 Nov 2018): https://gist.github.com/dominictarr/9fd9c1024c94592bc7268d36b8d83b3a
• GitHub advisories: GHSA-mh6f-8j2x-4483 (event-stream) and GHSA-9x64-5r7x-2q53 (flatmap-stream): https://github.com/advisories/GHSA-mh6f-8j2x-4483
• BitPay: bitpay/wallet issue #9346, Copay 5.0.2 to 5.1.0: https://github.com/bitpay/wallet/issues/9346
• Snyk: A post-mortem of the malicious event-stream backdoor: https://snyk.io/blog/a-post-mortem-of-the-malicious-event-stream-backdoor/
• es-incident payload analysis: https://es-incident.github.io/payloads.html
• nodemon issue #1442 (the deprecation warning): https://github.com/remy/nodemon/issues/1442
• The Register: Check your repos, crypto-coin-stealing code sneaks into fairly popular npm lib (26 Nov 2018): https://www.theregister.com/2018/11/26/npm_repo_bitcoin_stealer
• npm downloads API: event-stream 12-18 Nov 2018 and 12-18 Oct 2026; flatmap-stream 5 Sep to 27 Nov 2018: https://api.npmjs.org/downloads/point/2018-11-12:2018-11-18/event-stream
• GitHub: npm provenance public beta (19 Apr 2023): https://github.blog/changelog/2023-04-19-npm-provenance-public-beta/
• Our check: pubcheck.py on the osec.one site's package-lock.json, 23 Oct 2026