# GHSA-9x64-5r7x-2q53: Malicious Package in flatmap-stream

> A malicious npm package executes arbitrary code to steal cryptocurrency private keys and account data from victims.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** No
- **Published:** 1 Sep 2020

## What is GHSA-9x64-5r7x-2q53?

GHSA-9x64-5r7x-2q53 is a vulnerability in flatmap-stream, published on 1 Sep 2020. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Version 0.1.1 of `flatmap-stream` is considered malicious.

This module runs an encrypted payload targeting a very specific application, `copay` and because they shared the same description it would have likely worked for `copay-dash`.

The injected code:

- Read in AES encrypted data from a file disguised as a test fixture
- Grabbed the npm package description of the module that imported it, using an automatically set environment variable
- Used the package description as a key to decrypt a chunk of data pulled in from the disguised file

The decrypted data was part of a module, which was then compiled in memory and executed.

This module performed the following actions:

- Decrypted another chunk of data from the disguised file
- Concatenated a small, commented prefix from the first decrypted chunk to the end of the second decrypted chunk
- Performed minor decoding tasks to transform the concatenated block of code from invalid JS to valid JS (we believe this was done to evade detection by dynamic analysis tools)
- Wrote this processed block of JS out to a file stored in a dependency that would be packaged by the build scripts: 

The chunk of code that was written out was the actual malicious code, intended to be run on devices owned by the end users of Copay.

This code would do the following:

- Detect the current environment: Mobile/Cordova/Electron
- Check the Bitcoin and Bitcoin Cash balances on the victim's copay account
- If the current balance was greater than 100 Bitcoin, or 1000 Bitcoin Cash:
  - Harvest the victim's account data in full
  - Harvest the victim's copay private keys
  - Send the victim's account data/private keys off to a collection

## Recommendation

If you find this module in your environment it's best to remove it. The malicious version of event-stream and flatmap-stream have been removed from the npm Registry.

## Which versions are affected by GHSA-9x64-5r7x-2q53?

2 open source packages ship an affected version, including flatmap-stream.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `flatmap-stream` | npm | All versions | None |
| `flatmap-stream` | npm | All versions | None |

## How do I fix GHSA-9x64-5r7x-2q53?

No fix has been published for GHSA-9x64-5r7x-2q53 yet. Limit exposure of the affected software until one is available.

## Is GHSA-9x64-5r7x-2q53 being exploited?

There is no known exploitation of GHSA-9x64-5r7x-2q53 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-9x64-5r7x-2q53 and fix it if it is affected.

What it is: GHSA-9x64-5r7x-2q53 is a vulnerability in flatmap-stream, published on 1 Sep 2020. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-9x64-5r7x-2q53 in the wild and no public exploit code.

Affected packages and fixed versions:
- flatmap-stream (npm): affected all versions; no fix listed
- flatmap-stream (npm): affected all versions; no fix listed

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-9x64-5r7x-2q53/ (Markdown: https://insights.sbomify.com/GHSA-9x64-5r7x-2q53/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-9x64-5r7x-2q53

---
From sbomify Insights: https://insights.sbomify.com/GHSA-9x64-5r7x-2q53/
Summaries are generated and may contain mistakes; the official description above is the record.
