? Pending

User tests: Successful: 0 Unsuccessful: 0

avatar weeblr
weeblr
7 Oct 2020

Pull Request for Issue #11541 .

Summary of Changes

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-be 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.

Note that 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.

Testing Instructions

From a stock Joomla install:

  1. Disable Caching in Global configuration
  2. Create a menu item GUEST with access level "guest"
  3. Create a menu item REGISTERED with access level "registered"
  4. Enable the Language Filter system plugin
  5. Log out of admin
  6. On front end, GUEST menu item should be displayed
  7. Log in to the front end **make sure to tick the Remember me check box"
  8. The REGISTERED menu item is shown, GUEST menu item is hidden
  9. Close your browser:
    • the entire browser, not just the current tab
    • browser must NOT be set to "reload all tabs opened when it was closed".
  10. Navigate to your test site URL again by pasting it in the address bar

Step 9 & 10 can be replaced by deleting some cookies, see end of this description.

Actual result BEFORE applying this Pull Request

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.

Expected result AFTER applying this Pull Request

The REGISTERED menu item is displayed and the GUEST one is not shown.

Note on testing:

Rather than closing browser at each attempt, you can simulate the same behavior with the development tools:

  1. Open the dev tools at Application->Cookies
  2. After logging-in with Remember me checked - step 8, you'll see (at least) 3 cookies:
  • joomla_remember_me_xxxx
  • joomla_user_state_xxx
  • session cookie that looks like "433f42e5e0d104622fd1b9c1c38b3945"

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.

avatar weeblr weeblr - open - 7 Oct 2020
avatar weeblr weeblr - change - 7 Oct 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Oct 2020
Category Libraries
avatar weeblr weeblr - change - 7 Oct 2020
Labels Added: ?
avatar SharkyKZ
SharkyKZ - comment - 7 Oct 2020

Can you check if #21230 fixes your issue? If it does, that would be a better fix than essentially undoing #8012.

avatar weeblr
weeblr - comment - 7 Oct 2020

@SharkyKZ Thanks for the head up. To think the problem was understood and fixed in 2018...

#8012 looked good but it actually caused the problem at hand. Injecting the user is ok, except if the user can possibly change at a later time and that memoized/injected user is not updated.

As for #21230, it indeed fixes the problem, in a more generic way and allow keeping #8012.

Note that I think my testing instructions are easier to follow than the ones in 21230.

You can close this I guess but only if 21230 is revived and actually merged.

Lastly, I can confirm the bug also exists in Joomla 4 and can be tested in the exact same way.

avatar weeblr
weeblr - comment - 7 Oct 2020

@SharkyKZ It seems my Joomla-CMS codestyle is not up to date as Drone is failing with codestyle errors.

Is there a codestyle configuration file for Intelij IDEA/PHPStorm?

avatar AndySDH
AndySDH - comment - 7 Oct 2020

Thanks for the head up. To think the problem was understood and fixed in 2018...

Yeah, crazy!

You can close this I guess but only if 21230 is revived and actually merged.

Yep, please re-open and merge #21230, guys.

avatar AndySDH
AndySDH - comment - 7 Oct 2020

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.

By the way, you have a great point here @weeblr

avatar zero-24
zero-24 - comment - 7 Oct 2020

@SharkyKZ It seems my Joomla-CMS codestyle is not up to date as Drone is failing with codestyle errors.

Is there a codestyle configuration file for Intelij IDEA/PHPStorm?

Hopefully this could help?

https://docs.joomla.org/Joomla_CodeSniffer#PhpStorm

avatar weeblr
weeblr - comment - 7 Oct 2020

@zero-24 Hmm, no this is to detect errors, not to actually format - I don't format code manually, I hope you don't ;)

I have an old one somewhere but recent update in intelij idea broke some of it and the PHPDoc formatting does not pass test ATM

avatar weeblr
weeblr - comment - 7 Oct 2020

OK, this looks like it: https://github.com/joomla/coding-standards/tree/master/Joomla/IDE

Although that's probably the one I got, it's from 2017

avatar zero-24
zero-24 - comment - 7 Oct 2020

@zero-24 Hmm, no this is to detect errors, not to actually format - I don't format code manually, I hope you don't ;)

I have an old one somewhere but recent update in intelij idea broke some of it and the PHPDoc formatting does not pass test ATM

The only doc i'm aware of is that. But I dont use phpstorm so i can not help on that.

avatar weeblr
weeblr - comment - 7 Oct 2020

Hmm too bad. The sniffer is not useful, the only really useful thing is the autoformatter. I'll try to fix my local rules then.
But that prevents me from contributing to core obviously.

avatar zero-24
zero-24 - comment - 7 Oct 2020

I'm sure here a people that use PHPStorm but i's just not me ;-)

avatar weeblr
weeblr - comment - 7 Oct 2020

OK, so actually PHPStorm/Intelij IDEA has built-in support for Joomla - which I knew - but that includes formatting as well. Nothing to do except selecting that formatting style for Joomla projects!

avatar weeblr
weeblr - comment - 8 Oct 2020

@SharkyKZ @zero-24 I am going to close this PR in favor of another one, which has a better approach to solving the problem at hand in #11541
Please have a look at the new one, we should really eventually fix this, many people are experiencing this, sometimes without knowing I'm sure.

avatar weeblr weeblr - close - 8 Oct 2020
avatar weeblr weeblr - change - 8 Oct 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-10-08 10:50:37
Closed_By weeblr

Add a Comment

Login with GitHub to post a comment