- π¬π§United Kingdom mcdruid π¬π§πͺπΊ
This issue was discussed by the Drupal Security Team.
It was agreed that it can be handled in public as a security hardening; we can use this issue.
The problem is that there is significantly less entropy in the inputs to
user_pass_rehash()
if the user has an empty password field in the database.Users may have empty passwords if - for example - a site uses a Single Sign On integration to offload authentication.
Improvements could be made to the implementation to reduce the likelihood that an attacker could brute force e.g. a password reset URL if the user has no password stored in Drupal.
It may also be advisable for sites / projects that do not use Drupal's passwords for authentication to avoid leaving the password field empty in the database, but that can be looked at in a (public) follow-up. It wouldn't help much to set the password field to the same value for all users.
- Merge request !5823Issue #3277003: Harden user_pass_rehash() against attack β (Closed) created by mcdruid
- Status changed to Needs review
about 1 year ago 12:39pm 15 December 2023 - πΊπΈUnited States greggles Denver, Colorado, USA
mcdruid β credited greggles β .
- πΊπΈUnited States moshe weitzman Boston, MA
mcdruid β credited moshe weitzman β .
- π¬π§United Kingdom mcdruid π¬π§πͺπΊ
Adding credit from the private DST discussion - which is where the idea for this MR came from.
- π¬π§United Kingdom mcdruid π¬π§πͺπΊ
- Status changed to Needs work
about 1 year ago 3:12pm 15 December 2023 - πΊπΈUnited States smustgrave
Not sure if tests can be a follow up with security improvements but think this should get some test coverage.
- π¬π§United Kingdom mcdruid π¬π§πͺπΊ
More tests are always good, but I'm not sure what additional tests we'd add here.
There are already tests which cover functionality where
user_pass_rehash()
is used to construct URLs - e.g.:- \Drupal\Tests\user\Functional\UserPasswordResetTest
- \Drupal\Tests\user\Functional\UserCancelTest
The idea of the improvement being suggested is to reduce the chances of a successful brute force attack, and that's not necessarily an easy thing to test.
Open to suggestions of what testing we could add, but I think we may have to be satisfied that existing tests prove this change is not introducing a regression.
- π¬π§United Kingdom catch
What about a test that checks that two users with an empty password and the same last login timestamp get different hashes? That wouldn't prove that there's not some other vector for hash collision, but it would prove that we got rid of this one.
- Status changed to Needs review
about 1 year ago 12:12am 19 December 2023 - π¬π§United Kingdom mcdruid π¬π§πͺπΊ
Right, good plan.
Added a basic KernelTest that illustrates a possible hash collision when there are empty passwords in the db.
I've manually verified that the test fails without the change to
user_pass_hash()
.Sorry, I've not kept up with how we're doing (the equivalent of) test-only patches these days, but I'll try to find out in the next couple of days.
- π¬π§United Kingdom catch
@mcdruid in the gitlab pipeline UI, there's a 'test only' job which reverts any non-test changes, then runs only the tests changed in the MR, it doesn't work for everything but it works for most.
- π¬π§United Kingdom mcdruid π¬π§πͺπΊ
Ah, interesting thanks.
The test only job seems to have passed, but also shows the expected failure:
https://git.drupalcode.org/project/drupal/-/jobs/506479
Testing Drupal\Tests\user\Kernel\UserPassRehashTest F 1 / 1 (100%) Time: 00:00.568, Memory: 4.00 MB There was 1 failure: 1) Drupal\Tests\user\Kernel\UserPassRehashTest::testUniqueHashNoPasswordValue Failed asserting that 'VxdDGWYOnSlfWVeVDwheEkF38Avnca_EsLcz3fdfMm4' is not equal to 'VxdDGWYOnSlfWVeVDwheEkF38Avnca_EsLcz3fdfMm4'. /builds/project/drupal/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121 /builds/project/drupal/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55 /builds/project/drupal/core/modules/user/tests/src/Kernel/UserPassRehashTest.php:50 /builds/project/drupal/vendor/phpunit/phpunit/src/Framework/TestResult.php:728 FAILURES! Tests: 1, Assertions: 6, Failures: 1.
Do we need anything else in the MR?
I'd think this will need a CR; apart from anything else any reset URLs that have been sent out but not yet used will become invalid (although they only last for 24hrs by default IIRC).
- πΈπ°Slovakia poker10
The MR is not rebased, but I thought we fixed that in π Test-only job shouldn't require constant rebases to detect which files were changed. Active , so there is no need to rebase when running test-only pipeline.
- πΈπ°Slovakia poker10
I have created a simple draft CR here: https://www.drupal.org/node/3409738 β
And also created two follow-ups to fix the behavior of the test-only job from above here:
π Test-only job reverts unrelated changes in non-rebased MRs Active
π Test-only job does not detect failures correctly Needs review - Status changed to RTBC
about 1 year ago 5:13pm 21 December 2023 - πΊπΈUnited States smustgrave
Reviewing MR 5823
Test coverage is there per #22
CR reads fine to me.
Think this is good.
- Status changed to Needs work
12 months ago 5:08pm 1 January 2024 - π¬π§United Kingdom catch
One small comment on the test, otherwise this looks good to me.
- Status changed to Needs review
12 months ago 7:30pm 1 January 2024 - π¬π§United Kingdom mcdruid π¬π§πͺπΊ
Thanks; thought I'd tried that but I must have been doing something wrong..
- Status changed to RTBC
12 months ago 7:52pm 1 January 2024 - π§πͺBelgium BramDriesen Belgium π§πͺ
Out of interest, but can someone explain (if allowed) how separating the values (which are unique) with a
:
makes it so that the hashes are unique? I guess that was explained in private DST, but we can't see that discussion π - πͺπΈSpain fjgarlin
See the test.
When concatenating unique id and email like these two pairs:
- 123 / example@test.com
- 12 / 3example@test.comYouβd get the same string without the β:β.
- π§πͺBelgium BramDriesen Belgium π§πͺ
Ah, I see, makes perfect sense. Kind of overlooked that in the test case I guess. Thanks @fjgarlin!
- π¬π§United Kingdom catch
Committed/pushed to 11.x and cherry-picked to 10.2.x, thanks!
Automatically closed - issue fixed for 2 weeks with no activity.