Skip to content
Threat Feed
high advisory

Integer Overflow Vulnerability in nanoid Leads to Deterministic Token Generation

An integer overflow in the nanoid library allows unauthenticated attackers to permanently corrupt the process-wide CSPRNG pool, forcing all subsequent ID generation to output a deterministic string and enabling mass authentication bypass.

CVE search metadata

CVE search record: CVE-2026-73086. Severity: high. CVSS: 7.4. EPSS: 0.30%. KEV: no. Product: nanoid (< 3.3.12), nanoid (>= 4.0.0, < 5.1.11). Brief: Integer Overflow Vulnerability in nanoid Leads to Deterministic Token Generation. Brief link: https://feed.craftedsignal.io/briefs/2026-09-nanoid-overflow/

The popular npm package nanoid contains an integer overflow vulnerability (CVE-2026-73086) that can be triggered when a user-controlled value is passed to the nanoid(size) function. Specifically, supplying a size value greater than or equal to 2^31 triggers a bitwise OR operation (size |= 0) that causes the value to wrap into a negative signed 32-bit integer. This negative value bypasses the library's CSPRNG pool-refill logic, causing the internal poolOffset to point to an invalid memory index. Subsequent ID generation calls fail to retrieve entropy and instead read undefined from the buffer, resulting in a permanent corruption of the ID generation stream. Every ID produced thereafter becomes the deterministic string "uuuuuuuuuuuuuuuuuuuuu". This corruption persists process-wide until the application restarts or ~100 million additional IDs are generated. Because nanoid is commonly used for security-critical identifiers such as session tokens and CSRF tokens, this vulnerability allows for trivial session hijacking and authentication bypass across the affected application.

Attack Chain

  1. Attacker identifies an API endpoint or application feature that accepts a user-provided integer to determine ID length (e.g., a "token size" or "identifier length" parameter).
  2. Attacker sends a crafted request containing a value greater than or equal to 2,147,483,648 (0x80000000).
  3. The nanoid library's index.js performs size |= 0 on the malicious input, causing an integer overflow to -2,147,483,648.
  4. The library passes the negative integer to the fillPool() function, which fails to trigger the entropy refresh logic due to the negative index arithmetic.
  5. The internal poolOffset is updated to a deeply negative value, corrupting the subsequent ID generation loop.
  6. The nanoid function attempts to read from the corrupted pool index, receives undefined, and maps the resulting bitwise operation to the static character 'u'.
  7. The application returns a deterministic "uuuu..." ID to the user, confirming successful exploitation.
  8. Attacker leverages the predictable ID stream to predict future session tokens or forge identifiers for other users, leading to full account takeover or session hijacking.

Impact

Successful exploitation results in a complete loss of unpredictability and uniqueness for all identifiers generated by the affected process. This includes session tokens, CSRF tokens, API keys, and database primary keys. An attacker can predict tokens issued to other users, leading to widespread session hijacking and authentication bypass. The vulnerability is highly impactful because the corruption is persistent for the entire process lifetime and requires only a single unauthenticated request.

Recommendation

  1. Upgrade nanoid to version 3.3.12 or 5.1.11 (or later) immediately to incorporate input validation that prevents the integer overflow.
  2. Audit all application code paths that pass user-supplied input to the nanoid() function and implement strict server-side validation to ensure the size parameter stays within reasonable, positive bounds.
  3. Deploy monitoring to alert on application process crashes or abnormal token generation patterns that indicate the process may have been subjected to an exploitation attempt.

Immediate actions

Upgrade nanoid to 3.3.12 or 5.1.11

IT Operations 24h

Mitigations

Implement strict input validation for the size argument passed to nanoid

immediate Application Security

CVE-2026-73086