Fix: Add type check to hash before passing it to has_equals to prevent warning #8232
+13
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac Ticket: Core-59824
Summary
hash_equals()
function in thewp_check_password()
function would throw an error when it received a null value as one of its arguments. This issue occurs when the hash comparison logic inadvertently passes null, causing PHP to raise a TypeError in certain edge cases, especially when a hacker attempts to pass null values in an attack. The fix ensures that both the hash and the plaintext password are properly validated as strings before callinghash_equals()
andCheckPassword()
.Changes
Added type checks before invoking the hash_equals() function to ensure both the
$hash
and the result ofmd5($password)
are valid strings.Similarly, added type checks before calling
$wp_hasher->CheckPassword()
to ensure both$password
and$hash
are strings.The function now gracefully handles invalid or unexpected input (such as null values) by returning false instead of causing a fatal error.
Why is this important?
This change ensures that the wp_check_password() function will:
Avoid throwing errors when invalid inputs (like null) are provided, especially in cases of malicious requests.
Improve the robustness of the password-checking process, making it more secure and resilient to unexpected input.
Provide greater compatibility with PHP versions that support hash_equals() and newer password hashing protocols.