Home / juliangruber / keypair / CVE-2021-41117
CVE-2021-41117: is it exploited, and which versions of juliangruber keypair are affected and fixed?
CVE-2021-41117 is an incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG) vulnerability in juliangruber keypair. It is not known to be exploited: it is not in CISA's Known Exploited Vulnerabilities catalog (catalog 2026.11.30, read December 3, 2026, 18:09 UTC). Affected: keypair before 1.0.4 (GitHub advisory GHSA-3f99-hvg4-qjwj). Fixed in 1.0.4 (GitHub advisory GHSA-3f99-hvg4-qjwj). Severity: High (8.7, CVSS 3.1, from GitHub_M).
Data checked December 3, 2026: last read CISA KEV December 3, 2026, 18:09 UTC, CVE record November 19, 2026, 07:15 UTC and NVD November 19, 2026, 07:54 UTC.
What is CVE-2021-41117?
Insecure random number generation
keypair is a a RSA PEM key generator written in javascript. keypair implements a lot of cryptographic primitives on its own or by borrowing from other libraries where possible, including node-forge. An issue was discovered where this library was generating identical RSA keys used in SSH. This would mean that the library is generating identical P, Q (and thus N) values which, in practical terms, is impossible with RSA-2048 keys. Generating identical values, repeatedly, usually indicates an issue with poor random number generation, or, poor handling of CSPRNG output. Issue 1: Poor random number generation (`GHSL-2021-1012`). The library does not rely entirely on a platform provided CSPRNG, rather, it uses it's own counter-based CMAC approach. Where things go wrong is seeding the CMAC implementation with "true" random data in the function `defaultSeedFile`. In order to seed the AES-CMAC generator, the library will take two different approaches depending on the JavaScript execution environment. In a browser, the library will use [`window.crypto.getRandomValues()`](https://github.com/juliangruber/keypair/blob/87c62f255baa12c1ec4f98a91600f82af80be6db/index.js#L971). However, in a nodeJS execution environment, the `window` object is not defined, so it goes down a much less secure solution, also of which has a bug in it. It does look like the library tries to use node's CSPRNG when possible unfortunately, it looks like the `crypto` object is null because a variable was declared with the same name, and set to `null`. So the node CSPRNG path is never taken. However, when `window.crypto.getRandomValues()` is not available, a Lehmer LCG random number generator is used to seed the CMAC counter, and the LCG is seeded with `Math.random`. While this is poor and would likely qualify in a security bug in itself, it does not explain the extreme frequency in which duplicate keys occur. The main flaw: The output from the Lehmer LCG is encoded incorrectly. The specific [line][https://github.com/juliangruber/keypair/blob/87c62f255baa12c1ec4f98a91600f82af80be6db/index.js#L1008] with the flaw is: `b.putByte(String.fromCharCode(next & 0xFF))` The [definition](https://github.com/juliangruber/keypair/blob/87c62f255baa12c1ec4f98a91600f82af80be6db/index.js#L350-L352) of `putByte` is `util.ByteBuffer.prototype.putByte = function(b) {this.data += String.fromCharCode(b);};`. Simplified, this is `String.fromCharCode(String.fromCharCode(next & 0xFF))`. The double `String.fromCharCode` is almost certainly unintentional and the source of weak seeding. Unfortunately, this does not result in an error. Rather, it results most of the buffer containing zeros. Since we are masking with 0xFF, we can determine that 97% of the output from the LCG are converted to zeros. The only outputs that result in meaningful values are outputs 48 through 57, inclusive. The impact is that each byte in the RNG seed has a 97% chance of being 0 due to incorrect conversion. When it is not, the bytes are 0 through 9. In summary, there are three immediate concerns: 1. The library has an insecure random number fallback path. Ideally the library would require a strong CSPRNG instead of attempting to use a LCG and `Math.random`. 2. The library does not correctly use a strong random number generator when run in NodeJS, even though a strong CSPRNG is available. 3. The fallback path has an issue in the implementation where a majority of the seed data is going to effectively be zero. Due to the poor random number generation, keypair generates RSA keys that are relatively easy to guess. This could enable an attacker to decrypt confidential messages or gain authorized access to an account belonging to the victim.
From the CVE record by GitHub_M, last updated August 4, 2024, 02:59 UTC.
Which versions are affected, and which fix it?
| Vendor | Product | Affected | Fixed or not affected from |
|---|---|---|---|
| juliangruber | keypair | <= 1.0.3 |
As the CVE record by GitHub_M states it, last updated August 4, 2024. Version ranges are the CNA's; a version the record calls not affected is usually the fix.
Which packages are affected, and in which version is each fixed?
| Ecosystem | Package | Affected | Fixed in | Advisory |
|---|---|---|---|---|
| npm | keypair | < 1.0.4 | 1.0.4 | GHSA-3f99-hvg4-qjwj |
GitHub Advisory Database, reviewed advisories (CC BY 4.0); advisory updated October 11, 2021. Summary: Insecure random number generation in keypair.
Which products and versions does the NVD list as affected?
| Vendor | Product | Versions | Type |
|---|---|---|---|
| keypair project | keypair | before 1.0.4 | application |
NVD analysis (status Modified), last modified June 17, 2026, 04:07 UTC.
How severe is CVE-2021-41117?
| Score | Version | Vector | Source |
|---|---|---|---|
| High 8.7 | CVSS 3.1 | CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:N | GitHub_M |
| Critical 9.1 | CVSS 3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N | NVD |
| Medium 6.4 | CVSS 2.0 | AV:N/AC:L/Au:N/C:P/I:P/A:N | NVD |
Each score is shown as its source gave it: the CNA that wrote the record, CISA's ADP (vulnrichment) and the NVD. They can differ.
What the ratings mean: in CVSS 3 and 4, scores run from 0 to 10, with Low 0.1 to 3.9, Medium 4.0 to 6.9, High 7.0 to 8.9 and Critical 9.0 to 10.0. CVSS 2 has no Critical band: its High runs from 7.0 to 10.0. The vector lists how the flaw is reached (network, local), what an attacker needs (privileges, a user's click) and what it can harm.
Is CVE-2021-41117 exploited in the wild?
- CISA KEV
- Not listed (catalog 2026.11.30)
- EPSS
- 3.19% probability of exploitation activity in the next 30 days, percentile 88.5 (FIRST EPSS, scores of December 3, 2026)
What kind of flaw is it?
- CWE-335 Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG)
Where are the vendor advisories and references?
- https://github.com/juliangruber/keypair/security/advisories/GHSA-3f99-hvg4-qjwj x_refsource_CONFIRM
- https://securitylab.github.com/advisories/GHSL-2021-1012-keypair/ x_refsource_MISC
When was it published, and where is the official record?
- Reserved
- September 15, 2021
- Published
- October 11, 2021, 17:10 UTC
- CVE record updated
- August 4, 2024, 02:59 UTC by GitHub_M
- NVD
- Modified, last modified June 17, 2026, 04:07 UTC
- Last checked
- CVE list November 19, 2026, 07:15 UTC; NVD November 19, 2026, 07:54 UTC; KEV December 3, 2026, 18:09 UTC; EPSS December 3, 2026
- Official record
- cve.org · NVD
Questions about CVE-2021-41117
Is CVE-2021-41117 exploited in the wild?
Not as far as CISA knows: it is not in the Known Exploited Vulnerabilities catalog, read December 3, 2026, 18:09 UTC. FIRST's EPSS gives it a 3.19% chance of exploitation activity in the next 30 days (scores of December 3, 2026).
Which versions of juliangruber keypair are affected by CVE-2021-41117?
keypair before 1.0.4, per the GitHub advisory GHSA-3f99-hvg4-qjwj. The tables above give every range the sources list.
Which version fixes CVE-2021-41117?
1.0.4, per the GitHub advisory GHSA-3f99-hvg4-qjwj. Check the vendor's advisory before you rely on it.
How severe is CVE-2021-41117?
High (8.7, CVSS 3.1, from GitHub_M). The severity table above shows each score with its source.
Where is the official record of CVE-2021-41117?
The CVE Program's record is at cve.org and the NVD's at nvd.nist.gov. For a fix, the vendor's own advisory is the one to follow.