Tidy: don't skip strong-password validation for whitespace-only / "0" input#233
Open
dknauss wants to merge 1 commit into
Open
Tidy: don't skip strong-password validation for whitespace-only / "0" input#233dknauss wants to merge 1 commit into
dknauss wants to merge 1 commit into
Conversation
validate_strong_password() detects an empty/unchanged password field with `trim( $_POST['pass1'] )`. An all-whitespace value (e.g. " ") trims to '' and is treated as "no password set", so the function returns early and skips the length, zxcvbn, and Have I Been Pwned checks — while WordPress still saves the whitespace password. A user under an enforced strong-password policy can defeat it this way. (The same early-return also fires for a password of "0", which is falsy after trim.) Only a genuinely empty field means "no change", so gate on the string being non-empty instead of on trim().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Passwords::validate_strong_password()decides whether a password change is present usingtrim( $_POST['pass1'] ). That treats an all-whitespace value (" ") — and, becausetrim()'s result is used as a boolean, a value of"0"— as "no password set", so the function returns early and skips its length / zxcvbn / Have I Been Pwned checks for those inputs.This is harmless in practice — WordPress core already rejects a whitespace-only password on every path, so one can't actually be set or used through the UI:
edit_user()trimspass1and only savesif ( ! empty( $pass1 ) )→" "becomes a no-op change."The password cannot be a space or all spaces."beforereset_password()is called.wp_authenticate()trims the entry andwp_authenticate_username_password()rejects an empty password.So this isn't a policy bypass — it's a small correctness issue: the blank-field test should key off an empty field, not
trim(), so the plugin's own checks don't silently skip for whitespace-only /"0"input.Fix
Only a genuinely empty field means "no change". Legitimate password changes are unaffected.