CWE-338
Weakness AllowedUse of Cryptographically Weak Pseudo-Random Number Generator (PRNG)
Abstraction: Base · Status: Draft
The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong.
When a non-cryptographic PRNG is used in a cryptographic context, it can expose the cryptography to certain types of attacks.
Often a pseudo-random number generator (PRNG) is not designed for cryptography. Sometimes a mediocre source of randomness is sufficient or preferable for algorithms that use random numbers. Weak generators generally take less processing power and/or do not use the precious, finite, entropy sources on a system. While such PRNGs might have very useful features, these same features could be used to break the cryptography.
Mapping guidance
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.
Modes of introduction
REALIZATION: This weakness is caused during implementation of an architectural security tactic.
Detection methods
Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Effectiveness: High
Notes
Maintenance
As of CWE 4.5, terminology related to randomness, entropy, and predictability can vary widely. Within the developer and other communities, "randomness" is used heavily. However, within cryptography, "entropy" is distinct, typically implied as a measurement. There are no commonly-used definitions, even within standards documents and cryptography papers. Future versions of CWE will attempt to define these terms and, if necessary, distinguish between them in ways that are appropriate for different communities but do not reduce the usability of CWE for mapping, understanding, or other scenarios.
Content history
updated Time_of_Introduction
updated Common_Consequences, Relationships, Other_Notes, Taxonomy_Mappings
updated Common_Consequences
updated Common_Consequences, Observed_Examples, References, Relationships
updated Demonstrative_Examples, Potential_Mitigations
updated Applicable_Platforms, Description, Name, Other_Notes
updated Relationships
updated Demonstrative_Examples, Description, Modes_of_Introduction, Relationships, Taxonomy_Mappings
updated Relationships
updated References, Relationships
updated Demonstrative_Examples
updated Maintenance_Notes
updated Relationships
updated Detection_Factors, Relationships
updated Mapping_Notes
updated Observed_Examples
updated Applicable_Platforms, Relationships, Weakness_Ordinalities
384 vulnerabilities reference this CWE, most recent first.
GHSA-RW92-CWM5-WP25
Vulnerability from github – Published: 2026-09-18 21:32 – Updated: 2026-09-18 21:32Cotonti through 1.0.0 derives password recovery validation tokens from md5(microtime()) in users.passrecover.php, creating a predictable token space of approximately one million values per second. Unauthenticated attackers can read the server Date header, precompute candidate tokens within a narrow time window, and probe them against the passrecover authentication endpoint to reset any account password including administrators.
{
"affected": [],
"aliases": [
"CVE-2026-93868"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-09-18T20:17:34Z",
"severity": "CRITICAL"
},
"details": "Cotonti through 1.0.0 derives password recovery validation tokens from md5(microtime()) in users.passrecover.php, creating a predictable token space of approximately one million values per second. Unauthenticated attackers can read the server Date header, precompute candidate tokens within a narrow time window, and probe them against the passrecover authentication endpoint to reset any account password including administrators.",
"id": "GHSA-rw92-cwm5-wp25",
"modified": "2026-09-18T21:32:27Z",
"published": "2026-09-18T21:32:27Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-93868"
},
{
"type": "WEB",
"url": "https://github.com/Cotonti/Cotonti/issues/1890"
},
{
"type": "WEB",
"url": "https://github.com/Cotonti/Cotonti/pull/1898"
},
{
"type": "WEB",
"url": "https://github.com/Cotonti/Cotonti"
},
{
"type": "WEB",
"url": "https://github.com/Cotonti/Cotonti/blob/1.0.0/modules/users/inc/users.passrecover.php"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/cotonti-through-1.0.0-predictable-password-recovery-token-via-weak-prng"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
"type": "CVSS_V4"
}
]
}
GHSA-RXR3-QRG9-4XG5
Vulnerability from github – Published: 2025-04-10 12:31 – Updated: 2025-04-10 15:31In jenkins/ssh-slave Docker images based on Debian, SSH host keys are generated on image creation for images based on Debian, causing all containers based on images of the same version use the same SSH host keys, allowing attackers able to insert themselves into the network path between the SSH client (typically the Jenkins controller) and SSH build agent to impersonate the latter.
{
"affected": [],
"aliases": [
"CVE-2025-32755"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2025-04-10T12:15:16Z",
"severity": "CRITICAL"
},
"details": "In jenkins/ssh-slave Docker images based on Debian, SSH host keys are generated on image creation for images based on Debian, causing all containers based on images of the same version use the same SSH host keys, allowing attackers able to insert themselves into the network path between the SSH client (typically the Jenkins controller) and SSH build agent to impersonate the latter.",
"id": "GHSA-rxr3-qrg9-4xg5",
"modified": "2025-04-10T15:31:48Z",
"published": "2025-04-10T12:31:27Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2025-32755"
},
{
"type": "WEB",
"url": "https://www.jenkins.io/security/advisory/2025-04-10/#SECURITY-3565"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N",
"type": "CVSS_V3"
}
]
}
GHSA-V6PF-6PX3-6H92
Vulnerability from github – Published: 2026-10-01 15:30 – Updated: 2026-10-01 15:30In deployments using BoKS keytab management, affected versions of boks_keytabmd generate Active Directory service-account passwords from a predictable pseudo-random sequence seeded with the current Unix timestamp. An attacker who knows the service principal and can estimate the password-change time can reproduce a limited candidate set and verify candidates offline.
{
"affected": [],
"aliases": [
"CVE-2026-79901"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-10-01T14:17:30Z",
"severity": "CRITICAL"
},
"details": "In deployments using BoKS keytab management, affected versions of boks_keytabmd generate Active Directory service-account passwords from a predictable pseudo-random sequence seeded with the current Unix timestamp. An attacker who knows the service principal and can estimate the password-change time can reproduce a limited candidate set and verify candidates offline.",
"id": "GHSA-v6pf-6px3-6h92",
"modified": "2026-10-01T15:30:41Z",
"published": "2026-10-01T15:30:41Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-79901"
},
{
"type": "WEB",
"url": "https://www.fortra.com/security/advisories/product-security/fi-2026-012"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-VF9W-PWWQ-JWVX
Vulnerability from github – Published: 2026-11-13 12:31 – Updated: 2026-11-13 12:31Zipline before 4.0.2 contains a predictable filename vulnerability that allows attackers to infer other users' upload filenames by recovering the Math.random generator state. Attackers with five consecutive gfycat-style filenames can reconstruct the random state to predict previous and future filenames until the instance restarts, exposing private uploads.
{
"affected": [],
"aliases": [
"CVE-2025-71461"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-11-13T10:17:24Z",
"severity": "MODERATE"
},
"details": "Zipline before 4.0.2 contains a predictable filename vulnerability that allows attackers to infer other users\u0027 upload filenames by recovering the Math.random generator state. Attackers with five consecutive gfycat-style filenames can reconstruct the random state to predict previous and future filenames until the instance restarts, exposing private uploads.",
"id": "GHSA-vf9w-pwwq-jwvx",
"modified": "2026-11-13T12:31:12Z",
"published": "2026-11-13T12:31:11Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/diced/zipline/security/advisories/GHSA-6rg9-q9ww-w2rw"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2025-71461"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/zipline-before-4.0.2-predictable-filenames-via-math-random-state-recovery"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
"type": "CVSS_V4"
}
]
}
GHSA-VH45-F885-3848
Vulnerability from github – Published: 2026-07-24 21:50 – Updated: 2026-08-13 17:41Summary
sm-crypto (npm package 0.4.0, the latest release, published 2026-01-20)
generates SM2 private keys and signing ephemeral scalars from a single
module-wide RNG instance (src/sm2/utils.js: const rng = new SecureRandom()).
SecureRandom is jsbn's PRNG, which seeds an ARC4 stream from
window.crypto.getRandomValues when available. In Node.js — sm-crypto's
primary runtime — window is undefined, so the CSPRNG branch is skipped
and the seed pool is instead filled from Math.random() (V8 xorshift128+,
recoverable from a few outputs) plus new Date().getTime() (wall clock,
attacker-estimable).
Node does expose Web Crypto as globalThis.crypto, but jsbn checks
window.crypto, not globalThis.crypto, so the secure path is never taken.
Consequently every SM2 private key produced by the default
sm2.generateKeyPairHex() and every signing ephemeral scalar is derived from
non-cryptographic sources and is predictable by an attacker who can observe
a few Math.random() outputs and estimate the generation time.
This is the library's default (no-argument) path; no caller-selected
parameter or configuration is required to trigger it. It is reproduced
end-to-end against the unmodified real npm packages (sm-crypto@0.4.0 +
jsbn@1.1.0); the PoC below runs against the real installed package, not a
copy. The defect is still present on the latest published version (0.4.0) and
is not covered by any existing JuneAndGreen/sm-crypto issue (0 afldl issues
exist; the most recent issues are unrelated SM3/HKDF/PBKDF2 feature requests).
Details
jsbn@1.1.0 index.js — RNG pool initialization (fallback taken in Node):
if (rng_pool == null) {
rng_pool = new Array(); rng_pptr = 0; var t;
if (typeof window !== "undefined" && window.crypto) { // <-- false in Node
if (window.crypto.getRandomValues) { /* webcrypto */ }
...
}
while (rng_pptr < rng_psize) { // <-- fallback path
t = Math.floor(65536 * Math.random()); // Math.random()
rng_pool[rng_pptr++] = t >>> 8;
rng_pool[rng_pptr++] = t & 255;
}
rng_pptr = 0;
rng_seed_time(); // + Date.getTime()
}
sm-crypto src/sm2/utils.js:
const { SecureRandom } = require('jsbn');
const rng = new SecureRandom(); // single module-wide RNG
...
function generateKeyPairHex(a, b, c) {
const random = a ? new BigInteger(a, b, c)
: new BigInteger(n.bitLength(), rng); // uses rng
const d = random.mod(n.subtract(BigInteger.ONE)).add(BigInteger.ONE); // private key
...
}
The default (no-argument) call path uses rng, the jsbn ARC4 instance seeded
from Math.random() + time. The same rng feeds the signing ephemeral
scalar during SM2 signing.
PoC
The PoC runs against the real installed npm packages. It pins Math.random
and Date before require('sm-crypto') so jsbn's seed pool is built from
controlled inputs. Three independent fresh Node processes then produce the
same SM2 private key, proving the key is a pure deterministic function of
those non-cryptographic sources. It also prints a probe confirming the fallback
branch is taken in Node.
One-line reproducer
WORK=$(mktemp -d) && cd "$WORK" && npm init -y >/dev/null \
&& npm install sm-crypto@0.4.0 jsbn@1.1.0 >/dev/null \
&& export NODE_PATH="$WORK/node_modules" \
&& node poc.js probe && node poc.js deterministic && node poc.js deterministic
poc.js
/*
* PoC for sm-crypto predictable default RNG in Node.js.
*
* sm-crypto (npm 0.4.0) generates SM2 private keys / ephemeral scalars using
* jsbn's SecureRandom. In a browser jsbn seeds ARC4 from window.crypto, but in
* Node.js `window` is undefined so the CSPRNG branch is skipped and the pool is
* filled from Math.random() plus new Date().getTime(). Both are
* non-cryptographic; the time is attacker-estimable and V8's Math.random is a
* recoverable xorshift128+ stream. Consequently SM2 keys produced by the
* default path are predictable.
*
* This PoC proves the key is a deterministic function of those two inputs: we
* pin Math.random and the clock to fixed values BEFORE sm-crypto (and therefore
* jsbn) is loaded, then generate a keypair. Re-running with the same pinned
* values reproduces the exact same private key.
*/
const MODE = process.argv[2] || 'probe'; // 'probe' | 'deterministic'
if (MODE === 'deterministic') {
// --- pin entropy sources BEFORE requiring sm-crypto/jsbn ---
const fixedTime = 1700000000000;
let s = 0x12345678 >>> 0;
Math.random = function () {
// tiny deterministic LCG standing in for the (already non-crypto) Math.random
s = (Math.imul(s, 1103515245) + 12345) >>> 0;
return s / 0x100000000;
};
const RealDate = globalThis.Date;
class FixedDate extends RealDate {
constructor(...a) { super(...(a.length === 0 ? [fixedTime] : a)); }
}
FixedDate.now = () => fixedTime;
globalThis.Date = FixedDate;
}
const sm2 = require('sm-crypto').sm2;
const kp = sm2.generateKeyPairHex();
console.log('PRIVATE=' + kp.privateKey);
if (MODE === 'probe') {
console.log('--- probe ---');
console.log('typeof window =', typeof window, '(undefined in Node => jsbn CSPRNG branch skipped)');
console.log('typeof globalThis.crypto =', typeof globalThis.crypto, '(Node Web Crypto exists but jsbn checks window.crypto, not globalThis.crypto)');
console.log('Math.random sample =', Math.random());
console.log('Date.now() =', Date.now(), '(attacker-estimable, mixed into ARC4 seed)');
}
Real captured output:
===== PROBE (real default path, no patching) =====
PRIVATE=6072e45733a4187791ec28ce906fef18c7d33c8529969e1a852833c4349cfc38
--- probe ---
typeof window = undefined (undefined in Node => jsbn CSPRNG branch skipped)
typeof globalThis.crypto = object (Node Web Crypto exists but jsbn checks window.crypto, not globalThis.crypto)
Math.random sample = 0.704452488761137
Date.now() = 1784455686795 (attacker-estimable, mixed into ARC4 seed)
===== DETERMINISTIC (Math.random + Date pinned before require sm-crypto) =====
--- run #1 --- PRIVATE=143268fa0939b4da09eab8c9a2e027a04555b6c433fef4f54fc5edd517c0a6b1
--- run #2 --- PRIVATE=143268fa0939b4da09eab8c9a2e027a04555b6c433fef4f54fc5edd517c0a6b1
The two deterministic runs produce the identical SM2 private key,
demonstrating the key is a pure function of Math.random() + wall-clock time.
Impact
Private-key recovery / signature forgery of any SM2 keypair generated with the default API in Node.js. This is the most serious class of defect for a maintained SM2 library: the default key-generation path is non-cryptographic on its primary runtime.
- Private-key recovery. Any SM2 keypair generated with the default API in
Node is derived from
Math.random()+ wall-clock time. An attacker who can observe a fewMath.random()outputs (V8xorshift128+state is recoverable from ~4 observed doubles) and estimate the generation time can reproduce the private key and forge signatures. - Signing ephemeral reuse / forgery. The same RNG feeds the ephemeral
scalar
kduring SM2 signing; a predictablekleaks the private key from a single signature (SM2 is EC-Schnorr-like:s = (k^-1)(e + d·r) mod n). - Pre-authentication / no privilege required: anyone who can induce a victim to generate a key or sign a message (the normal API use) is positioned to predict the secret material.
Suggested fix
Seed the RNG from a CSPRNG in Node. The simplest fix in sm-crypto is to
replace the jsbn ARC4 instance with Web Crypto / crypto.randomBytes:
// src/sm2/utils.js
const nodeCrypto = (typeof require === 'function') ? require('crypto') : null;
function csrandBytes(n) {
if (nodeCrypto) return nodeCrypto.randomBytes(n); // Node
if (globalThis.crypto) { // Web Crypto (browser/Node ≥ 19)
const b = new Uint8Array(n); globalThis.crypto.getRandomValues(b); return b;
}
throw new Error('no CSPRNG available');
}
and use it to generate the private key / ephemeral directly, or to reseed the
jsbn pool. A separate (upstream) fix belongs in jsbn to check
globalThis.crypto in addition to window.crypto.
Affected versions
- npm
sm-crypto0.4.0 (latest, published 2026-01-20). Depends onjsbn ^1.1.0(jsbn@1.1.0, whoseindex.jsRNG is the root cause). - Runtime: Node.js (the primary runtime; in a browser the jsbn CSPRNG branch is taken).
Credit
Reported by the diff/ambidiff security research effort (afldl).
{
"affected": [
{
"package": {
"ecosystem": "npm",
"name": "sm-crypto"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "0.5.0"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-73567"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": true,
"github_reviewed_at": "2026-07-24T21:50:45Z",
"nvd_published_at": null,
"severity": "CRITICAL"
},
"details": "## Summary\n\n`sm-crypto` (npm package **0.4.0**, the latest release, published 2026-01-20)\ngenerates SM2 private keys and signing ephemeral scalars from a single\nmodule-wide RNG instance (`src/sm2/utils.js`: `const rng = new SecureRandom()`).\n`SecureRandom` is jsbn\u0027s PRNG, which seeds an **ARC4** stream from\n`window.crypto.getRandomValues` when available. **In Node.js \u2014 sm-crypto\u0027s\nprimary runtime \u2014 `window` is `undefined`, so the CSPRNG branch is skipped**\nand the seed pool is instead filled from `Math.random()` (V8 `xorshift128+`,\nrecoverable from a few outputs) plus `new Date().getTime()` (wall clock,\nattacker-estimable).\n\nNode *does* expose Web Crypto as `globalThis.crypto`, but jsbn checks\n`window.crypto`, not `globalThis.crypto`, so the secure path is never taken.\nConsequently every SM2 private key produced by the default\n`sm2.generateKeyPairHex()` and every signing ephemeral scalar is derived from\nnon-cryptographic sources and is **predictable** by an attacker who can observe\na few `Math.random()` outputs and estimate the generation time.\n\nThis is the library\u0027s **default** (no-argument) path; no caller-selected\nparameter or configuration is required to trigger it. It is reproduced\nend-to-end against the unmodified real npm packages (`sm-crypto@0.4.0` +\n`jsbn@1.1.0`); the PoC below runs against the real installed package, not a\ncopy. The defect is still present on the latest published version (0.4.0) and\nis not covered by any existing `JuneAndGreen/sm-crypto` issue (0 afldl issues\nexist; the most recent issues are unrelated SM3/HKDF/PBKDF2 feature requests).\n\n## Details\n\n`jsbn@1.1.0` `index.js` \u2014 RNG pool initialization (fallback taken in Node):\n\n```js\nif (rng_pool == null) {\n rng_pool = new Array(); rng_pptr = 0; var t;\n if (typeof window !== \"undefined\" \u0026\u0026 window.crypto) { // \u003c-- false in Node\n if (window.crypto.getRandomValues) { /* webcrypto */ }\n ...\n }\n while (rng_pptr \u003c rng_psize) { // \u003c-- fallback path\n t = Math.floor(65536 * Math.random()); // Math.random()\n rng_pool[rng_pptr++] = t \u003e\u003e\u003e 8;\n rng_pool[rng_pptr++] = t \u0026 255;\n }\n rng_pptr = 0;\n rng_seed_time(); // + Date.getTime()\n}\n```\n\n`sm-crypto` `src/sm2/utils.js`:\n\n```js\nconst { SecureRandom } = require(\u0027jsbn\u0027);\nconst rng = new SecureRandom(); // single module-wide RNG\n...\nfunction generateKeyPairHex(a, b, c) {\n const random = a ? new BigInteger(a, b, c)\n : new BigInteger(n.bitLength(), rng); // uses rng\n const d = random.mod(n.subtract(BigInteger.ONE)).add(BigInteger.ONE); // private key\n ...\n}\n```\n\nThe default (no-argument) call path uses `rng`, the jsbn ARC4 instance seeded\nfrom `Math.random()` + time. The same `rng` feeds the signing ephemeral\nscalar during SM2 signing.\n\n## PoC\n\nThe PoC runs against the real installed npm packages. It pins `Math.random`\nand `Date` **before** `require(\u0027sm-crypto\u0027)` so jsbn\u0027s seed pool is built from\ncontrolled inputs. Three independent fresh Node processes then produce the\n**same** SM2 private key, proving the key is a pure deterministic function of\nthose non-cryptographic sources. It also prints a probe confirming the fallback\nbranch is taken in Node.\n\n### One-line reproducer\n\n```bash\nWORK=$(mktemp -d) \u0026\u0026 cd \"$WORK\" \u0026\u0026 npm init -y \u003e/dev/null \\\n \u0026\u0026 npm install sm-crypto@0.4.0 jsbn@1.1.0 \u003e/dev/null \\\n \u0026\u0026 export NODE_PATH=\"$WORK/node_modules\" \\\n \u0026\u0026 node poc.js probe \u0026\u0026 node poc.js deterministic \u0026\u0026 node poc.js deterministic\n```\n\n### `poc.js`\n\n```js\n/*\n * PoC for sm-crypto predictable default RNG in Node.js.\n *\n * sm-crypto (npm 0.4.0) generates SM2 private keys / ephemeral scalars using\n * jsbn\u0027s SecureRandom. In a browser jsbn seeds ARC4 from window.crypto, but in\n * Node.js `window` is undefined so the CSPRNG branch is skipped and the pool is\n * filled from Math.random() plus new Date().getTime(). Both are\n * non-cryptographic; the time is attacker-estimable and V8\u0027s Math.random is a\n * recoverable xorshift128+ stream. Consequently SM2 keys produced by the\n * default path are predictable.\n *\n * This PoC proves the key is a deterministic function of those two inputs: we\n * pin Math.random and the clock to fixed values BEFORE sm-crypto (and therefore\n * jsbn) is loaded, then generate a keypair. Re-running with the same pinned\n * values reproduces the exact same private key.\n */\n\nconst MODE = process.argv[2] || \u0027probe\u0027; // \u0027probe\u0027 | \u0027deterministic\u0027\n\nif (MODE === \u0027deterministic\u0027) {\n // --- pin entropy sources BEFORE requiring sm-crypto/jsbn ---\n const fixedTime = 1700000000000;\n let s = 0x12345678 \u003e\u003e\u003e 0;\n Math.random = function () {\n // tiny deterministic LCG standing in for the (already non-crypto) Math.random\n s = (Math.imul(s, 1103515245) + 12345) \u003e\u003e\u003e 0;\n return s / 0x100000000;\n };\n const RealDate = globalThis.Date;\n class FixedDate extends RealDate {\n constructor(...a) { super(...(a.length === 0 ? [fixedTime] : a)); }\n }\n FixedDate.now = () =\u003e fixedTime;\n globalThis.Date = FixedDate;\n}\n\nconst sm2 = require(\u0027sm-crypto\u0027).sm2;\nconst kp = sm2.generateKeyPairHex();\nconsole.log(\u0027PRIVATE=\u0027 + kp.privateKey);\n\nif (MODE === \u0027probe\u0027) {\n console.log(\u0027--- probe ---\u0027);\n console.log(\u0027typeof window =\u0027, typeof window, \u0027(undefined in Node =\u003e jsbn CSPRNG branch skipped)\u0027);\n console.log(\u0027typeof globalThis.crypto =\u0027, typeof globalThis.crypto, \u0027(Node Web Crypto exists but jsbn checks window.crypto, not globalThis.crypto)\u0027);\n console.log(\u0027Math.random sample =\u0027, Math.random());\n console.log(\u0027Date.now() =\u0027, Date.now(), \u0027(attacker-estimable, mixed into ARC4 seed)\u0027);\n}\n```\n\nReal captured output:\n\n```\n===== PROBE (real default path, no patching) =====\nPRIVATE=6072e45733a4187791ec28ce906fef18c7d33c8529969e1a852833c4349cfc38\n--- probe ---\ntypeof window = undefined (undefined in Node =\u003e jsbn CSPRNG branch skipped)\ntypeof globalThis.crypto = object (Node Web Crypto exists but jsbn checks window.crypto, not globalThis.crypto)\nMath.random sample = 0.704452488761137\nDate.now() = 1784455686795 (attacker-estimable, mixed into ARC4 seed)\n\n===== DETERMINISTIC (Math.random + Date pinned before require sm-crypto) =====\n--- run #1 --- PRIVATE=143268fa0939b4da09eab8c9a2e027a04555b6c433fef4f54fc5edd517c0a6b1\n--- run #2 --- PRIVATE=143268fa0939b4da09eab8c9a2e027a04555b6c433fef4f54fc5edd517c0a6b1\n```\n\nThe two deterministic runs produce the **identical** SM2 private key,\ndemonstrating the key is a pure function of `Math.random()` + wall-clock time.\n\n## Impact\n\n**Private-key recovery / signature forgery of any SM2 keypair generated with\nthe default API in Node.js.** This is the most serious class of defect for a\nmaintained SM2 library: the *default* key-generation path is\nnon-cryptographic on its primary runtime.\n\n- **Private-key recovery.** Any SM2 keypair generated with the default API in\n Node is derived from `Math.random()` + wall-clock time. An attacker who can\n observe a few `Math.random()` outputs (V8 `xorshift128+` state is\n recoverable from ~4 observed doubles) and estimate the generation time can\n reproduce the private key and forge signatures.\n- **Signing ephemeral reuse / forgery.** The same RNG feeds the ephemeral\n scalar `k` during SM2 signing; a predictable `k` leaks the private key from a\n single signature (SM2 is EC-Schnorr-like: `s = (k^-1)(e + d\u00b7r) mod n`).\n- Pre-authentication / no privilege required: anyone who can induce a victim\n to generate a key or sign a message (the normal API use) is positioned to\n predict the secret material.\n\n### Suggested fix\n\nSeed the RNG from a CSPRNG in Node. The simplest fix in `sm-crypto` is to\nreplace the jsbn ARC4 instance with Web Crypto / `crypto.randomBytes`:\n\n```js\n// src/sm2/utils.js\nconst nodeCrypto = (typeof require === \u0027function\u0027) ? require(\u0027crypto\u0027) : null;\nfunction csrandBytes(n) {\n if (nodeCrypto) return nodeCrypto.randomBytes(n); // Node\n if (globalThis.crypto) { // Web Crypto (browser/Node \u2265 19)\n const b = new Uint8Array(n); globalThis.crypto.getRandomValues(b); return b;\n }\n throw new Error(\u0027no CSPRNG available\u0027);\n}\n```\n\nand use it to generate the private key / ephemeral directly, or to reseed the\njsbn pool. A separate (upstream) fix belongs in jsbn to check\n`globalThis.crypto` in addition to `window.crypto`.\n\n### Affected versions\n\n- npm `sm-crypto` **0.4.0** (latest, published 2026-01-20). Depends on\n `jsbn ^1.1.0` (`jsbn@1.1.0`, whose `index.js` RNG is the root cause).\n- Runtime: Node.js (the primary runtime; in a browser the jsbn CSPRNG branch\n is taken).\n\n## Credit\n\nReported by the diff/ambidiff security research effort (afldl).",
"id": "GHSA-vh45-f885-3848",
"modified": "2026-08-13T17:41:00Z",
"published": "2026-07-24T21:50:45Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/JuneAndGreen/sm-crypto/security/advisories/GHSA-vh45-f885-3848"
},
{
"type": "WEB",
"url": "https://github.com/JuneAndGreen/sm-crypto/commit/1f9bd7bd160c24efd9c26c8f7fda997c68c823d0"
},
{
"type": "PACKAGE",
"url": "https://github.com/JuneAndGreen/sm-crypto"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N",
"type": "CVSS_V3"
}
],
"summary": "sm-crypto: Predictable SM2 key generation in Node.js: default RNG uses Math.random + wall clock"
}
GHSA-VHQP-3RVR-75RX
Vulnerability from github – Published: 2026-07-20 09:31 – Updated: 2026-07-20 21:31Crypt::Password versions through 0.28 for Perl generate insecure random values for salts.
These versions use the built-in rand function, which is predictable and unsuitable for cryptography.
{
"affected": [],
"aliases": [
"CVE-2026-16235"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-07-20T07:16:37Z",
"severity": "CRITICAL"
},
"details": "Crypt::Password versions through 0.28 for Perl generate insecure random values for salts.\n\nThese versions use the built-in rand function, which is predictable and unsuitable for cryptography.",
"id": "GHSA-vhqp-3rvr-75rx",
"modified": "2026-07-20T21:31:44Z",
"published": "2026-07-20T09:31:08Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-16235"
},
{
"type": "WEB",
"url": "https://metacpan.org/release/DRSTEVE/Crypt-Password-0.28/source/lib/Crypt/Password.pm#L306-309"
},
{
"type": "WEB",
"url": "http://www.openwall.com/lists/oss-security/2026/07/20/3"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-VJFH-J2FF-QXW8
Vulnerability from github – Published: 2022-10-14 12:00 – Updated: 2025-05-16 15:30D-Link COVR 1200,1202,1203 v1.08 was discovered to have a predictable seed in a Pseudo-Random Number Generator.
{
"affected": [],
"aliases": [
"CVE-2022-42159"
],
"database_specific": {
"cwe_ids": [
"CWE-335",
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2022-10-13T19:15:00Z",
"severity": "MODERATE"
},
"details": "D-Link COVR 1200,1202,1203 v1.08 was discovered to have a predictable seed in a Pseudo-Random Number Generator.",
"id": "GHSA-vjfh-j2ff-qxw8",
"modified": "2025-05-16T15:30:30Z",
"published": "2022-10-14T12:00:25Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-42159"
},
{
"type": "WEB",
"url": "https://github.com/14isnot40/vul_discovery/blob/master/D-Link%20COVR%2012xx%20.pdf"
},
{
"type": "WEB",
"url": "https://www.dlink.com/en/security-bulletin"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N",
"type": "CVSS_V3"
}
]
}
GHSA-VMRC-27XM-26FJ
Vulnerability from github – Published: 2026-11-19 15:31 – Updated: 2026-11-19 15:31Dell PowerStore SDNAS contains a cryptographically weak PRNG vulnerability that could allow a network attacker to decrypt or tamper with NAS SSH/SFTP sessions.
{
"affected": [],
"aliases": [
"CVE-2026-111509"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-11-19T13:17:27Z",
"severity": "CRITICAL"
},
"details": "Dell PowerStore SDNAS contains a cryptographically weak PRNG vulnerability that could allow a network attacker to decrypt or tamper with NAS SSH/SFTP sessions.",
"id": "GHSA-vmrc-27xm-26fj",
"modified": "2026-11-19T15:31:06Z",
"published": "2026-11-19T15:31:06Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-111509"
},
{
"type": "WEB",
"url": "https://www.dell.com/support/kbdoc/en-us/000527640/dsa-2026-479-dell-powerstore-t-security-update-for-multiple-vulnerabilities"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N",
"type": "CVSS_V3"
}
]
}
GHSA-VRGH-5W3C-GGF8
Vulnerability from github – Published: 2021-12-03 20:38 – Updated: 2021-12-03 15:18showdoc is vulnerable to Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG).
{
"affected": [
{
"package": {
"ecosystem": "Packagist",
"name": "showdoc/showdoc"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "2.9.13"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2021-3990"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": true,
"github_reviewed_at": "2021-12-02T21:16:12Z",
"nvd_published_at": "2021-12-01T11:15:00Z",
"severity": "MODERATE"
},
"details": "showdoc is vulnerable to Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG).",
"id": "GHSA-vrgh-5w3c-ggf8",
"modified": "2021-12-03T15:18:33Z",
"published": "2021-12-03T20:38:50Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-3990"
},
{
"type": "WEB",
"url": "https://github.com/star7th/showdoc/commit/a9886f26c08225e0adca75c67dfca3f7c42b87d0"
},
{
"type": "PACKAGE",
"url": "https://github.com/star7th/showdoc"
},
{
"type": "WEB",
"url": "https://huntr.dev/bounties/0680067d-56a7-4412-b06e-a267e850ae9f"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N",
"type": "CVSS_V3"
}
],
"summary": "showdoc is vulnerable to Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)"
}
GHSA-VXR9-MR85-JWJW
Vulnerability from github – Published: 2022-05-14 03:49 – Updated: 2022-05-14 03:49It was discovered that QtPass before 1.2.1, when using the built-in password generator, generates possibly predictable and enumerable passwords. This only applies to the QtPass GUI.
{
"affected": [],
"aliases": [
"CVE-2017-18021"
],
"database_specific": {
"cwe_ids": [
"CWE-338"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2018-01-05T19:29:00Z",
"severity": "CRITICAL"
},
"details": "It was discovered that QtPass before 1.2.1, when using the built-in password generator, generates possibly predictable and enumerable passwords. This only applies to the QtPass GUI.",
"id": "GHSA-vxr9-mr85-jwjw",
"modified": "2022-05-14T03:49:11Z",
"published": "2022-05-14T03:49:11Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2017-18021"
},
{
"type": "WEB",
"url": "https://github.com/IJHack/QtPass/issues/338"
},
{
"type": "WEB",
"url": "https://github.com/IJHack/QtPass/releases/tag/v1.2.1"
},
{
"type": "WEB",
"url": "https://lists.zx2c4.com/pipermail/password-store/2018-January/003165.html"
},
{
"type": "WEB",
"url": "https://qtpass.org"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
Mitigation
Use functions or hardware which use a hardware-based random number generation for all crypto. This is the recommended solution. Use CyptGenRandom on Windows, or hw_rand() on Linux.
No CAPEC attack patterns related to this CWE.