Problem
The access check for the /user/login path is performed as the user that's changing the settings. This is problematic because a logged-in user may not have access to the login screen but may be allowed to change basic site settings. This could also cause the login path to be set to something that the logged in user has access to but an anonymous user does not.
This can be reproduced by installing the latest version of r4032login in a clean Drupal 8 install and creating a new role that has the "Administer basic site settings" permission. Assign this role to a non-admin user and attempt to change the basic site settings with the login path set to /user/login. You'll receive a form error that you're not allowed to access /user/login.
Solution
Perform the access check for the chosen login screen path as the anonymous user.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | interdiff_8-10.txt | 383 bytes | nixou |
| #10 | 3010747-access-check-10.patch | 3.85 KB | nixou |
| #8 | interdiff_5-8.txt | 478 bytes | yarik.lutsiuk |
| #8 | 3010747-access-check-8.patch | 3.77 KB | yarik.lutsiuk |
| #5 | interdiff_3_5.txt | 2.2 KB | nixou |
Comments
Comment #2
kingdutchComment #3
kingdutchAlso changed the error message to reflect the changed expectation.
Comment #4
robertragas commentedRTBC
Comment #5
nixou commentedOk I added a test to cover that but I can't make it pass with your patch, not sure why.
I upload the patch so we can see what the testbot says.
Comment #6
nixou commentedComment #7
philyPatch #5 works for me using Drupal 8.8.3 and r4032login 8.x-1.1
Thanks
Comment #8
yarik.lutsiuk commentedHello,
patch with updated test.
Cheers
Comment #9
solideogloria commentedComment #10
nixou commentedAdded default theme for tests under D9.
Comment #12
nixou commentedCommitted to 2.x-dev, will be released in next 2.1.0.
Thanks you all !
Comment #13
kingdutchI'm happy this got merged! However, I do think a follow up is needed.
The change to the test in #8 no longer tests the issue that was reported here. The test user can now link to any paths, so even with the old code the test would now pass.
I suspect the test failure was caused by one of the other path fields' validation failing (specifically I'm not sure if
https://drupal.org/is valid for the authenticated user redirect), but I don't currently have a set-up where I can verify that hypothesis.No need to revert the code from this issue, but to avoid regressions in the future we should probably figure out how the test can work without the
link to any pagepermission.Comment #14
nixou commentedIndeed, thanks for the catch.
I looked again into this and I found that the test fail with an error "Either the path '/user/login' is invalid or you do not have access to it." which is not thrown by our code.
The point is that this test submit the form at /admin/config/system/site-information without filling the "front page" field.
When we look at core/modules/system/src/Form/SiteInformationForm.php we can see this :
So the core will fill the frontpage field with the "/user/login" path and then send an error because the user is authenticated and cannot access to this path.
This is exactly the same problem as ours but coming from the core.
As this test should not be about testing the core, we can just update it to fill the frontpage field with the path /admin/config/system/site-information.
While debugging this I also seen that there is a problem with the new validation of the path coming with this patch : an invalid path such as /abcd will not be considere as invalid.
So I'll create a follow up as you suggested to update the following things :
Comment #15
solideogloria commented#3191522: Incorrect validation and test for the "Path to user login form" field