CVE-2024-55565: Predictable results in nanoid generation when given non-integer values

Medium CVSS 4.3

OSV id
GHSA-mwcw-c2x4-8c55
Also known as
CVE-2024-55565
Published
Last modified

Affected packages

PackageAffected versionsFixed in
nanoid
npm
>= 4.0.0, < 5.0.9 5.0.9
nanoid
npm
< 3.3.8 3.3.8

Versions we track that it affects: nanoid 3.3.7; nanoid 3.3.7

How to fix it

nanoid (npm)

Upgrade nanoid to 5.0.9 or later.

npm install nanoid@5.0.9
# if it is an indirect dependency: npm update nanoid (or npm audit fix)
  • If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
  • Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.

nanoid (npm)

Upgrade nanoid to 3.3.8 or later.

npm install nanoid@3.3.8
# if it is an indirect dependency: npm update nanoid (or npm audit fix)
  • If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
  • Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.

Not sure whether your project uses an affected version? Check your lockfile below for free.

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.

References

Am I affected?

Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.

or paste its content

Needed when you paste. package.json and pyproject.toml only have version ranges: use the lockfile next to them.

Only package names and versions are checked; the file itself is not kept. We use your email to send this report and nothing else unless you tick the box above. Privacy policy.

About this data

Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.