User tests: Successful: Unsuccessful:
Pull Request for Issue #11541 .
AbstracMenu and SiteMenu classes use a memoized copy of the current user. Under some circumstances, this causes incorrect menu items to be displayed when user is logged in through the Remember-me feature (registered-access level items not shown) as the user has not yet been updated to logged-in state.
Circumstances are that Application::getMenu() is called from a plugin early on, typically from a system plugin constructor or onAfterInitialise.
getMenu() may not be called directly but for instance calling Application::getRouter() to add parse or build rules triggers the problem because the router itself grabs the menu in its contructor.
The language filter plugin does that, any SEF extension will also attach routing rules as well as many other extensions.
For 3rd party extensions, the problem will appear less frequently because it is also a requirement that the plugin in question is located before the RememberMe plugin, which is not common but will happen when user re-order plugins or when extensions want to the be the 1st plugin in the list for instance.
The problem affects Joomla 3 and Joomla 4 the same. Testing instructions are the same. I think however the issue should be solved differently in J3 and J4. This PR is for Joomla 3 and fixes the problem simply, in the most B/C manner.
With Joomla 4, the same code can be used and will also solve the problem. But I think a more robust approach should be used. It would make sense the Remember me plugin is located first in the list of system plugins. It would even make more sense that logging-in through the remember me feature is embedded in the CMS app and not in a plugin. Such logging-in should happen exactly as early as if the user was logged-in through the session or else there's a risk of similar side-effects happening in other areas, where some parts of the code see the user as a guest while later on it's seen as logged-in.
This issue was identified in 2016 (#11541)and a fix proposed at the time but unfortunately never merged. This PR uses a slightly different method which only touches the Menu class, not the remember me plugin. I believe it's better to do it that way, especially for Joomla 3, so that no changes are needed in 3rd-party extensions providing features similar to Remember-me, or otherwise.
From a stock Joomla 3 install:
Step 9 & 10 can be replaced by deleting some cookies, faster to test but requires knowledge of browser dev tools. See end of this description.
The GUEST menu item is displayed despite the user being logged in and the login module showing the user as Logged in. The REGISTERED menu item is not displayed.
The REGISTERED menu item is displayed and the GUEST one is not shown.
Rather than closing browser at each attempt, you can simulate the same behavior with the development tools:
To simulate closing the browser, you can delete the joomla_user_state cookie and the session cookie. After that, just reload the page to reproduce step 10.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
We have a b/c problem on this PR, if we remove $this->user and someone extends this class he/she expects that $this->user is populated with the current user...
@HLeithner I know. I tried to minimize B/C breaks while still fixing the problem. As this issue appears on pretty much any multilingual site that has non-public content, I think it's pretty important to fix.
How about I use a magic getter function instead of a getUser() method?
@HLeithner Redone it with a magic getter. Also removed getUser() but left setUser(). Not sure that's needed anymore actually.
My 2c this is the wrong approach. I think Remember Me plugin is in the wrong. It should perform a redirect after login. This would solve potential issues anywhere else where user instance could be cached.
I have tested this item
500 error displayed on the frontend.
I have tested this item
I test this item. It gives an error when clicked on the menu at the frontend with Guest ACL after Patch is applied.
Folks, this is for staging, NOT 4.0.
Hi
We do have more feedback about this problem from the field!
@ashvini77 @snehaM26 can you redo your testing (against Joomla 3, not Joomla 4)?
Best regards
I have tested this item
Tested the latest version successfully.
It fixes the issue as described.
Thanks @weeblr!
succesfull tested on a new multilingal hosted site
@HLeithner @infograf768 can this be merged now? (I know the second Human tester did not use Patch Tester)
sorry to late for 3.9.25
Anyway the redirect mentioned by sharky would solve the problem too right?
Hi
If the issue is created by the Remember me plugin, yes.
This fixes the problem for the menu system, meaning it'd be fixed regardless of the source.
Hi
I can see my last message is ambiguous so for clarity: the proposed redirect in Remember plugin does not fix the problem.
It only fixes it if the user object change is caused by the Remember me plugin. If the change is caused by another extension (typically extensions dealing with access such as subscription extension for instance), then the issue is still present.
tested with success with patch tester :
I do not know nom how to indicate it passed the test succesfully
documentation https://docs.joomla.org/Testing_Joomla!_patches/fr tells about a test this button, but I do not see how to use it
helpers like me who just use windows and not comand lines are lost when they want help devs to debug
@web54 You go to the PR in the issue tracker here https://issues.joomla.org/tracker/joomla-cms/30991 , then use the blue "Test this" button at the top left corner, then select the appropriate test result and then submit.
I have tested this item
tested in local with ampps
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-03-15 10:10:06 |
Closed_By | ⇒ | rdeutz | |
Labels |
Added:
?
|
Do maintainers not review the code anymore or what?
Do maintainers not review the code anymore or what?
Sure we do, what you are refering to?
I have tested this item✅ successfully on 9ea1a38
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30991.