Problem/Motivation
The password reset feature was recently hardened in #2400197: Harden the security where hash values are compared but there is a reproducible regression where a password hash was stored on the user's session, and the form builder seeks to compare that value against the string expected in the GET parameter, even if it's not present. Thus, the hash-checker fails, attempting to compare a string value to NULL:
User warning: Expected user_string to be a string, NULL given in Drupal\Component\Utility\Crypt::hashEquals() (line 159 of core/lib/Drupal/Component/Utility/Crypt.php).
Proposed resolution
Test against the GET values before proceeding with the password-reset logic.
Remaining tasks
Does a test need to be written for this? As it sits, this is not failing any text presently in core.
User interface changes
None
API changes
None
Data model changes
None
Original report by Arla
I quickly looked into this again. I'm not sure what the determining conditions were at the time when I posted #84, but I just found a way to reproduce:
Run `drush uli`, open the returned link and click "Log in"
You're now on user/1/edit?pass-reset-token={hash}
Remove the query string (go to user/1/edit)
Receive warning: Expected user_string to be a string, NULL given in Drupal\Component\Utility\Crypt::hashEquals()
This really seems like an edge case, but to my understanding we should avoid such a warning in any case.| Comment | File | Size | Author |
|---|---|---|---|
| #10 | pass-reset-token-2624986-10.patch | 2.27 KB | arla |
| #10 | pass-reset-token-2624986-10-TEST_ONLY.patch | 1.18 KB | arla |
| #7 | interdiff-2624986-4-7.txt | 877 bytes | heykarthikwithu |
| #7 | 2624986-7.patch | 1.09 KB | heykarthikwithu |
| #4 | reset-tolken-2624986-4.patch | 1.1 KB | kristofferwiklund |
Comments
Comment #2
arla commentedComment #3
fgmNitpicking : while you're updating this, I think it would be more readable avoid repeating the 'pass_reset_' . $account->id() concatenation + function call by using a variable.
Comment #4
kristofferwiklund commentedHad similar problem.
Logging in as user 1 with the link from "drush uli". Then go to /user/1/edit gives a big error message.
The above patch solves the problem. I have also update the code with regard of the comment #3.
Comment #5
arla commentedLooks good to me. Tested manually.
The parentheses around
$token = ...are not necessary but perhaps they increase legibility so ±0.Related question: what should we expect when a user uses the password reset link but then does not immediately change the password? (which is the case at hand.)
Comment #6
bradjones1Bumping.
Comment #7
heykarthikwithurerolled in 8.2.x with minor change.
Comment #8
arla commentedTested manually again, works well.
Comment #9
alexpottIs it not possible to write an automated test for this? It would seem as though it should be possible.
Comment #10
arla commentedAdding test.
Comment #12
alexpottThe test and change look good. Nice find.
Comment #13
alexpottI've been working with the same code extensively in #2515050: A valid one-time login link may be leaked by the referer header to 3rd parties and from the work I've done there it is obvious that this change makes sense.
Comment #14
xjmSince #2400197: Harden the security where hash values are compared was committed to 8.1.x I'm assuming this also applies to that branch? (Currently we are filing issues against the minimum branch based on our allowed changes policy.) At first glance this issue seems beta- and patch-release safe to me.
Comment #17
catchCommitted/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!