Skip to content

fix(deps): update dependency nanoid to v5 [security] - #1187

Open
renovate[bot] wants to merge 1 commit into
masterfrom
renovate/npm-nanoid-vulnerability
Open

renovate[bot] wants to merge 1 commit into
masterfrom
renovate/npm-nanoid-vulnerability

Conversation

@renovate

@renovate renovate Bot commented Dec 10, 2024 •

Copy link
Copy Markdown
Contributor

This PR contains the following updates:

Package Change Age Confidence
nanoid ^4.0.0 → ^5.0.0 age confidence

Predictable results in nanoid generation when given non-integer values

CVE-2024-55565 / GHSA-mwcw-c2x4-8c55

More information

Details

When nanoid is called with a fractional value, there were a number of undesirable effects:

  1. in browser and non-secure, the code infinite loops on while (size--)
  2. in node, the value of poolOffset becomes fractional, causing calls to nanoid to return zeroes until the pool is next filled
  3. if the first call in node is a fractional argument, the initial buffer allocation fails with an error

Version 3.3.8 and 5.0.9 are fixed.

Severity

  • CVSS Score: 4.3 / 10 (Medium)
  • Vector String: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


nanoid: custom generators can loop indefinitely when size is zero

CVE-2026-67213 / GHSA-2v37-7h3g-55p8

More information

Details

nanoid (Nano ID) before 5.1.6 contains an infinite loop in the customAlphabet and customRandom functions. When these functions are configured with a size of 0, the internal generation loop never satisfies its exit condition and spins indefinitely, hanging the calling thread. An application that passes an unvalidated, attacker-controlled size of 0 to these functions is exposed to a denial-of-service condition.

Severity

  • CVSS Score: 8.2 / 10 (High)
  • Vector String: CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


nanoid: non-secure generators can loop indefinitely with negative size

CVE-2026-67214 / GHSA-28wg-ghj8-5hjv

More information

Details

nanoid (Nano ID) before 5.1.16 contains an infinite loop in the customAlphabet and nanoid functions of its non-secure module (nanoid/non-secure). When these functions are given a negative size, the loop counter is decremented from a negative value and never reaches its termination condition, spinning indefinitely and hanging the calling thread. An application that passes an unvalidated, attacker-controlled negative size to these functions is exposed to a denial-of-service condition.

Severity

  • CVSS Score: 8.2 / 10 (High)
  • Vector String: CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


nanoid: Integer Overflow or Wraparound

CVE-2026-73086 / GHSA-xwg4-73v4-xw9w

More information

Details

Summary

An 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.

Details

nanoid() at index.js:101 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.

The negative value is passed to fillPool() (index.js:15):

function fillPool(bytes) {
  if (!pool || pool.length < bytes) {       // false: pool exists, -2B < pool.length
    pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
    crypto.getRandomValues(pool)
    poolOffset = 0
  } else if (poolOffset + bytes > pool.length) {  // false: poolOffset + (-2B) < pool.length
    crypto.getRandomValues(pool)
    poolOffset = 0
  }
  poolOffset += bytes  // poolOffset += -2147483648 → deeply negative
}

Neither branch triggers, so the pool is never refreshed. poolOffset becomes ~-2.1 billion.

Subsequent nanoid() calls execute:

for (let i = poolOffset - size; i < poolOffset; i++) {
  id += scopedUrlAlphabet[pool[i] & 63]
}

pool[negative_index] returns undefined. undefined & 63 evaluates to 0. urlAlphabet[0] is 'u'. Every ID becomes "uuuuuuuuuuuuuuuuuuuuu".

The 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.

PoC
import { nanoid } from 'nanoid'

// Step 1: Normal operation
console.log(nanoid())  // e.g., "V1StGXR8_Z5jdHi6B-myT"

// Step 2: Trigger overflow (e.g., from an API parameter)
try { nanoid(2147483648) } catch(e) {}

// Step 3: All subsequent IDs are deterministic
console.log(nanoid())  // "uuuuuuuuuuuuuuuuuuuuu"
console.log(nanoid())  // "uuuuuuuuuuuuuuuuuuuuu"
console.log(nanoid())  // "uuuuuuuuuuuuuuuuuuuuu"
// ... forever, process-wide

Run with: node --experimental-vm-modules poc.mjs

Attack 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).

Impact

Complete loss of ID unpredictability and uniqueness, process-wide, from a single request.

  • All session IDs, CSRF tokens, API keys, and database identifiers generated after the attack are identical and predictable
  • An attacker can predict all tokens issued to other users, enabling session hijacking and authentication bypass
  • The corruption is persistent (survives across requests) and affects all consumers of nanoid in the same process
  • No special privileges or preconditions required — a single unauthenticated request is sufficient
  • Affects any application that passes external input to the size parameter without validation

Severity

  • CVSS Score: 7.4 / 10 (High)
  • Vector String: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


Release Notes

ai/nanoid (nanoid)

v5.1.16

Compare Source

v5.1.15

Compare Source

  • Fixed random pool corruption on big ID sizes.

v5.1.14

