Skip to content
Crypto Disclosed report Advanced CVE-2022-35255

Weak randomness in WebCrypto keygen

The key generation code for WebCrypto secret keys called the entropy source without checking whether it succeeded, and the returned bytes were not guaranteed to be cryptographically strong. An attacker could potentially predict generated keys, breaking confidentiality and integrity.

bnoordhuis Follow

Originally disclosed on HackerOne

High 8.4 View original
  • Triaged in under an hour
  • Fixed in 24 days
  • Disclosed after 54 days

https://github.com/nodejs/node/pull/35093 introduced a call to EntropySource() in SecretKeyGenTraits::DoKeyGen() in src/crypto/crypto_keygen.cc. There are two problems with this:

  1. It does not check the return value, it assumes EntropySource() always succeeds, but it can (and sometimes will) fail.

  2. The random data returned byEntropySource() may not be cryptographically strong and therefore not suitable as keying material.

An example is a freshly booted system or a system without /dev/random or getrandom(2).

Impact

EntropySource() calls out to openssl's RAND_poll() and RAND_bytes() in a best-effort attempt to obtain random data.

OpenSSL has a built-in CSPRNG but that can fail to initialize, in which case it's possible either:

  1. No random data gets written to the output buffer, i.e., the output is unmodified, or

  2. Weak random data is written. It's theoretically possible for the output to be fully predictable because the CSPRNG starts from a predictable state.

The output buffer is allocated in SecretKeyGenTraits::DoKeyGen() using OPENSSL_malloc() (alias for CRYPTO_malloc()), which in turn calls malloc().

malloc() does not zero the buffer but its contents may be predicted or manipulated by an external attacker, e.g. by manipulating an arraybuffer, then forcing the GC to reclaim it.

Users can override the CSPRNG (and do) so there are probably more failure modes. A buggy CSPRNG could write out only zeroes, for example, comparable to (2).

I have a (trivial!) patch available. H1 gives this a really high CVSS score but I suppose that's appropriate when the worst case failure mode is a complete breakdown of confidentiality and integrity.

The original report as published on HackerOne, by bnoordhuis. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code ignored the return value of the entropy source and treated best-effort random data as suitable keying material, with the output buffer left uninitialised on failure.

Impact

On systems where the CSPRNG fails to initialise, generated keys could in theory be fully predictable, breaking confidentiality and integrity.

What the attacker needed

System with failing or weak CSPRNG; attacker can influence heap contents

The fix

The author had a trivial patch available, though the text does not describe its contents.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When software creates a secret key, it needs unpredictable random numbers. This code asked the operating system for randomness but never checked whether that request worked, and the randomness could be weak on some systems. If the numbers are predictable, someone could guess the key and read or alter protected data.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by bnoordhuis

View all

1 more disclosed report, best first.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.