# CVE-2021-4239: Weak encryption and denial of service in github.com/flynn/noise

> Weak encryption after massive message counts and nonce desynchronization allow denial of service and security bypass in the Go Noise protocol library.

- **Severity:** High 7.5 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 27 Dec 2022
- **Updated:** 14 Apr 2025
- **Also known as:** GHSA-6cr6-fmvc-vw2p, GHSA-g9mp-8g3h-3c5c, GO-2022-0425, UBUNTU-CVE-2021-4239

## What is CVE-2021-4239?

CVE-2021-4239 is a high-severity vulnerability in github.com/flynn/noise, published on 27 Dec 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

The Noise protocol implementation suffers from weakened cryptographic security after encrypting 2^64 messages, and a potential denial of service attack. After 2^64 (~18.4 quintillion) messages are encrypted with the Encrypt function, the nonce counter will wrap around, causing multiple messages to be encrypted with the same key and nonce. In a separate issue, the Decrypt function increments the nonce state even when it fails to decrypt a message. If an attacker can provide an invalid input to the Decrypt function, this will cause the nonce state to desynchronize between the peers, resulting in a failure to encrypt all subsequent messages.

Weakness: CWE-311 (Missing Encryption of Sensitive Data)

## Which versions are affected by CVE-2021-4239?

5 open source packages ship an affected version, including github.com/flynn/noise. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/flynn/noise` | Go | All versions | 1.0.0 |
| `github.com/flynn/noise` | Go | All versions | 1.0.0 |
| `github.com/flynn/noise` | Go | All versions | 1.0.0 |
| `github.com/flynn/noise` | Go | All versions | 1.0.0 |
| `github.com/flynn/noise` | Go | All versions | 1.0.0 |

Products: Noiseprotocol Noise.

## How do I fix CVE-2021-4239?

Upgrade github.com/flynn/noise to 1.0.0 or later.

## Is CVE-2021-4239 being exploited?

There is no known exploitation of CVE-2021-4239 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-4239 and fix it if it is affected.

What it is: CVE-2021-4239 is a high-severity vulnerability in github.com/flynn/noise, published on 27 Dec 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-4239 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/flynn/noise (Go): affected all versions; fixed in 1.0.0
- github.com/flynn/noise (Go): affected all versions; fixed in 1.0.0
- github.com/flynn/noise (Go): affected all versions; fixed in 1.0.0
- github.com/flynn/noise (Go): affected all versions; fixed in 1.0.0
- github.com/flynn/noise (Go): affected all versions; fixed in 1.0.0

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/CVE-2021-4239/ (Markdown: https://insights.sbomify.com/CVE-2021-4239/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-4239
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-4239
- OSV: https://osv.dev/vulnerability/CVE-2021-4239

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-4239/
Summaries are generated and may contain mistakes; the official description above is the record.
