#34383Incorrect redirect with multiple user groups
Description
If the “redirectMode” is set to “groupLogin” and there are several groups with “felogin_redirectPid”, the redirect should happen to the first or last group (depending on the mode of “redirectFirst” flag. The actual redirect result is undefined because felogin fetches groups from the database without any sorting. Depending on MySQL internal index state, results can come in any order and this order can change over time. In addition felogin uses $GLOBALS[‘TSFE’->fe_user->groupData[‘uid’], which contains sorted uid values for groups. This prevents correct redirects for multiple groups too.
Felogin should ensure that it adds redirects URLs in the proper order.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Related issues 1
History 1618
-
Gerrit Code Review changed status
NewUnder Review <span data-processor="relativetime" data-value="2012-02-28T13:09:34+00:00" > 02/28/12, 13:09 </span> Patch set 1 for branch *master* has been pushed to the review server. It is available at http://review.typo3.org/9275 -
Jigal van Hemert commented <span data-processor="relativetime" data-value="2012-02-28T14:49:57+00:00" > 02/28/12, 14:49 </span>
-
Dmitry Dulepov commented <span data-processor="relativetime" data-value="2012-02-28T16:13:02+00:00" > 02/28/12, 16:13 </span>
Yes, that’s all correct but would you submit a better patch? ;)
Anyway, we solved it for the customer in our local core. The problem is that the customer wants redirects based on the first group. This does not work at all, even though it is advertised by TYPO3 as the official feature. So this feature should be either removed or fixed. I decided to fix it in a simpler way. Felogin should not have really implemented that due to reasons you described so well. But since the feature is implemented, it has to work. So here is the fix.
The proposed solution works in most cases. So if anybody has the same problem, you are welcome to use the patch.
-
Gerrit Code Review <span data-processor="relativetime" data-value="2012-04-14T22:42:36+00:00" > 04/14/12, 22:42 </span> Patch set 2 for branch *master* has been pushed to the review server. It is available at http://review.typo3.org/9275
-
Jigal van Hemert commented <span data-processor="relativetime" data-value="2012-04-15T15:29:19+00:00" > 04/15/12, 15:29 </span>
I think I found the source of “the official feature”: http://wiki.typo3.org/Felogin . This is a very outdated version and doesn’t match the manual in the system extension.
One possible solution would be:
- collect groups sorted by ordering in auth service
- collect subgroups sorted by ordering in auth service
- give groups to felogin
- felogin loops through list until one has a redirect (not in a single query) -
Alexander Opitz commented and changed status
Under ReviewNew Is Regression 0 <span data-processor="relativetime" data-value="2014-06-12T14:59:50+00:00" > 06/12/14, 14:59 </span>Patch was abandoned so reset issue status.
-
Mathias Schreiber commented <span data-processor="relativetime" data-value="2015-11-12T19:26:06+00:00" > 11/12/15, 19:26 </span>
Any pointers here?
-
Dmitry Dulepov commented <span data-processor="relativetime" data-value="2015-11-14T09:33:32+00:00" > 11/14/15, 09:33 </span>
What pointers? :)
-
Jigal van Hemert changed Duplicated by #72251 <span data-processor="relativetime" data-value="2018-01-23T22:05:49+00:00" > 01/23/18, 22:05 </span>
-
Jan Stockfisch changed Related to #84262 <span data-processor="relativetime" data-value="2018-06-19T10:38:58+00:00" > 06/19/18, 10:38 </span>
-
Markus Klein commented and changed category <span data-processor="relativetime" data-value="2020-10-21T15:03:41+00:00" > 10/21/20, 15:03 </span>
That’s a problem of the FrontendUserAuthentication class, not of felogin.
-
Dmitry Dulepov commented <span data-processor="relativetime" data-value="2020-10-21T19:18:46+00:00" > 10/21/20, 19:18 </span>
Markus Klein wrote:
> That’s a problem of the FrontendUserAuthentication class, not of felogin.Are you sure? At the time of reporting redirection was made by the felogin extension. Since redirection functionality is located in the extension, logically the fix should be in the extension as well.
-
Markus Klein commented <span data-processor="relativetime" data-value="2020-10-21T20:44:59+00:00" > 10/21/20, 20:44 </span>
Yes the redirection stems from felogin, but the groups are loaded in FrontendUserAuthentication and order should be handled there, right?
-
Dmitry Dulepov commented <span data-processor="relativetime" data-value="2020-10-22T13:40:40+00:00" > 10/22/20, 13:40 </span>
Markus Klein wrote:
> Yes the redirection stems from felogin, but the groups are loaded in FrontendUserAuthentication and order should be handled there, right?It would not be that easy and useful. Typical goal for loading groups in user auth is to set various permissions. Order does not matter for that. However ordering takes time. Since group loading happens on every request, it is more time to sort them for every request than it is now without sorting. But the result of this new sorting will be useless for 99.999% of cases (no redirection on most pages).
Groups can be nested. For example:
a
b
c -> (a)
d -> (a, c)
e -> (b)
f -> (c, f)
g -> (e, f)Sorting is not trivial here. Where “c” goes: first or the last? And so on. This all has to be in the algorithm. And if it all works on every request, these are extra calculations that are useless for most pages.
So is it worth to sort groups while loading?
-
Markus Klein commented <span data-processor="relativetime" data-value="2020-10-22T15:54:05+00:00" > 10/22/20, 15:54 </span>
Totally correct. But I remember there were some other cases, which needed sorted groups as well.
Generally: The groups are rather “static data”. So actually the order can be cached for a very long time, until some group or the user is modified.
Then group loading (incl. proper ordering) would be linear or constant time.The algorithm doing the sorting should be a dedicated class covered with a lot of tests, to have this documented “technically”.
-
Benni Mack commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2024-12-04T09:57:54+00:00" > 12/04/24, 09:57 </span>Markus Klein wrote in #note-15:
> Generally: The groups are rather “static data”. So actually the order can be cached for a very long time, until some group or the user is modified.
> Then group loading (incl. proper ordering) would be linear or constant time.
>
> The algorithm doing the sorting should be a dedicated class covered with a lot of tests, to have this documented “technically”.This is now in a dedicated class with a PSR-14 event to solve this issue about sorting in Authenitcation if needed. I don’t plan to change this (sorting in UserAuth), as this might have other side-effects – however we can modify this in the EXT:felogin extension now. Anyone up to do this?
-
Markus Klein commented <span data-processor="relativetime" data-value="2024-12-05T13:32:01+00:00" > 12/05/24, 13:32 </span>
Benni Mack wrote in #note-16:
> Markus Klein wrote in #note-15:
> > Generally: The groups are rather “static data”. So actually the order can be cached for a very long time, until some group or the user is modified.
> > Then group loading (incl. proper ordering) would be linear or constant time.
> >
> > The algorithm doing the sorting should be a dedicated class covered with a lot of tests, to have this documented “technically”.
>
> This is now in a dedicated class with a PSR-14 event to solve this issue about sorting in Authenitcation if needed. I don’t plan to change this (sorting in UserAuth), as this might have other side-effects – however we can modify this in the EXT:felogin extension now. Anyone up to do this?Why not fix the sorting stuff as a potential breaking change for v14?
-
Benni Mack commented and changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2026-10-23T08:11:40+00:00" > 10/23/26, 08:11 </span>On main (since e7204abb37d, v13), RedirectModeHandler::redirectModeGroupLogin() iterates frontend.user->userGroups, which GroupResolver builds in the order of the user’s usergroup field (subgroups before their parent group), and returns the first group with a redirect page. The unordered DB fetch and the uid-sorted groupData usage are gone, so the redirect is deterministic. The order can be changed via AfterGroupsResolvedEvent / ModifyResolvedFrontendGroupsEvent. Closing as resolved; please reopen if you can still reproduce it on v13+.
The groupData originates from the authentication service and has not defined order. It also takes into account that groups can have subgroups. This complicates the order a bit.
Subgroups also make it harder to define any order.
If the default authentication service of the core is used we could say that the order in the BE should be the order of the groups. The question is then how the subgroups should fit in this order? First the groups, then the subgroups, then the sub-subgroups, etc.? Or the first group, the first subgroup of the first group, the subgroup of the first subgroup of the first group, the second subgroup of the first group, …?
In t3lib_userAuthGroup::fetchGroups() there is no defined order (database order) for the group list, subgroups are appended to the main groups (unless the group is already present in the existing list).
The place to set an order would in the first place be the authentication service. I’m not sure if other authentication services will also import the group records to make them available for felogin to query. If this is not the case the code in felogin should be extended to provide a mechanism for the authentication service to provide such redirect information.