# CVE-2024-36400: nano-id is unable to generate the correct character set

> Predictable IDs due to reduced entropy allow attackers to bypass security controls relying on unique identifiers.

- **Severity:** Critical 9.4 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 4 Jun 2024
- **Updated:** 2 Aug 2024
- **Also known as:** GHSA-2hfw-w739-p7x5, GHSA-9hc7-6w9r-wj94, RUSTSEC-2024-0343

## What is CVE-2024-36400?

CVE-2024-36400 is a critical vulnerability in viz-rs nano-id, published on 4 Jun 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

nano-id is a unique string ID generator for Rust. Affected versions of the nano-id crate incorrectly generated IDs using a reduced character set in the `nano_id::base62` and `nano_id::base58` functions. Specifically, the `base62` function used a character set of 32 symbols instead of the intended 62 symbols, and the `base58` function used a character set of 16 symbols instead of the intended 58 symbols. Additionally, the `nano_id::gen` macro is also affected when a custom character set that is not a power of 2 in size is specified. It should be noted that `nano_id::base64` is not affected by this vulnerability. This can result in a significant reduction in entropy, making the generated IDs predictable and vulnerable to brute-force attacks when the IDs are used in security-sensitive contexts such as session tokens or unique identifiers. The vulnerability is fixed in 0.4.0.

Weakness: CWE-331 (Insufficient Entropy)

## Which versions are affected by CVE-2024-36400?

5 open source packages ship an affected version, including nano-id. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `nano-id` | crates.io | All versions | 0.4.0 |
| `nano-id` | crates.io | All versions | 0.4.0 |
| `nano-id` | crates.io | All versions | 0.4.0 |
| `nano-id` | crates.io | All versions | 0.4.0 |
| `nano-id` | crates.io | From 0.0.0-0 | 0.4.0 |

Products: Viz Nano Id.

## How do I fix CVE-2024-36400?

Upgrade nano-id to 0.4.0 or later.

## Is CVE-2024-36400 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-36400 and fix it if it is affected.

What it is: CVE-2024-36400 is a critical vulnerability in viz-rs nano-id, published on 4 Jun 2024. 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-2024-36400 in the wild and no public exploit code.

Affected packages and fixed versions:
- nano-id (crates.io): affected all versions; fixed in 0.4.0
- nano-id (crates.io): affected all versions; fixed in 0.4.0
- nano-id (crates.io): affected all versions; fixed in 0.4.0
- nano-id (crates.io): affected all versions; fixed in 0.4.0
- nano-id (crates.io): affected from 0.0.0-0; fixed in 0.4.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-2024-36400/ (Markdown: https://insights.sbomify.com/CVE-2024-36400/index.md)
```

## Sources

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

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