Skip to content

Security issue : use hash_equals() instead of '===' to compare hashes #642

@iransmaarthbb

Description

@iransmaarthbb

Hi dev,
I would like to point out a security issue in the EncryptService class :

protected function hash_equals($a, $b) {
		if (function_exists('random_bytes')) {
			$key = random_bytes(128);
		} else {
			$key = openssl_random_pseudo_bytes(128);
		}
		return hash_hmac('sha512', $a, $key) === hash_hmac('sha512', $b, $key);
}

A simple strict equals sign === is used for hash comparison, which is vulnerable to timing attack.
The hash_equals() function should be used (http://php.net/manual/en/function.hash-equals.php) for comparing hashes.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions