You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
crypto: scrypt with params over maxmem leaves an OpenSSL error queued; the next createPrivateKey fails #66668
The asynchronous crypto.scrypt(..., cb) behaves the same way: its parameter check throws synchronously and leaves the
same error queued.
How often does it reproduce? Is there a required condition?
Always, when the scrypt parameters exceed maxmem (the memory check). A non-power-of-two N (also ERR_CRYPTO_INVALID_SCRYPT_PARAMS) does not leave an error behind.
What is the expected behavior? Why is that the expected behavior?
The failed scrypt parameter check should not affect unrelated later crypto calls: createPrivateKey of a valid key
should succeed. The OpenSSL error queue should be cleared when the parameter check fails, as Node does elsewhere.
What do you see instead?
The first createPrivateKey (or other key-parsing call) after the failed scrypt throws the scrypt's EVP_R_MEMORY_LIMIT_EXCEEDED. Through jsonwebtoken this surfaced as «secretOrPrivateKey must be an asymmetric key when
using RS256» (jsonwebtoken retries a key that fails createPrivateKey as an HMAC secret), which made it look like a
random signing failure under load.
Additional information
The likely source is the fix for #53291 (PR #53300): when ncrypto::checkScryptParams fails, src/crypto/crypto_scrypt.cc
(line ~92 on main) reads the OpenSSL error with ERR_peek_last_error() to build the message, but never pops or
clears it, so it stays queued for the next OpenSSL consumer on the thread. A ClearErrorOnReturn (or ERR_get_error() / ERR_clear_error() after formatting) on that path should fix it. Same class as #45485
(X509Certificate.checkPrivateKey() with a non-matching key makes the next createPrivateKey() fail), #21281 and #42793.
Activity