Compare Source

  • Fixed npm package size regression.

v5.1.13

Compare Source

  • Fixed npm package size regression.

v5.1.12

Compare Source

  • Moved to npm Provenance and Staged Publishing.

v5.1.11

Compare Source

  • Fixed breaking Nano ID by requesting big ID.

v5.1.10

Compare Source

v5.1.9

Compare Source

  • Fixed npm package size regression.

v5.1.8

Compare Source

v5.1.7

Compare Source

v5.1.6

Compare Source

  • Fixed infinite loop on 0 size for customAlphabet.

v5.1.5

Compare Source

  • Fixed latest version on npm after 3.x release.

v5.1.4

Compare Source

  • Fixed latest version on npm after 3.x release.

v5.1.3

Compare Source

v5.1.2

Compare Source

  • Fixed module docs.

v5.1.1

Compare Source

v5.1.0

Compare Source

v5.0.9

Compare Source

  • Fixed a way to break Nano ID by passing non-integer size (by @​myndzi).

v5.0.8

Compare Source

v5.0.7

Compare Source

v5.0.6

Compare Source

  • Fixed React Native support.

v5.0.5

Compare Source

  • Make browser’s version faster by increasing size a little (by Samuel Elgozi).

v5.0.4

Compare Source

v5.0.3

Compare Source

  • Fixed CLI docs (by Chris Schmich).

v5.0.2

Compare Source

  • Fixed webcrypto import (by Divyansh Singh).

v5.0.1

Compare Source

  • Fixed Node.js 18 support.

v5.0.0

Compare Source


Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from 1e7d32f to 78d5755 Compare August 13, 2025 17:26
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 78d5755 to a627d65 Compare August 19, 2025 13:36
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from a627d65 to b250d87 Compare August 31, 2025 11:07
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from b250d87 to 3e22b04 Compare September 25, 2025 16:33
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 3e22b04 to bbc0227 Compare October 21, 2025 11:15
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from bbc0227 to 299109a Compare November 11, 2025 02:16
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 299109a to 514dd69 Compare November 18, 2025 22:59
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 514dd69 to 7c89228 Compare December 3, 2025 19:10
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 7c89228 to aadb143 Compare December 31, 2025 16:03
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from aadb143 to 1bbe417 Compare January 8, 2026 17:31
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 1bbe417 to ff76ec3 Compare January 19, 2026 20:02
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from ff76ec3 to 0242aa2 Compare February 2, 2026 21:53
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from 0aa73b2 to 138fc8d Compare February 17, 2026 15:46
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 138fc8d to 76d1c2b Compare March 5, 2026 19:13
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 76d1c2b to bba6451 Compare March 13, 2026 16:49
@renovate renovate Bot changed the title fix(deps): update dependency nanoid to v5 [security] fix(deps): update dependency nanoid to v5 [security] - autoclosed Mar 27, 2026
@renovate renovate Bot closed this Mar 27, 2026
@renovate
renovate Bot deleted the renovate/npm-nanoid-vulnerability branch March 27, 2026 01:24
@renovate renovate Bot changed the title fix(deps): update dependency nanoid to v5 [security] - autoclosed fix(deps): update dependency nanoid to v5 [security] Mar 30, 2026
@renovate renovate Bot reopened this Mar 30, 2026
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 3 times, most recently from a6ab955 to 55b895d Compare April 1, 2026 20:34
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 55b895d to 83b478f Compare April 8, 2026 19:55
@renovate renovate Bot changed the title fix(deps): update dependency nanoid to v5 [security] fix(deps): update dependency nanoid to v5 [security] - autoclosed Apr 27, 2026
@renovate renovate Bot closed this Apr 27, 2026
@renovate renovate Bot changed the title fix(deps): update dependency nanoid to v5 [security] - autoclosed fix(deps): update dependency nanoid to v5 [security] Apr 27, 2026
@renovate renovate Bot reopened this Apr 27, 2026
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 3 times, most recently from b9751f1 to e9afd7a Compare April 29, 2026 09:51
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from 9c1395d to e0e5610 Compare May 18, 2026 10:45
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from b15adee to 40dcd8a Compare June 1, 2026 17:58
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 40dcd8a to 3606657 Compare June 11, 2026 16:05
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from 4393425 to a139e01 Compare July 17, 2026 11:35
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from e63bac1 to 2145212 Compare July 24, 2026 19:35
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 2145212 to 09aa174 Compare July 30, 2026 21:12
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 3 times, most recently from 2887b05 to f037859 Compare August 14, 2026 19:15
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from f037859 to 21df561 Compare August 26, 2026 18:48
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 4 times, most recently from e9c4ae7 to dddbe97 Compare September 9, 2026 18:53
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from efdc45f to 72af62b Compare September 15, 2026 20:17
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch 2 times, most recently from 4e03184 to 161b52a Compare October 1, 2026 04:26
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from 161b52a to b7b8a4a Compare October 5, 2026 15:39
@renovate
renovate Bot force-pushed the renovate/npm-nanoid-vulnerability branch from b7b8a4a to 1590dc0 Compare October 13, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

0 participants