? ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
22 Feb 2020

The code was already present to not display super user in the list of available usergroups. But the logic was not correct. With this PR the list of available user groups in the com_users options correctly excludes super users

Pull Request for Issue #27629

(Just noticed this should have been done against staging. I am offline for the next few hours but this can still be tested in j4 and then I can backport it when confirmed it works)

avatar brianteeman brianteeman - open - 22 Feb 2020
avatar brianteeman brianteeman - change - 22 Feb 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 Feb 2020
Category Libraries
avatar joomdonation
joomdonation - comment - 22 Feb 2020

If I'm not mistaken, your change will always remove user groups which has core.admin permission, even if the current user is Super Admin, so it changes existing behavior and it's wrong.

I think we can:

protected function getOptions()
	{
		// Hash for caching
		$hash = spl_object_id($this->element);

		if (!isset(static::$options[$hash]))
		{
			static::$options[$hash] = parent::getOptions();

			$groups             = UserGroupsHelper::getInstance()->getAll();
			$checkSuperUser     = (int) $this->getAttribute('checksuperusergroup', 0);
			
			if ($this->getAttribute('exclude_permissions'))
			{
				$excludePermissions = explode(',', $this->getAttribute('exclude_permissions'));
			}
			else
			{
				$excludePermissions = array();
			}



			$isSuperUser        = Factory::getUser()->authorise('core.admin');
			$options            = [];



			foreach ($groups as $group)
			{
				// Don't show the user groups which is set in exclude_permissions property
				foreach ($excludePermissions as $permission)
				{
					if (Access::checkGroup($group->id, $permission))
					{
						continue 2;
					}
				}

				// Don't show super user groups to non super users.
				if ($checkSuperUser && !$isSuperUser && Access::checkGroup($group->id, 'core.admin'))
				{
					continue;
				}

				$options[] = (object) array(
					'text'  => str_repeat('- ', $group->level) . $group->title,
					'value' => $group->id,
					'level' => $group->level
				);
			}

			static::$options[$hash] = array_merge(static::$options[$hash], $options);
		}

		return static::$options[$hash];
	}

That code will allows us to prevent user groups with any permissions we want from being shown in the field.

avatar brianteeman
brianteeman - comment - 22 Feb 2020

If I'm not mistaken, your change will always remove user groups which has core.admin permission, even if the current user is Super Admin, so it changes existing behavior and it's wrong.

You are misunderstanding the point of the PR. The aim of the PR is prevent the guest and registered user groups being set in com_users as superuser. That is exactly what it does. There is never a use case where you should be able to set either of those as a superuser. The code already exists to prevent it from happening during registration but there was a missed case of the guest user. Instead of leaving the situation where a site admin can set the user group to be a value that the registration forbids and then giving an error this PR correctly prevents that scenario from ever happening.

avatar joomdonation
joomdonation - comment - 22 Feb 2020

I understand the point of the PR and the code you changed. However, you changed code of a form field type here and with that change, if someone uses that field type (for example, in third party extensions), they won't be able to list Super Users group (for Super Admin) and don't show that user group (for none Super Admin users) on the same form. That's a backward in-compatible change. That's the reason I suggested adding exclude_permissions attribute

(I hope it's clear now as I don't know how to explain it better, maybe someone with better English can explain more clearly)

avatar brianteeman
brianteeman - comment - 22 Feb 2020

That's a backward in-compatible change.

This is Joomla 4 :)

avatar brianteeman
brianteeman - comment - 22 Feb 2020

Also if you look in the xml you will see that the attribute had already been added - its just the logic for the attribute that was not working as intended

avatar joomdonation
joomdonation - comment - 22 Feb 2020

Even with Joomla 4, it limits the usage of the form field, make it less flexible than how it was designed.

avatar brianteeman
brianteeman - comment - 22 Feb 2020

This is NOT breaking anything. The field is working exactly as it was before. It is ONLY if you have the additional paramater in the xml that any usergroup is removed. That paramater existed before - it just didnt work

avatar joomdonation
joomdonation - comment - 22 Feb 2020

As I said, it changes the behavior of the field, make it less flexible. I don't know how to explain it more clear, so I will leave it to someone else.

avatar joomdonation
joomdonation - comment - 22 Feb 2020

Maybe an example would help. Assume that in Mass Mail Users feature of Joomla, a user from Manage User group is not allowed to send Mass Mail to Super User group. At the moment, it could be done by change this field https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_users/forms/mail.xml#L26 , add checksuperusergroup="1" to it

However, with your change, even users from Super Users user group won't be able to see and send mail to Super Users (or Administrator) group.

Hope it's more clear now.

avatar Bakual
Bakual - comment - 22 Feb 2020

@joomdonation Brian is right here. The $checkSuperUser is only true if the checksuperusergroup attribute is set in the XML. That attribute is only used for the new_usertype and guest_usergroup fields.
It was added as part a security hardening in 3.6.5. See https://developer.joomla.org/security-centre/667-20161204-misc-security-hardening.html

