[php-src] Issue #14007: password_hash does not allow \0 in the $password
| From: | savaskoc | Date: | Fri, 19 Apr 2024 14:59:13 +0000 |
| Subject: | [php-src] Issue #14007: password_hash does not allow \0 in the $password | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246791@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14007
Author: savaskoc
### Description
[CVE-2024-3096](https://github.com/php/php-src/security/advisories/GHSA-h746-cjrr-wfmr) has been
fixed with [this
commit](https://github.com/php/php-src/commit/0ba5229a3f7572846e91c8f5382e87785f543826). The issue
identified within the CVE only happens when
$password starts with \0.
However with the fix, password_hash function throws an exception if
$password CONTAINS \0.
The following code:
```php
<?php
try {
$hash = password_hash("\0PaSsWorD", PASSWORD_BCRYPT);
var_dump(password_verify('', $hash));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
$hash = password_hash("P\0aSsWorD", PASSWORD_BCRYPT);
var_dump(password_verify('', $hash));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
```
Resulted in this output:
```
Bcrypt password must not contain null character
Bcrypt password must not contain null character
```
But I expected this output instead:
```
Bcrypt password must not start with null character
bool(false)
```
### PHP Version
PHP 8.3.6
### Operating System
_No response_