-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Bug: unexpected behavior when calling wp_set_password() via REST API #36
Comments
I haven't dug into this yet, but I just wanted to say thanks for providing an informative bug report with along with workarounds that you've tried, research that you've done into this, and steps to reproduce. I appreciate that. 🙏 |
Looking at that function, there's an early return for API requests that would prevent setting the password: wp-password-bcrypt/wp-password-bcrypt.php Lines 108 to 113 in 9ad6c27
I'm assuming empty($passwords = WP_Application_Passwords::get_user_application_passwords($user_id)) So if there are no existing application passwords for the user, that function will just return without doing anything 🤔 Would you be able to debug and see which condition is causing the short-circuit? You could copy the plugin source and modify it. |
Just had a chance to dig in. First of all, the reason this method currently does nothing is indeed latter rule; there are no application passwords defined, so Just to be extra clear: I'm not trying to set an application password, but rather change the user's "normal" password via REST API. (I hope that was obvious already, but one can never be too sure.) Looking at #31 I have a rough idea why the method works the way it does, but it does also seem to prevent what I'm trying to do here, and differs in this regard from how the core version works. Edit: Strike that, that wouldn't help with the problem mentioned in issue #22. But it doesn't seem quite right to assume that API requests are always about applications passwords either :) |
wp_set_password should never update application passwords. That's a straight violation of the implicit API of that function which leads to this bug. Regarding application passwords in wp_check_password, you have to decide what to update based on what type of hash is checked. If the stored hash (second Argument) matches the user's password hash (needs to be fetched using passed ID) the password is updated. If any of the application passwords (need to be fetched) match the passed hash the application passwords are updated. If none of the above is true nothing is updated. |
The are several plugins that call wp_check_password on strings that are in fact not the user's Login password. Those will all reset the real password. |
To add to my comments, I don't think bcrypt should be used for application passwords at all. Application passwords are randomly generated and have roughly 140 bits of entropy. A "simple" hash function is more than enough. |
I have the same issue! At least an entry should be added to log in such case |
Terms
Description
What's wrong?
Trying to change user password within a custom REST API route by calling
wp_set_password()
doesn't seem to do anything at the moment.What have you tried?
Among other things tried disabling wp-password-bcrypt, after which things started working again.
What insights have you gained?
If I disable "application_password_is_api_request" check by filter (
add_filter('application_password_is_api_request', '__return_false')
) before callingwp_set_password()
in my REST route, changing password seems to work as expected.Possible solutions
Not familiar enough with the implementation to make any real suggestions, except that if this can't be reliably fixed, then perhaps it should be documented?
Temporary workarounds
Calling
add_filter('application_password_is_api_request', '__return_false')
beforewp_set_password()
in REST route.Steps To Reproduce
wp_set_password('some-password-string', 1)
:Expected Behavior
New password should work.
Actual Behavior
New password doesn't work, but old password still works. If I uncomment the filter in the action hook above, things now work as expected.
Relevant Log Output
No response
Versions
1.1.0
The text was updated successfully, but these errors were encountered: