# CVE-2021-23566: nanoid information exposure via valueOf

Source: https://junglewise.ai/threats/cve-2021-23566-nanoid-information-exposure-via-valueof  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2022-01-21. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2021-23566 · Severity: low · CVSS 3.1 · Published 2022-01-21

nanoid is a popular JavaScript library used to generate unique identifiers (IDs) for database records and other applications. A vulnerability in versions 3.0.0 through 3.1.30 allows an attacker with local access to recover previously generated IDs by exploiting the valueOf() function, potentially compromising the uniqueness guarantee that applications rely on for security or data integrity.

Technologies: [nanoid (npm)](https://junglewise.ai/threats/technologies/nanoid). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2021-23566 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-23566 being exploited in the wild.

**How severe is CVE-2021-23566?** Low severity, with a CVSS score of 3.1, published 21 January 2022.

**Which products and versions are affected?** nanoid (npm) SEMVER:introduced=3.0.0,fixed=3.1.31.

**Is there a fix for CVE-2021-23566?** Yes. nanoid (npm): upgrade to 3.1.31 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2021-23566 attacked?** It is attacked with local access.

**Am I affected by CVE-2021-23566?** Check whether you run nanoid (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- nanoid (npm): upgrade to 3.1.31 or later

  ```sh
  npm install nanoid@3.1.31
  ```


## Technical details

The vulnerability is an information exposure flaw (CWE-200, CWE-704) in nanoid's valueOf() function implementation. Versions 3.0.0 through 3.1.30 allow an attacker to reproduce the last generated ID, breaking the confidentiality of ID generation. This is a local privilege vulnerability requiring local access (AV:L) and low privileges (PR:L), with no user interaction needed. An attacker can deterministically recreate previously issued IDs, which may compromise applications using nanoid for security tokens, session identifiers, or other confidential purposes. The vulnerability was fixed in version 3.1.31 via commit 2b7bd9332bc49b6330c7ddb08e5c661833db2575.

## Affected products

- ai nanoid 3.0.0 to 3.1.30

## Identifiers

- CVE-2021-23566
- GHSA-qrpm-p2h7-hrv2

## Timeline

- 2022-01-21: disclosed: Advisory published via GitHub Security Advisory GHSA-qrpm-p2h7-hrv2
- 2022-01-11: patched: Fix merged in pull request #328, available in version 3.1.31

## References

- [https://github.com/ai/nanoid/pull/328](https://github.com/ai/nanoid/pull/328)

## Related threats

- [nanoid integer overflow in CSPRNG pool](https://junglewise.ai/threats/cve-2026-73086-nanoid-integer-overflow-in-csprng-pool)
- [nanoid infinite loop in non-secure module](https://junglewise.ai/threats/cve-2026-67214-nanoid-infinite-loop-in-non-secure-module)
- [nanoid infinite loop in customAlphabet and customRandom](https://junglewise.ai/threats/cve-2026-67213-nanoid-infinite-loop-in-customalphabet-and-customrandom)
- [nanoid infinite loop and predictable ID generation with fractional size values](https://junglewise.ai/threats/cve-2024-55565-nanoid-infinite-loop-and-predictable-id-generation-with)
