Vulnerabilities in pkg:npm/nanoid
PACKAGECVE-2026-73086 is a HIGH (CVSS 7.4) integer overflow or wraparound vulnerability (CWE-190: Integer Overflow or Wraparound) affecting nanoid libraries in the npm ecosystem. The issue involves integer overflow or wraparound. Remediation is available by upgrading affected packages to version 3.3.12, 5.1.11.
pkg:npm/nanoid
Vulnerability advisories affecting package pkg:npm/nanoid. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-xwg4-73v4-xw9w | CVE-2026-73086 | HIGH | nanoid: Integer Overflow or Wraparound |
| GHSA-2v37-7h3g-55p8 | CVE-2026-67213 | HIGH | nanoid: custom generators can loop indefinitely when size is zero |
| GHSA-28wg-ghj8-5hjv | CVE-2026-67214 | HIGH | nanoid: non-secure generators can loop indefinitely with negative size |
| GHSA-mwcw-c2x4-8c55 | CVE-2024-55565 | MODERATE | Predictable results in nanoid generation when given non-integer values |
| GHSA-qrpm-p2h7-hrv2 | CVE-2021-23566 | MODERATE | Exposure of Sensitive Information to an Unauthorized Actor in nanoid |
CVE-2026-73086 at a Glance
Security Impact
CVSS: 7.4
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N).
How to Fix CVE-2026-73086
To remediate this vulnerability, upgrade all affected nanoid dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install nanoid@3.3.12
npm install nanoid@5.1.11
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls nanoid
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2026-73086, inspect your project dependencies using npm:
npm ls nanoid
Analyze the terminal output to locate any version of nanoid in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.3.12), your application is affected.
Note: The npm ls nanoid command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-190: Integer Overflow or Wraparound, where the product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. this occurs when an integer value is incremented to a value that is too large to store in the associated representation. when this occurs, the value may become a very small or negative number. In nanoid, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-73086 Affected nanoid Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
nanoid
|
npm |
< 3.3.12
|
3.3.12
|
|
nanoid
|
npm |
≥ 4.0.0
< 5.1.11
|
5.1.11
|
References
Frequently Asked Questions
What is CVE-2026-73086?
Which nanoid versions are affected?
What version fixes CVE-2026-73086?
Is nanoid affected?
What is the CVSS score of CVE-2026-73086?
What CWE is associated with CVE-2026-73086?
How can I check npm dependencies for CVE-2026-73086?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-xwg4-73v4-xw9w",
"modified" : "2026-09-01T19:23:45Z",
"published" : "2026-09-01T19:23:45Z",
"aliases" : [ "CVE-2026-73086" ],
"summary" : "nanoid: Integer Overflow or Wraparound",
"details" : "### Summary\n\nAn integer overflow in `nanoid(size)` permanently corrupts the process-wide CSPRNG pool, causing all subsequent ID generation to return the deterministic string `\"uuuuuuuuuuuuuuuuuuuuu\"`. Any application that passes user-influenced values to the `size` parameter loses all randomness guarantees for session tokens, CSRF tokens, and unique identifiers until process restart.\n\n### Details\n\n`nanoid()` at [`index.js:101`](https://github.com/ai/nanoid/blob/main/index.js#L101) coerces the `size` parameter with `size |= 0`, which converts it to a signed 32-bit integer. When `size >= 2^31` (e.g., `2147483648`), this wraps to `-2147483648`.\n\nThe negative value is passed to `fillPool()` ([`index.js:15`](https://github.com/ai/nanoid/blob/main/index.js#L15)):\n\n```javascript\nfunction fillPool(bytes) {\n if (!pool || pool.length < bytes) { // false: pool exists, -2B < pool.length\n pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)\n crypto.getRandomValues(pool)\n poolOffset = 0\n } else if (poolOffset + bytes > pool.length) { // false: poolOffset + (-2B) < pool.length\n crypto.getRandomValues(pool)\n poolOffset = 0\n }\n poolOffset += bytes // poolOffset += -2147483648 → deeply negative\n}\n```\n\nNeither branch triggers, so the pool is never refreshed. `poolOffset` becomes ~-2.1 billion.\n\nSubsequent `nanoid()` calls execute:\n```javascript\nfor (let i = poolOffset - size; i < poolOffset; i++) {\n id += scopedUrlAlphabet[pool[i] & 63]\n}\n```\n\n`pool[negative_index]` returns `undefined`. `undefined & 63` evaluates to `0`. `urlAlphabet[0]` is `'u'`. Every ID becomes `\"uuuuuuuuuuuuuuuuuuuuu\"`.\n\nThe corruption is **persistent** — it affects all subsequent calls in the process until ~100 million calls eventually wrap `poolOffset` back to positive, or the process restarts.\n\n### PoC\n\n```javascript\nimport { nanoid } from 'nanoid'\n\n// Step 1: Normal operation\nconsole.log(nanoid()) // e.g., \"V1StGXR8_Z5jdHi6B-myT\"\n\n// Step 2: Trigger overflow (e.g., from an API parameter)\ntry { nanoid(2147483648) } catch(e) {}\n\n// Step 3: All subsequent IDs are deterministic\nconsole.log(nanoid()) // \"uuuuuuuuuuuuuuuuuuuuu\"\nconsole.log(nanoid()) // \"uuuuuuuuuuuuuuuuuuuuu\"\nconsole.log(nanoid()) // \"uuuuuuuuuuuuuuuuuuuuu\"\n// ... forever, process-wide\n```\n\nRun with: `node --experimental-vm-modules poc.mjs`\n\nAttack scenario: Any API endpoint that accepts a user-controlled length/size parameter (URL shortener slug length, configurable token size, etc.) and passes it to `nanoid(userInput)`.\n\n### Impact\n\n**Complete loss of ID unpredictability and uniqueness, process-wide, from a single request.**\n\n- All session IDs, CSRF tokens, API keys, and database identifiers generated after the attack are identical and predictable\n- An attacker can predict all tokens issued to other users, enabling session hijacking and authentication bypass\n- The corruption is persistent (survives across requests) and affects all consumers of `nanoid` in the same process\n- No special privileges or preconditions required — a single unauthenticated request is sufficient\n- Affects any application that passes external input to the `size` parameter without validation",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "nanoid"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.3.12"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "nanoid"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "4.0.0"
}, {
"fixed" : "5.1.11"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/ai/nanoid/security/advisories/GHSA-xwg4-73v4-xw9w"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-73086"
}, {
"type" : "WEB",
"url" : "https://github.com/ai/nanoid/commit/7087969281cab8ba8ae3babf1894e819068b3bb4"
}, {
"type" : "WEB",
"url" : "https://github.com/ai/nanoid/commit/821dfed7b5db7f88e92f56c60eef32c8135077c3"
}, {
"type" : "WEB",
"url" : "https://github.com/ai/nanoid/commit/b0036ed60dc9facd7f1191a50dfb3076500202ac"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/ai/nanoid"
}, {
"type" : "WEB",
"url" : "https://github.com/ai/nanoid/releases/tag/3.3.12"
}, {
"type" : "WEB",
"url" : "https://github.com/ai/nanoid/releases/tag/5.1.11"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-190" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2026-09-01T19:23:45Z",
"nvd_published_at" : "2026-08-11T17:19:16Z"
}
}