# CVE-2021-41117: juliangruber keypair insecure random number generation

Source: https://junglewise.ai/threats/cve-2021-41117-juliangruber-keypair-insecure-random-number-generation  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2021-10-11. Updated: 2026-05-14  
License: CC BY 4.0 with a link back

CVE-2021-41117 · Severity: low · CVSS 3.1 · Published 2021-10-11

The keypair library, used for generating RSA encryption keys in JavaScript environments, contains a flaw that results in the creation of weak, predictable security keys. Because the random number generator used to build these keys is flawed, an attacker could potentially guess a victim's private key, allowing them to decrypt private communications or gain unauthorized access to accounts. This issue is particularly severe for applications running in Node.js environments where the library fails to use secure system-level random number sources.

Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2021-41117 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-41117 being exploited in the wild.

**How severe is CVE-2021-41117?** Low severity, with a CVSS score of 3.1, published 11 October 2021.

**Which products and versions are affected?** keypair (npm) SEMVER:introduced=0,fixed=1.0.4.

**Is there a fix for CVE-2021-41117?** Yes. keypair (npm): upgrade to 1.0.4 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2021-41117 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2021-41117?** Check whether you run keypair (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- keypair (npm): upgrade to 1.0.4 or later

  ```sh
  npm install keypair@1.0.4
  ```


## Technical details

The keypair library (versions <= 1.0.3) suffers from multiple PRNG weaknesses, primarily affecting Node.js environments. First, a variable shadowing bug causes the library to fail to detect the native Node.js 'crypto' module, falling back to an insecure Lehmer LCG seeded by Math.random(). Second, a coding error in the fallback path uses a double 'String.fromCharCode' conversion (String.fromCharCode(String.fromCharCode(next & 0xFF))), which results in approximately 97% of the entropy seed bytes being set to zero. This drastically reduces the keyspace, leading to the generation of identical or easily guessable RSA keys. Attackers can exploit this to perform key recovery attacks, decrypting traffic or impersonating users. The issue is fixed in version 1.0.4 by correctly requiring the crypto module and fixing the encoding logic.

## Affected products

- juliangruber keypair <= 1.0.3

## Identifiers

- CVE-2021-41117
- GHSA-3f99-hvg4-qjwj

## Timeline

- 2021-09-30: disclosed: Reported to maintainer by GitHub Security Lab
- 2021-10-11: patched: Version 1.0.4 released
- 2021-10-11: advisory

## References

- [https://github.com/juliangruber/keypair/security/advisories/GHSA-3f99-hvg4-qjwj](https://github.com/juliangruber/keypair/security/advisories/GHSA-3f99-hvg4-qjwj)
- [https://github.com/juliangruber/keypair/commit/9596418d3363d3e757676c0b6a8f2d35a9d1cb18](https://github.com/juliangruber/keypair/commit/9596418d3363d3e757676c0b6a8f2d35a9d1cb18)
- [https://github.com/juliangruber/keypair](https://github.com/juliangruber/keypair)
- [https://github.com/juliangruber/keypair/releases/tag/v1.0.4](https://github.com/juliangruber/keypair/releases/tag/v1.0.4)
