fix(deps): update dependency sm-crypto to ^0.5.0 [security] - #917
Open
renovate[bot] wants to merge 1 commit into
Open
fix(deps): update dependency sm-crypto to ^0.5.0 [security]#917renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
Contributor
Author
Branch automerge failureThis PR was configured for branch automerge. However, this is not possible, so it has been raised as a PR instead.
|
renovate
Bot
force-pushed
the
renovate/npm-sm-crypto-vulnerability
branch
7 times, most recently
from
July 31, 2026 04:44
1f92f18 to
c12de22
Compare
renovate
Bot
force-pushed
the
renovate/npm-sm-crypto-vulnerability
branch
from
July 31, 2026 17:13
c12de22 to
ae23730
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^0.4.0→^0.5.0sm-crypto: Predictable SM2 key generation in Node.js: default RNG uses Math.random + wall clock
GHSA-vh45-f885-3848
More information
Details
Summary
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()).SecureRandomis jsbn's PRNG, which seeds an ARC4 stream fromwindow.crypto.getRandomValueswhen available. In Node.js — sm-crypto'sprimary runtime —
windowisundefined, so the CSPRNG branch is skippedand the seed pool is instead filled from
Math.random()(V8xorshift128+,recoverable from a few outputs) plus
new Date().getTime()(wall clock,attacker-estimable).
Node does expose Web Crypto as
globalThis.crypto, but jsbn checkswindow.crypto, notglobalThis.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 fromnon-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 acopy. The defect is still present on the latest published version (0.4.0) and
is not covered by any existing
JuneAndGreen/sm-cryptoissue (0 afldl issuesexist; the most recent issues are unrelated SM3/HKDF/PBKDF2 feature requests).
Details
jsbn@1.1.0index.js— RNG pool initialization (fallback taken in Node):sm-cryptosrc/sm2/utils.js:The default (no-argument) call path uses
rng, the jsbn ARC4 instance seededfrom
Math.random()+ time. The samerngfeeds the signing ephemeralscalar during SM2 signing.
PoC
The PoC runs against the real installed npm packages. It pins
Math.randomand
Datebeforerequire('sm-crypto')so jsbn's seed pool is built fromcontrolled 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
poc.jsReal captured output:
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.
Node is derived from
Math.random()+ wall-clock time. An attacker who canobserve a few
Math.random()outputs (V8xorshift128+state isrecoverable from ~4 observed doubles) and estimate the generation time can
reproduce the private key and forge signatures.
scalar
kduring SM2 signing; a predictablekleaks the private key from asingle signature (SM2 is EC-Schnorr-like:
s = (k^-1)(e + d·r) mod n).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-cryptois toreplace the jsbn ARC4 instance with Web Crypto /
crypto.randomBytes: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.cryptoin addition towindow.crypto.Affected versions
sm-crypto0.4.0 (latest, published 2026-01-20). Depends onjsbn ^1.1.0(jsbn@1.1.0, whoseindex.jsRNG is the root cause).is taken).
Credit
Reported by the diff/ambidiff security research effort (afldl).
Severity
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Release Notes
JuneAndGreen/sm-crypto (sm-crypto)
v0.5.0Compare Source
Configuration
📅 Schedule: (UTC)
🚦 Automerge: Enabled.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.