All the vulnerabilities related to the version 2.0.0 of the package
Improper calculations in ECC implementation can trigger a Denial-of-Service (DoS)
When using the non-default "fallback" crypto back-end, ECC operations in node-jose
can trigger a Denial-of-Service (DoS) condition, due to a possible infinite loop in an internal calculation. For some ECC operations, this condition is triggered randomly; for others, it can be triggered by malicious input.
The JOSE logic implemented by node-jose
usually relies on an external cryptographic library for the underlying cryptographic primitives that JOSE operations require. When WebCrypto or the Node crypto
module are available, they are used. When neither of these libraries is available, node-jose
includes its own "fallback" implementations of some algorithms based on node-forge
, in particular implementations of ECDH and ECDSA.
A various points, these algorithm implementations need to compute to the X coordinate of an elliptic curve point. This is done by calling the getX()
method of the object representing the point, which is an alias of the function pointFpGetX()
in lib/deps/ecc/math.js
.
Computing the X coordinate from the form in which the point is stored requires computing the modular inverse of the Z coordinate, using the modInverse
function from the jsbn
library (e.g., this.z.modInverse(this.curve.p)
). The output of this function call is multiplied by another value before being reduced with the barrettReduce()
function.
The root cause of this issue is that the jsbn
modInverse
function sometimes returns negative results. These results are correct in that they are equivalent mod the relevant modulus, but can be problematic for functions that expect modular operations to always return positive results (in the range [0, p)
, where p
is the modulus).
In particular, while the Barrett reduction algorithm in general can handle negative inputs, the implementation in node-jose
explicitly does not. Therefore, while the negative value that is returned by modInverse()
is mathematically correct, it leads to an error in barrettReduce()
causing an infinite loop which may result in a Denial of Service condition.
For a given prime modulus, we estimate that roughly one in every 2^20
inputs produce a negative modInverse()
. This estimate was validated with exhaustive testing on small primes (<30 bits) and randomized testing with regard to the P-256 prime.
This issue is only present in situations where the "fallback" cryptographic implementation is being used, i.e., situations where neither WebCrypto nor the Node crypto
module is available.
The following elliptic curve algorithms are impacted by this issue (all in lib/deps/ecc/index.js
):
exports.generateKeyPair
)ECPrivateKey.prototype.toPublicKey
)ECPrivateKey.prototype.sign
)ECPublicKey.prototype.verify
)ECPrivateKey.prototype.computeSecret
)In the first three cases, the points being evaluated are generated randomly, so an attack could only arise due to a bad value being randomly selected (as noted above, with probability roughly 2^{-20}
). In the latter two cases, the points being evaluated are provided from outside the library, and thus potentially by attackers.
Has the problem been patched? What versions should users upgrade to?
Since this issue is only present in the "fallback" crypto implementation, it can be avoided by ensuring that either WebCrypto or the Node crypto
module is available in the JS environment where node-jose
is being run.
If you have any questions or comments about this advisory:
Improper Verification of Cryptographic Signature in node-forge
RSA PKCS#1 v1.5 signature verification code is not properly checking DigestInfo
for a proper ASN.1 structure. This can lead to successful verification with signatures that contain invalid structures but a valid digest.
The issue has been addressed in node-forge
1.3.0
.
If you have any questions or comments about this advisory:
Prototype Pollution in node-forge debug API.
The forge.debug
API had a potential prototype pollution issue if called with untrusted input. The API was only used for internal debug purposes in a safe way and never documented or advertised. It is suspected that uses of this API, if any exist, would likely not have used untrusted inputs in a vulnerable way.
The forge.debug
API and related functions were removed in 1.0.0.
Don't use the forge.debug
API directly or indirectly with untrusted input.
If you have any questions or comments about this advisory:
Open Redirect in node-forge
parseUrl functionality in node-forge mishandles certain uses of backslash such as https:/\/\/\
and interprets the URI as a relative path.
Improper Verification of Cryptographic Signature in node-forge
RSA PKCS#1 v1.5 signature verification code is lenient in checking the digest algorithm structure. This can allow a crafted structure that steals padding bytes and uses unchecked portion of the PKCS#1 encoded message to forge a signature when a low public exponent is being used.
The issue has been addressed in node-forge
1.3.0
.
For more information, please see "Bleichenbacher's RSA signature forgery based on implementation error" by Hal Finney.
If you have any questions or comments about this advisory:
URL parsing in node-forge could lead to undesired behavior.
The regex used for the forge.util.parseUrl
API would not properly parse certain inputs resulting in a parsed data structure that could lead to undesired behavior.
forge.util.parseUrl
and other very old related URL APIs were removed in 1.0.0 in favor of letting applications use the more modern WHATWG URL Standard API.
Ensure code does not directly or indirectly call forge.util.parseUrl
with untrusted input.
If you have any questions or comments about this advisory:
Improper Verification of Cryptographic Signature in node-forge
RSA PKCS#1 v1.5 signature verification code does not check for tailing garbage bytes after decoding a DigestInfo
ASN.1 structure. This can allow padding bytes to be removed and garbage data added to forge a signature when a low public exponent is being used.
The issue has been addressed in node-forge
1.3.0
.
For more information, please see "Bleichenbacher's RSA signature forgery based on implementation error" by Hal Finney.
If you have any questions or comments about this advisory: