-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Account Protection: Add password validation #41401
Account Protection: Add password validation #41401
Conversation
…add/protect/account-protection-settings
…add/protect/account-protection-settings
…add/protect/account-protection-settings
Error thrown when creating a new account via
|
Right, good catch - its annoying but its looking like each form is going to need its own variation in checks. As it stands it seems like there might not be a way to perform user specific check on the reset form because the user is logged out, we also shouldn't run current/recent password checks when adding a new user since its not relevant there and the user reference wont have an ID because its not been generated yet. I'll pull this back out and see if I can get a unique path for each sorted out. UPDATE: Tweaked the primary validation method to also skip the recent password check when were in create user context. I've already applied some conditional skips for the other forms and some comments for clarification. |
…ction-password-validation
/** | ||
* Return all validation errors. | ||
* | ||
* @param \WP_User|\stdClass $user The user object or a copy. | ||
* @param string $password The password to check. | ||
* | ||
* @return array An array of validation errors (if any). | ||
*/ | ||
public function return_all_validation_errors( $user, string $password ): array { | ||
$errors = array(); | ||
|
||
if ( $this->contains_backslash( $password ) ) { | ||
$errors[] = __( 'Doesn\'t contain a backslash (\\) character', 'jetpack-account-protection' ); | ||
} | ||
|
||
if ( $this->is_invalid_length( $password ) ) { | ||
$errors[] = __( 'Between 6 and 150 characters', 'jetpack-account-protection' ); | ||
} | ||
|
||
if ( $this->matches_user_data( $user, $password ) ) { | ||
$errors[] = __( 'Doesn\'t match user data', 'jetpack-account-protection' ); | ||
} | ||
|
||
if ( $this->is_recent_password( $user->ID, $password ) ) { | ||
$errors[] = __( 'Not used recently', 'jetpack-account-protection' ); | ||
} | ||
|
||
if ( $this->is_weak_password( $password ) ) { | ||
$errors[] = __( 'Not a leaked password.', 'jetpack-account-protection' ); | ||
} | ||
|
||
return $errors; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Return all validation errors. | |
* | |
* @param \WP_User|\stdClass $user The user object or a copy. | |
* @param string $password The password to check. | |
* | |
* @return array An array of validation errors (if any). | |
*/ | |
public function return_all_validation_errors( $user, string $password ): array { | |
$errors = array(); | |
if ( $this->contains_backslash( $password ) ) { | |
$errors[] = __( 'Doesn\'t contain a backslash (\\) character', 'jetpack-account-protection' ); | |
} | |
if ( $this->is_invalid_length( $password ) ) { | |
$errors[] = __( 'Between 6 and 150 characters', 'jetpack-account-protection' ); | |
} | |
if ( $this->matches_user_data( $user, $password ) ) { | |
$errors[] = __( 'Doesn\'t match user data', 'jetpack-account-protection' ); | |
} | |
if ( $this->is_recent_password( $user->ID, $password ) ) { | |
$errors[] = __( 'Not used recently', 'jetpack-account-protection' ); | |
} | |
if ( $this->is_weak_password( $password ) ) { | |
$errors[] = __( 'Not a leaked password.', 'jetpack-account-protection' ); | |
} | |
return $errors; | |
} |
This return_all_validation_errors
method doesn't appear to be used anywhere. Can it be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added in preparation for the follow up where it will be used.
…ction-password-validation
My thought is that we shouldn't need to verify the core nonces inside hooks like I'm assuming these were added potentially in response to PHPCS issues when working with |
FYI |
Nit - unnecessary phpcs disable of unused param: Diff |
I have drafted a branch here which makes a few adjustments to:
I would approve this PR with nonces removed, though I would like to circle back on items in the above at some point. Feel free to take a look and cherry-pick anything worthwhile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for making these changes. Manually re-tested the add, edit, and password reset flows.
Description
Adds
Validation_Service
methods for the following processes and accompanying tests.Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
cd projects/packages/account-protection && composer phpunit
and verify that all tests passScreenshots
Reset form:
![Screen Shot on 2025-01-31 at 10-02-13](https://private-user-images.githubusercontent.com/43220201/408674258-aae2a404-8f7a-4c81-ab42-b33f41ac8085.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTI1NjgsIm5iZiI6MTczOTU1MjI2OCwicGF0aCI6Ii80MzIyMDIwMS80MDg2NzQyNTgtYWFlMmE0MDQtOGY3YS00YzgxLWFiNDItYjMzZjQxYWM4MDg1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDE2NTc0OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE0NWNlMTljZmQwOGNiM2VkZmYwODk1ZDUyNDllZDdhYWQyZDI5MTVlNmViM2JlZDI0MWEyMjk4NzZlM2ViMTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.BlR52NTIjOit5tgBbUZlCQS9PxeC6a_RN7fwUX_CzP4)
Profile form (add-new/update):
![Screen Shot 2025-01-31 at 10 01 30](https://private-user-images.githubusercontent.com/43220201/408674046-d7893327-362e-4662-9184-bb028c10cda7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTI1NjgsIm5iZiI6MTczOTU1MjI2OCwicGF0aCI6Ii80MzIyMDIwMS80MDg2NzQwNDYtZDc4OTMzMjctMzYyZS00NjYyLTkxODQtYmIwMjhjMTBjZGE3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDE2NTc0OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ1NGM1NzVjZGQ2NDUwOGI4MGY2MTY5ZDY0NDhmYTRjMDA5ODRiZmU0Y2ZkMDNjZjlkNjMxNjFhMmU2ZDg5NmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.bN96IgIMEDOy3ZWrnR-0zNJEkijV7uXPCOHck5bx-eI)