Problem/Motivation
The Anonymous user, as created by the user_install() function (@see user.module's .install file),
has its status property set to 0 and is therefore blocked from authenticating.
That reasonable default should not be modified since we don't want to authenticate anonymous users.
To safeguard against this, the UnblockUser pluginUser::activate() method should ascertain that the Anonymous user does not become unblocked.
In order to achieve this, the User::isAnonymous() method also needs to enforce a stricter check on the uid property.
Proposed resolution
Modify the UnblockUser::execute()User::activate() method and implement a Logical Exception being thrown that disallows the Anonymous user from becoming unblocked.
Additionally, make User::isAnonymous() more strict and accept only uid === 0 as the condition that reveals when a user is truly anonymous.
Remaining tasks
Provide a patch.
Provide a Change Record for changes that may affect developers.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3311563
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
stefanos.petrakisComment #3
stefanos.petrakisComment #4
cilefen commentedComment #5
wim leersInteresting!
But shouldn't we then make this much more explicit by updating
\Drupal\user\Entity\User::activate()to throw an exception if one even tries to do this for the anonymous user?Comment #6
stefanos.petrakisThanks @WimLeers, that sounds even better. Something along these lines then?
Comment #7
stefanos.petrakisTest added.
Comment #9
stefanos.petrakisFixing different things, the main attempt is at hopefully improving the following points:
which I agree with.
All in all, this seems to be more important than not, I have the feeling there are a couple of important things that need attention here, maybe even breaking this down in smaller issues. Gonna bump this to major precautionary.
Comment #10
stefanos.petrakisAnd the patches of course.
Comment #11
stefanos.petrakisPHPCS fixes
Comment #14
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
At this time we would need a D10.1.x patch or MR for this issue.
Comment #15
_utsavsharma commentedPatch for 10.1.x.
Comment #18
smustgrave commentedHiding files to avoid confusion.
Ran the tests locally without the fix and got
Failed asserting that exception of type "LogicException" is thrown.And clearly it passes with the fix.
Changes look good. Not sure if a security review should happen first (question for committer)
Comment #19
longwaveAdded a question to the MR. This also needs a change record to note that we are making
User::isAnonymous()more strict, as other code may have copied the pattern in core and usedisAnonymous()to detect new users, which will now stop working.Comment #20
stefanos.petrakisComment #21
stefanos.petrakisAdded a Change Record as per #19.
Will have a look at the failing tests now.
Comment #22
stefanos.petrakisThis one is up for a review again, the change record is in place, although a draft that could use some eyes on.
The points in the MR have all been addressed.
Comment #23
smustgrave commentedSee
\Drupal\Core\Session\AccountInterfaceis being replaced now. Is this change going to be disruptive to anyone using that interface now?Comment #24
stefanos.petrakisThe reason I replaced
\Drupal\Core\Session\AccountInterfacewith\Drupal\user\UserInterfaceis because it was causing a breakage in that Unit test class due to the following change:That change is however crucial to this issue and also makes sense in that class since it is an access control handler specific to the user entity type. And that type has a
isNew()method.The Unit test class however that is testing that handler has been using so far a
\Drupal\Core\Session\AccountInterfacemock that does not have anisNew()method (which causes the breakage) but most importantly makes less sense to use for testing the access control handler for the user entity type instead of the\Drupal\user\UserInterfaceitself.So, all in all, that change is not disruptive, but the Unit test needed an adjustment IMHO.
Comment #25
smustgrave commentedThanks for the explanation. Will move it on and see what the committer thinks too.
Comment #27
catchThere's a very small chance that this could break some existing code (for example using ::isAnonymous() as a proxy for ::isNew()) but that could would already be broken as this issue shows, and it might even fix some hidden bugs for people. So I think the change record here (which looks good) is enough.
Committed c704db9 and pushed to 10.1.x. Thanks!