CVE-2021-23566: Nanoid Exposure Of Sensitive Information To Vulnerability

MODERATE
Advisory Identifier: GHSA-qrpm-p2h7-hrv2
CVSS 5.5
CWE-704 CWE-200
Published
Advisory Summary

CVE-2021-23566 is a MODERATE (CVSS 5.5) exposure of sensitive information to vulnerability (CWE-704: Incorrect Type Conversion or Cast) affecting Nanoid libraries in the npm ecosystem. The issue involves exposure of sensitive information to an unauthorized actor in nanoid. Remediation is available by upgrading affected packages to version 3.1.31.

CVE-2021-23566 at a Glance

CVE Identifier CVE-2021-23566
GHSA Identifier GHSA-qrpm-p2h7-hrv2
Severity MODERATE
CVSS v3.1 Base Score 5.5
CWE Classification CWE-704: Incorrect Type Conversion or Cast
Affected Product Nanoid
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2021-23566

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.

nanoid fixed: 3.1.31
npm install nanoid@3.1.31
Verify Direct and Transitive Dependencies

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-2021-23566, 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.1.31), 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-704: Incorrect Type Conversion or Cast, where the product does not correctly convert an object, resource, or structure from one type to a different type. 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

The package nanoid from 3.0.0, before 3.1.31, are vulnerable to Information Exposure via the valueOf() function which allows to reproduce the last id generated.

CVE-2021-23566 Affected Nanoid Versions

1 component(s)
Fixed Versions:
3.1.31
Product / Package Ecosystem Affected Versions Fixed Version
nanoid
npm
≥ 3.0.0
< 3.1.31
3.1.31

References

Frequently Asked Questions

What is CVE-2021-23566?
CVE-2021-23566 is a security vulnerability in Nanoid involving Exposure of Sensitive Information to an Unauthorized Actor in nanoid under CWE-704: Incorrect Type Conversion or Cast.
Which Nanoid versions are affected?
Affected versions include releases prior to 3.1.31 across affected packages: nanoid.
What version fixes CVE-2021-23566?
Upgrading to 3.1.31 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nanoid affected?
Yes, nanoid is affected in releases prior to 3.1.31. Upgrade your dependency to 3.1.31 or later.
What is the CVSS score of CVE-2021-23566?
CVE-2021-23566 has a CVSS v3.1 base score of 5.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2021-23566?
CVE-2021-23566 is classified under CWE-704: Incorrect Type Conversion or Cast (The product does not correctly convert an object, resource, or structure from one type to a different type.).
How can I check npm dependencies for CVE-2021-23566?
Run the dependency tree command: 'npm ls nanoid'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-qrpm-p2h7-hrv2",
  "modified" : "2025-11-04T16:35:00Z",
  "published" : "2022-01-21T23:57:06Z",
  "aliases" : [ "CVE-2021-23566" ],
  "summary" : "Exposure of Sensitive Information to an Unauthorized Actor in nanoid",
  "details" : "The package nanoid from 3.0.0, before 3.1.31, are vulnerable to Information Exposure via the valueOf() function which allows to reproduce the last id generated.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "nanoid"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.1.31"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-23566"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ai/nanoid/pull/328"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ai/nanoid/commit/2b7bd9332bc49b6330c7ddb08e5c661833db2575"
  }, {
    "type" : "WEB",
    "url" : "https://gist.github.com/artalar/bc6d1eb9a3477d15d2772e876169a444"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ai/nanoid"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/12/msg00025.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2025/01/msg00006.html"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-2332550"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JS-NANOID-2332193"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200", "CWE-704" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-01-18T21:54:04Z",
    "nvd_published_at" : "2022-01-14T20:15:00Z"
  }
}