2

In phpstorm php 7.4 I am using the following function below, it seems to function as it should but I get the following EA error in console on line 551

[EA] The IV generated can be false, please add necessary checks.

[EA] Use 2nd parameter for determining if the algorithm used was cryptographically strong.

  function _token()
    {
        $random_token = base64_encode(openssl_random_pseudo_bytes(32));
        return $_SESSION['token'] = $random_token;
    }

This is line 551

$random_token = base64_encode(openssl_random_pseudo_bytes(32));

This is highlighted red

openssl_random_pseudo_bytes

1 Answer 1

2

If you read the manual for openssl_random_pseudo_bytes() you will see there is a second parameter for determining if the value generated is "cryptographically strong":

If passed into the function, this will hold a bool value that determines if the algorithm used was "cryptographically strong", e.g., safe for usage with GPG, passwords, etc. true if it did, otherwise false

You need to pass this parameter and then check to see if is true (and thus okay to use that value):

function _token()
{
    $random_token = base64_encode(openssl_random_pseudo_bytes(32, $strong));
    if (!$strong) {
        // deal with the token not being "cryptographically strong"
        throw new RuntimeException('Token is not cryptographically strong');
    }
    return $_SESSION['token'] = $random_token;
}

For me, PHPStorm still shows that error, but that is what it is trying to tell you to do.

1
  • 1
    I added the 2nd parameter but it still throws the IV generated can be false, please add necessary checks error, wasn't sure if it is a false positive
    – Da' Don
    Jan 2, 2021 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.