So it indeed looks like an oversight that you can set it to a superuser group if you're a super user yourself. It never makes sense to be able to set that.

@brianteeman You can also remove the line 84 $isSuperUser = Factory::getUser()->authorise('core.admin'); since $isSuperUser isn't used anymore after you removed the only use of it.

avatar joomdonation
joomdonation - comment - 22 Feb 2020

@Bakual I don't know the reason/history of checksuperusergroup attribute, so I commented base on reading the code. And from reading the code, the original behavior is that:

  • If checksuperusergroup is not set, the field will show all user groups.
  • If checksuperusergroup is set and the current user does not have core.admin permission, hide all user groups which are having core.admin permission
  • If checksuperusergroup is set and the current user has core.admin permission, all user groups still be displayed

So this PR, as I mentioned, change behavior of a form field type which could be used by third party extensions (the sample user case which mentioned in Mass Mail example could be valid)

And if you are correct that checksuperusergroup is added as part of 3.6.5 security release, why we can still set Guest User Group to Super Users now? So the link you sent https://developer.joomla.org/security-centre/667-20161204-misc-security-hardening.html could be additional code added elsewhere.

avatar Bakual
Bakual - comment - 22 Feb 2020

If checksuperusergroup is set and the current user has core.admin permission, all user groups still be displayed

Yep, and this is basically a bug as it doesn't make sense. It also doesn't make sense to behave like this for 3rd parties. So the changed behavior is fine.

And if you are correct that checksuperusergroup is added as part of 3.6.5 security release, why we can still set Guest User Group to Super Users now?

Which only proves my point that it is a bug ?
I think what happend back then was that the one who wrote the security fix mixed the part for the "Guest User Group" and "New User Registration Group" with the part "restricting the ability for a lesser privileged user to make user group assignment changes to users in a Super User group". First one shouldn't be allowed for Super Users as well, and the second part should be allowed for Super Users, hence the conditional. But instead of adding that conditional only for the second part of the fix, it got added to both of them.

avatar alikon
alikon - comment - 24 Feb 2020

I have tested this item successfully on 7d6f427


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28011.

avatar alikon alikon - test_item - 24 Feb 2020 - Tested successfully
avatar alikon
alikon - comment - 24 Feb 2020

guess should be backported on 3.x

avatar jwaisner
jwaisner - comment - 25 Feb 2020

I have tested this item successfully on 7d6f427


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28011.

avatar jwaisner jwaisner - test_item - 25 Feb 2020 - Tested successfully
avatar jwaisner jwaisner - change - 25 Feb 2020
Status Pending Ready to Commit
avatar jwaisner
jwaisner - comment - 25 Feb 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28011.

avatar joomdonation
joomdonation - comment - 25 Feb 2020

@brianteeman Please remove this line of code https://github.com/brianteeman/joomla-cms/blob/superuser/libraries/src/Form/Field/UsergrouplistField.php#L81 as it's not needed with your change anymore.

avatar Quy
Quy - comment - 10 Mar 2020

@brianteeman Please delete obsolete variable on line 81.

avatar brianteeman brianteeman - change - 10 Mar 2020
Labels Added: ? ? ?
avatar richard67
richard67 - comment - 15 Mar 2020

@brianteeman Could you solve conflicts? Or shall I do it for you to save you some time?

avatar richard67
richard67 - comment - 15 Mar 2020

Conflicts are coming from recently merged #28021 .

avatar brianteeman
brianteeman - comment - 15 Mar 2020

not at my laptop right now.not ging to try doing it on my phone. so feel free to give it a go

avatar richard67 richard67 - change - 15 Mar 2020
Labels Removed: ?
avatar richard67
richard67 - comment - 15 Mar 2020

@brianteeman Done. Was possible in the GitHub UI, but you are right, that should not be done on a mobile phone.

avatar brianteeman
brianteeman - comment - 15 Mar 2020

thx

avatar richard67
richard67 - comment - 15 Mar 2020

@alikon @jwaisner Could you test again?

avatar richard67
richard67 - comment - 15 Mar 2020

I have tested this item successfully on e2e0434


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28011.

avatar richard67 richard67 - test_item - 15 Mar 2020 - Tested successfully
avatar chmst
chmst - comment - 15 Mar 2020

I have tested this item successfully on e2e0434


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28011.

avatar chmst chmst - test_item - 15 Mar 2020 - Tested successfully
avatar richard67
richard67 - comment - 15 Mar 2020

So we have 2 good tests again and can keep the RTC ;-)

avatar rdeutz rdeutz - change - 4 Apr 2020
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2020-04-04 12:44:11
Closed_By rdeutz
avatar rdeutz rdeutz - close - 4 Apr 2020
avatar rdeutz rdeutz - merge - 4 Apr 2020
avatar brianteeman
brianteeman - comment - 4 Apr 2020

Thanks

Add a Comment

Login with GitHub to post a comment