- First commit to issue fork.
- 🇺🇸United States DanChadwick
Along the lines of #10, here's a patch for 9.5.2 for those users who need to move past this. My site generates all accounts programmatically, so all with null passwords. I have confirmed the patch with manual testing. This patch won't apply to D10 because of the function signature change to use the SensitiveParmeter attribute. I simply cast to string because the code body handles empty strings cleanly and quickly and the code is simpler and more concise.
- Status changed to Needs review
over 1 year ago 2:59pm 8 March 2023 - 🇫🇷France andypost
A bit of clean-up for 6, hope this will address feedback on #10
- 🇫🇷France andypost
probably it needs follow-up for the interdiff because changing interface
- 🇫🇷France andypost
Even if user created by drush it still can have null password, so we should change interface
- 🇫🇷France andypost
Filed follow-up 🐛 UserInterface::getPassword() can return NULL Fixed
- 🇧🇷Brazil paulocs Belo Horizonte
Code looks good and it fixes the errors.
Only one thing: we use snake_case for variables declared in the functions.
$userWithoutPassword = $this->createMock('Drupal\user\Entity\User');
I'm attaching a patch and the inter-diff of this change only. So I think I can move to RTBC after tests pass.
- Status changed to RTBC
over 1 year ago 11:09pm 12 March 2023 - Status changed to Needs work
over 1 year ago 12:02am 13 March 2023 - 🇳🇿New Zealand quietone
I don't see that the two points in #10 have been addressed. Setting back to NW.
-
+++ b/core/modules/user/tests/src/Unit/UserAuthTest.php
@@ -278,4 +282,30 @@ public function testAddCheckToUrlForTrustedRedirectResponse(): void {
+ * Tests the authenticate method when the user has no stored password.
Let's be clear that this is testing when the user password is NULL.
+++ b/core/modules/user/tests/src/Unit/UserAuthTest.php @@ -278,4 +282,30 @@ public function testAddCheckToUrlForTrustedRedirectResponse(): void { + * In https://www.drupal.org/project/drupal/issues/3305807 it was discovered + * that attempting to login as a user that has no stored password will + * generate PHP notices due to calling substr on a NULL value.
I think testing when the password is NULL is a valid test and we don't need this extra paragraph. And especially it should not be referring to a d.o issue. I am usually all for comments but I don't think this is adding useful information. What would be useful is to add how the password can be NULL as comments in the fix.
-
+++ b/core/modules/user/tests/src/Unit/UserAuthTest.php
- 🇫🇷France andypost
Needs re-roll as comited 🐛 UserInterface::getPassword() can return NULL Fixed
- Status changed to Needs review
over 1 year ago 5:11pm 13 March 2023 - Status changed to Needs work
over 1 year ago 6:42pm 13 March 2023 - 🇺🇸United States smustgrave
Think I jumped the gun too early before, that's my mistake. Moving to NW per #20
- Status changed to Needs review
over 1 year ago 7:48pm 13 March 2023 - 🇫🇷France andypost
yes, this extra paragraph is useless, there's git for history
- Status changed to RTBC
over 1 year ago 9:02pm 13 March 2023 - 🇳🇿New Zealand quietone
In #20 I suggested adding a comment explaining how the password can be NULL for an existing user. I still that is worth doing.
- Status changed to Needs work
over 1 year ago 5:34am 21 March 2023 - Status changed to Needs review
over 1 year ago 6:51am 21 March 2023 - Status changed to Needs work
over 1 year ago 6:56am 21 March 2023 - 🇳🇿New Zealand quietone
Also, needs work for #20/#26.. The changes in the patch in #3 didn't add the comment in the fix.
- 🇫🇷France andypost
Basically any user created without password will have it as NULL, no idea where to document it
- Status changed to Needs review
over 1 year ago 5:58am 18 April 2023 - last update
over 1 year ago 29,284 pass - 🇮🇳India _pratik_ Banglore
patch #30 was not applying, Attached rerolled patch.
Unable to find comments line from #20, #26
thanks - Status changed to Needs work
over 1 year ago 2:40pm 18 April 2023 - Status changed to Needs review
over 1 year ago 3:52pm 2 May 2023 - last update
over 1 year ago 29,372 pass - 🇷🇺Russia ilya.no
@larowlan I agree with your suggestion and here is the patch for your comment #10. I've found, that PasswordHashingTest is now LegacyPasswordHashingTest due to recent changes in password processing logic. So, I've made a change to the new service and to the old one, because as long as this code is presented it needs to work properly although it's deprecated. Please, correct me, if I'm wrong.
- 🇫🇷France andypost
Thanks @ilya.no I missed this point but I checked and there's only string, empty string and
NULL
values possibleMoreover in context of 🌱 [Meta] Implement strict typing in existing code Active it can use follow-up to add deprecation if not a
string|null
is passed+++ b/core/lib/Drupal/Core/Password/PhpPassword.php @@ -45,6 +45,10 @@ public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $ + // Newly created account may have empty password. + if (!is_string($hash) || (is_string($hash) && mb_strlen($hash) === 0)) { +++ b/core/lib/Drupal/Core/Password/PhpassHashedPasswordBase.php @@ -242,6 +242,9 @@ public function hash(#[\SensitiveParameter] $password) { public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $hash) { + if (!is_string($hash) || (is_string($hash) && mb_strlen($hash) === 0)) { + return FALSE;
I bet we can simplify it with
if ($hash === NULL || $hash === '')
because it must be a
string
ornull
here - 🇫🇷France andypost
Re #10.1
Can we elaborate on why we didn't go that way?
I wanted to prevent calling service ("carbonless-optimization") as both places already checking previous argument for NULL to prevent useless function call.
I still sure we need to use the same pattern for saved hash as there's many reasons it could appear a NULL from database
- last update
over 1 year ago 29,375 pass - 🇷🇺Russia sorlov
Added changes mentioned in #36 🐛 Password is null if user has never logged in which causes PHP 8 warning Fixed
- Status changed to Needs work
over 1 year ago 8:22am 4 May 2023 - Status changed to Needs review
over 1 year ago 9:48am 4 May 2023 - last update
over 1 year ago 29,375 pass - last update
over 1 year ago 29,375 pass - last update
over 1 year ago 29,375 pass - last update
over 1 year ago 29,375 pass - Status changed to Needs work
over 1 year ago 6:56pm 6 May 2023 - 🇺🇸United States smustgrave
Seems part of #10 has been addressed. Think the part that @larowlan was looking for was a positive assertion somewhere.
- Status changed to Needs review
over 1 year ago 8:37am 26 July 2023 - 🇷🇺Russia ilya.no
@smustgrave I'm not sure, that I've got your point. In comment #10 it's stated, that we need to add test case, which looks like
assertFalse($password->check($a_password, NULL))
In my patch I've added following code
$this->assertFalse($this->passwordHasher->check($this->password, NULL));
which looks the same, as suggestion from comment #10.
Could you correct me, if I'm wrong? Or maybe I didn't understand you. Thanks!
- Status changed to Needs work
over 1 year ago 1:20pm 26 July 2023 - 🇺🇸United States smustgrave
Yes but it was request for a positive assertion. AssertTrue somewhere
- Status changed to Needs review
about 1 year ago 9:14am 15 August 2023 - 🇷🇺Russia sorlov
Logic of latest patch is pretty different from what was addressed in #10
So I don't see how we could have positive assertion for latest patch logic
- last update
about 1 year ago 28,526 pass - 🇺🇸United States smustgrave
11.x is the current dev branch.
Also #49 seems to be removing some of the original patch from 40.
- last update
about 1 year ago 29,960 pass - Status changed to Needs work
about 1 year ago 2:57pm 20 August 2023 The Needs Review Queue Bot → tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.
- last update
about 1 year ago 30,057 pass - last update
about 1 year ago 29,470 pass - last update
about 1 year ago 30,057 pass - Status changed to Needs review
about 1 year ago 5:12am 21 August 2023 - 🇷🇺Russia sorlov
Patch from #40 🐛 Password is null if user has never logged in which causes PHP 8 warning Fixed can be applied to 11.x as well
- Status changed to RTBC
about 1 year ago 5:19pm 28 August 2023 - 🇺🇸United States smustgrave
Going to see what the committers think if we need to do some trickery for a positive assertion. Going to mark it so it doesn't get lost in the shuffle of things.
- last update
about 1 year ago 29,470 pass - last update
about 1 year ago 29,471 pass - last update
about 1 year ago 29,471 pass - last update
about 1 year ago 29,471 pass - last update
about 1 year ago 29,472 pass - last update
about 1 year ago 29,472 pass - last update
about 1 year ago 29,472 pass - last update
about 1 year ago 29,474 pass 4:51 3:16 Running- Status changed to Needs work
about 1 year ago 1:52pm 14 September 2023 - 🇬🇧United Kingdom catch
Which patch is RTBC? 40 or 49? If it's 40, that should be re-uploaded so it's the newest patch on the issue. I think just a negative assertion is fine, we're testing there's no PHP warning.
- Status changed to Needs review
about 1 year ago 5:46am 27 September 2023 - 🇷🇺Russia ilya.no
@catch RTBC is for patch #40.
Patch from comment #49 is for 10.0.x branch without any explanation and I think, that we can ignore it. - Status changed to RTBC
about 1 year ago 5:56pm 27 September 2023 - 🇺🇸United States smustgrave
@ilya.no hid patch 49.
So #40 should be at the top.
- last update
about 1 year ago 29,643 pass - Status changed to Needs work
about 1 year ago 2:59pm 29 September 2023 - 🇺🇸United States xjm
Thanks for working on this! A few small things:
-
index f16eeb200c..e6863b6c3e 100644 --- a/core/lib/Drupal/Core/Password/PhpPassword.php index 052c2be81e..2cbdb3d617 100644 --- a/core/lib/Drupal/Core/Password/PhpassHashedPasswordBase.php @@ -242,6 +242,9 @@ public function hash(#[\SensitiveParameter] $password) { + if ($hash === NULL || $hash === '') { + return FALSE; + }
I think the same inline comment needs to be added above this hunk as well, unless we want to abstract it into a protected
checkEmptyPassword()
method somewhere. -
+++ b/core/lib/Drupal/Core/Password/PhpPassword.php @@ -45,6 +45,10 @@ public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $ + // Newly created account may have empty password.
Very minor nitpick: This is not a complete sentence, and complete sentences are required by our documentation guidelines → :
All documentation and comments should form proper sentences, use proper grammar and punctuation, and generally follow the same style guidelines as Drupal.org content: http://drupal.org/style-guide/content
So, I think this should be:
Newly created accounts may have empty passwords.
-
+++ b/core/modules/phpass/tests/src/Tests/LegacyPasswordHashingTest.php @@ -122,4 +122,13 @@ public function testPasswordRehashing() { + * Tests password check in case provided hash is NULL.
Tests password validation when the hash is NULL.
-
+++ b/core/modules/phpass/tests/src/Tests/LegacyPasswordHashingTest.php @@ -122,4 +122,13 @@ public function testPasswordRehashing() { + $this->assertFalse($this->passwordHasher->check($this->password, NULL));
Shouldn't we also cover empty string in the same method?
-
+++ b/core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php @@ -124,4 +124,13 @@ public function providerLongPasswords() { + * Tests password check in case provided hash is NULL. + * + * @covers ::check + */ + public function testEmptyHash() { + $this->assertFalse($this->passwordHasher->check($this->password, NULL)); + }
Same comments as above.
-
I'm working on this issue and @xjm and @allisonherodevs are mentoring me on it.
- Status changed to Needs review
about 1 year ago 8:06pm 29 September 2023 - last update
about 1 year ago Patch Failed to Apply - last update
about 1 year ago Patch Failed to Apply - last update
about 1 year ago Custom Commands Failed - last update
about 1 year ago Custom Commands Failed - 🇺🇸United States xjm
So I just spent 15 minutes trying to figure out what the heck was going on with #60. The patches are readable in dreditor or if opened in their own tab. However, when I try to curl them -- or even "File... Save as..." I get an empty file.
I think this is a previously-unknown-to-me security "feature" of Drupal.org in that it won't serve files with the word "password" in the name, which also means DrupalCI gets an empty patch. It's imperfect though because I can open them in the browser in Dreditor or their own tab. Weird, yo.
What I had to do was create a new file locally, copy the text from the patch opened in a tab, and paste it into my editor. I thought of naming them "hash-nid-etc.patch" but thought that could be, er, misinterpreted.) These are just versions of @ChrisPerko's patch and test-only patch that Drupal.org will deign to serve, so I'm still eligible to review/commit this when appropriate. Fun times!
Anyway, adding credit for Allison as well as the correct mentoring attribution for myself.
- 🇺🇸United States xjm
Neil says there's no restriction on on filenames containing "password", and that there are two weird characters at the beginning of both files. I still get an empty file when I curl. However, the patch was created on Windows...
- 🇺🇸United States xjm
Looks like stuff is mis-indented which at least is easier to fix. 😂
FILE: ...ore/modules/phpass/tests/src/Tests/LegacyPasswordHashingTest.php ---------------------------------------------------------------------- FOUND 2 ERRORS AFFECTING 2 LINES ---------------------------------------------------------------------- 131 | ERROR | [x] Line indented incorrectly; expected 4 spaces, | | found 6 | | (Drupal.WhiteSpace.ScopeIndent.IncorrectExact) 132 | ERROR | [x] Line indented incorrectly; expected 4 spaces, | | found 6 | | (Drupal.WhiteSpace.ScopeIndent.IncorrectExact) ---------------------------------------------------------------------- PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- FILE: ...w/html/core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php ---------------------------------------------------------------------- FOUND 2 ERRORS AFFECTING 2 LINES ---------------------------------------------------------------------- 133 | ERROR | [x] Line indented incorrectly; expected 4 spaces, | | found 6 | | (Drupal.WhiteSpace.ScopeIndent.IncorrectExact) 134 | ERROR | [x] Line indented incorrectly; expected 4 spaces, | | found 6 | | (Drupal.WhiteSpace.ScopeIndent.IncorrectExact) ---------------------------------------------------------------------- PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY ----------------------------------------------------------------------
- last update
about 1 year ago Patch Failed to Apply - last update
about 1 year ago Patch Failed to Apply I fixed the spacing, I'm crossing my fingers that I created the interdiff and patches correctly.
- Status changed to Needs work
about 1 year ago 11:57pm 29 September 2023 - Status changed to Needs review
about 1 year ago 12:49am 30 September 2023 - last update
about 1 year ago Patch Failed to Apply - last update
about 1 year ago Patch Failed to Apply Hopefully this is right this time. If not, someone else can fix it, or I will get to it Monday morning. Thanks for your help @xjm
- 🇺🇸United States xjm
Those look like the correct patches, but they still have whatever weird encoding problem unfortunately.
- last update
about 1 year ago 30,361 pass - last update
about 1 year ago 30,352 pass, 1 fail - 🇺🇸United States xjm
The last submitted patch, 70: password-3305807-68-FAIL.patch, failed testing. View results →
- Status changed to RTBC
about 1 year ago 9:01pm 30 September 2023 - last update
about 1 year ago 30,354 pass, 1 fail The last submitted patch, 70: password-3305807-68-FAIL.patch, failed testing. View results →
- Status changed to Needs work
about 1 year ago 10:58pm 2 October 2023 - 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
Looking much simpler, nice work.
I think we're missing a documentation update here.
Currently
\Drupal\Core\Password\PasswordInterface::check
documents thathash
is a string, but we're now effectively saying we also support NULL. I think we should update the @parameter type-hint fromstring
tostring|null
. - Status changed to Needs review
about 1 year ago 7:19am 3 October 2023 - last update
about 1 year ago Custom Commands Failed - 🇮🇳India asad_ahmed
I have updated the @parameter type-hint from string to string|null in core/lib/Drupal/Core/Password/PasswordInterface.php as per #75. Please review. Thanks
- Status changed to Needs work
about 1 year ago 3:49pm 3 October 2023 - 🇺🇸United States smustgrave
CC failure
Saving credit for ChrisPerko for keeping this issue moving forward.
- Status changed to Needs review
about 1 year ago 4:57pm 3 October 2023 - last update
about 1 year ago 30,372 pass - 🇫🇷France andypost
Fixed CS
+++ b/core/lib/Drupal/Core/Password/PasswordInterface.php @@ -27,14 +27,14 @@ public function hash(#[\SensitiveParameter] $password); * @param string $password - * A plain-text password - * @param string $hash + * A plain-text password. + * @param string|null $hash
this change is out of scope a bit but I included it as part of context
- Status changed to RTBC
about 1 year ago 6:30pm 3 October 2023 - last update
about 1 year ago 30,378 pass - last update
about 1 year ago 30,383 pass - last update
about 1 year ago 30,385 pass - Status changed to Postponed
about 1 year ago 9:33pm 10 October 2023 - 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
+++ b/core/modules/phpass/tests/src/Tests/LegacyPasswordHashingTest.php @@ -122,4 +122,14 @@ public function testPasswordRehashing() { + /** + * Tests password validation when the hash is NULL. + * + * @covers ::check + */ + public function testEmptyHash(): void { + $this->assertFalse($this->passwordHasher->check($this->password, NULL)); + $this->assertFalse($this->passwordHasher->check($this->password, '')); + }
This test didn't fail - and that's because of 🐛 Tests in core/modules/phpass/tests/src/Tests do not run Active , so postponing on that
And that's because its in a Tests folder when it should be in a folder named Unit
There are two tests in that folder, and neither of them are running in HEAD
- Status changed to Active
about 1 year ago 12:46am 16 October 2023 - Status changed to Needs review
about 1 year ago 1:15am 16 October 2023 - last update
about 1 year ago 30,412 pass - Status changed to RTBC
about 1 year ago 2:18pm 16 October 2023 - last update
about 1 year ago 30,417 pass - last update
about 1 year ago 30,422 pass - last update
about 1 year ago 30,428 pass - last update
about 1 year ago 30,436 pass - last update
about 1 year ago 30,440 pass - last update
about 1 year ago 30,458 pass -
larowlan →
committed 6df2fd88 on 10.1.x
Issue #3305807 by andypost, ChrisPerko, mediabounds, xjm, sorlov,...
-
larowlan →
committed 6df2fd88 on 10.1.x
-
larowlan →
committed d30fedcc on 10.2.x
Issue #3305807 by andypost, ChrisPerko, mediabounds, xjm, sorlov,...
-
larowlan →
committed d30fedcc on 10.2.x
-
larowlan →
committed 00a619f3 on 11.x
Issue #3305807 by andypost, ChrisPerko, mediabounds, xjm, sorlov,...
-
larowlan →
committed 00a619f3 on 11.x
- Status changed to Fixed
about 1 year ago 12:51am 30 October 2023 - 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
Committed to 11.x and backported to 10.2.x and 10.1.x
Thanks all.
The final patch was nice and small which is always a good sign
- 🇫🇷France andypost
Thank you! it was the last bit of PHP 8.0 compatibility! Now looking for 8.3)
Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
about 2 months ago 10:27am 27 September 2024 - 🇦🇹Austria aurelianzaha
@larowlan
It would be great to backport the MR also to 10.3
if there is a way I can help on that, let me know