Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293617

Crypt::randomBytes()/drupal_random_bytes() doesn't actually return cryptographically secure random bytes

$
0
0

Problem/Motivation

Drupal prefers openssl_random_pseudo_bytes() if available in Crypt::randomBytes() in 8.0.x or drupal_random_bytes() in 7.x and 6.x.

PHP used the wrong method in the openssl library now fixed in 5.6.12, 5.5.28, 5.4.44 see: https://bugs.php.net/bug.php?id=70014 but it is NOT classified as a security hole so backports are to older (ie distro) versions are less likely. Just because PHP didn't declare this a security hole doesn't mean it is not. But also read on for other scenarios where this class creates a security hole.

The returned pseudo-random bytes were NOT necessarily cryptographically secure.

Proposed resolution

Add random_compat v2.0.2 to core + use it for Crypt::randomBytes()
Adding v2 should be ok here because in drupal 7.x this includes a fallback.
(so not a concern like in #2763787: Upgrade random_compat to latest version which reverted the upgrade to v2.0.2 in drupal 8.2.x and 8.3.x)

Remaining tasks

review

User interface changes

n/a

API changes

n/a

Data model changes

n/a

RC phase evaluation

Reference: https://www.drupal.org/core/d8-allowed-changes
Issue categoryBug because the Crypt class doesn't do what the docblock says, and what the docblock says reflects how the class is actually used in Drupal.
Issue priority Critical because:
  • The class docblock claims to return cryptographically secure random data, which is not the case on:
    • PHP installations with versions lower than 5.6.12, 5.5.28, 5.4.44 with the openssl extension enabled
    • PHP installations on Windows, which are vulnerable to a situation where an attacker writes static data to C:\dev\urandom, which would make subsequent reads (i.e. from /dev/urandom in Crypt::randomBytes()) return nonrandom data
    • PHP installations which don't have ext_openssl and can't read from /dev/urandom, which makes Drupal fall back to a userspace "random" byte generator, which is not a good thing to do, especially if the class claims to produce cryptographically secure random bytes
  • The class claims to use the best possible source of cryptographically secure random bytes, which is not the case in all the situations listed above in addition to installations that have ext_sodium installed or PHP7 installations, which have random_bytes().
  • The PHP bug wasn't flagged as a security hole, so no CVE was issued, which means that the fix is less likely to be backported to older distro versions, which makes it more important that we work around it as we do with other PHP bugs/undesirable behaviors (drupal_[php built-in function] in D7 and whatever they were converted to in D8)
DisruptionNone. Everything should work exactly the same, except with actual cryptographically secure pseudorandom bytes

Viewing all articles
Browse latest Browse all 293617

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>