Opened 10 years ago
Closed 10 years ago
#38739 closed defect (bug) (fixed)
REST API: slashing and validation: users
| Reported by: | jnylen0 | Owned by: | rmccue |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.7 |
| Component: | REST API | Version: | 4.7 |
| Severity: | major | Keywords: | has-patch has-unit-tests commit |
| Cc: | Focuses: |
Description
There are multiple issues with validation of user parameters in the API:
- Improper/missing validation of usernames as compared to wp-admin. This allows creating a user with e.g.
username=¯\_(ツ)_/¯(in this case, the username is sanitized to__internally). - The API skips the
illegal_user_loginsfilter that sites can use to customize a list of prohibited usernames. - Missing checks for password: cannot be empty, cannot contain
\. - Backslashes are eaten (see also #38609, #38704, #38726).
This patch fixes the above issues and adds tests. The validation checks are adapted from edit_user here.
In order to test updating user passwords, we need to mock out wp_clear_auth_cookie and wp_set_auth_cookie. Otherwise, this error occurs due to the setcookie calls in those functions:
Cannot modify header information - headers already sent by (output started at tests/phpunit/includes/bootstrap.php:61)
HTML tags and other nastiness are currently removed from usernames correctly because wp_insert_user calls sanitize_user( $username, true ).
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
For the multi-error, this can instead use a single WP_Error instance and use
$error->add( $code, $message, $data ). This will give the main error, and add a newadditional_errorskey to the error response with the others.Otherwise, looks good to me.