{"vuln_id":"GHSA-7fj2-8x79-rjf4","aliases":["CVE-2023-0567"],"description":"BCrypt hashes erroneously validate if the salt is cut short by `$`","published_at":"2023-02-15T20:37:12Z","modified_at":"2023-02-15T20:37:12Z","first_seen_at":"2026-11-22T14:05:37.636774Z","severity":"low","severity_source":"ghsa","cvss_score":null,"cvss_vector":null,"cwe":[],"vendor":null,"product":null,"kev":{"is_kev":false,"date_added":null,"due_date":null,"ransomware":false},"epss":null,"epss_percentile":null,"nvd_status":null,"enriched_at":null,"links":{"nvd":"https://github.com/advisories/GHSA-7fj2-8x79-rjf4"},"matched_alias":null,"items":[{"id":12682,"source":{"id":"gh-php-src","name":"PHP releases (GitHub php/php-src tags)"},"title":"GHSA-7fj2-8x79-rjf4 / CVE-2023-0567: BCrypt hashes erroneously validate if the salt is cut short by `$`","summary":"BCrypt hashes erroneously validate if the salt is cut short by `$` ### Summary Malformatted BCrypt hashes that include a `$` within their salt part will trigger a buffer overread and may erroneously validate any password as valid. ### Details Example: ```php ``` This issue is caused by a PHP specific modification to the crypt_blowfish implementation that is fittingly named “PHP hack”: https://github.com/php/php-src/blob/2740920a392c043b034e2f0e41d819549836712a/ext/standard/crypt_blowfish.c#L374 The “hack” will allow a salt that is cut short by `$` to be detected as valid and allowing it to proceed with the algorithm. At the end the original `setting`, which is properly NUL terminated, will be copied into the output buffer: https://github.com/php/php-src/blob/2740920a392c043b034e2f0e41d819549836712a/ext/standard/crypt_blowfish.c#L763 which is then used to initialize the returned `zend_string` by leveraging `strlen()` and thus cutting the string short after the `setting`: https://github.com/php/php-src/blob/2740920a392c043b034e2f0e41d819549836712a/ext/standard/crypt.c#L137 … thus returning the original input. Furthermore a buffer overread of the `setting` input may be triggered when copying the `setting` into the output buffer, because the `memcpy` uses fixed sizes, even if the `setting` might be too short: https://github.com/php/php-src/blob/2740920a392c043b034e2f0e41d819549836712a/ext/standard/crypt_blowfish.c#L763 ### Suggested Fix The suggested fix would be removing the “PHP Hack” and thus the differences between PHP's crypt_blowfish and Openwall’s implementation which is the basis of PHP’s implementation. The “PHP Hack” exists since the very first version of PHP’s own crypt_blowfish implementation and no clear reasoning is given for its existence in the commentary or commit history. In any case such a hash is not a valid BCrypt hash and it is not generated by `password_hash()`, which is the recommended password hashing API in PHP. While this technically might break backwards compatibility with existing users, the fact that these hashes are never generated by `password_hash()`, are not accepted by other implementations of BCrypt and introduce possible security vulnerabilities in applications, they should be rejected in every supported PHP version. ### PoC Running the following in valgrind: ```php ``` results in: ``` ==423829== Memcheck, a memory error detector ==423829== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==423829== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==423829== Command: sapi/cli/php test3.php ==423829== ==423829== Invalid read of size 2 ==423829== at 0x4840240: memcpy@GLIBC_2.2.5 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==423829== by 0x591BE9: BF_crypt (crypt_blowfish.c:763) ==4 Patched: 8.0.28, 8.1.16, 8.2.3","url":"https://github.com/php/php-src/security/advisories/GHSA-7fj2-8x79-rjf4","published_at":"2023-02-15T20:37:12Z","updated_at":"2023-02-15T20:37:12Z","fetched_at":"2026-11-22T14:05:37.431205Z","severity":"medium","cvss_score":6.2,"epss":0.00925,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":"php","product":"php-src","vuln_id":"CVE-2023-0567","vuln_ids":["CVE-2023-0567","GHSA-7FJ2-8X79-RJF4"],"tags":["repo-advisory","security","repo:php/php-src","stack"],"cluster_id":11795,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/12682","html":"https://vulnwatch.ve1ve2.com/item/12682"}}]}