Skip to content

Commit

Permalink
fix(groups): prevent misuse of group membership actions
Browse files Browse the repository at this point in the history
Only allow actions to be executed for authorised requests.
  • Loading branch information
jeabakker committed Nov 16, 2021
1 parent 621b28e commit d9fcad7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions mod/groups/actions/groups/membership/delete_invite.php
Expand Up @@ -13,8 +13,12 @@
return get_entity($group_guid);
});

if (!$user && !($group instanceof \ElggGroup)) {
return elgg_error_response();
if (!$user && !$group instanceof \ElggGroup) {
return elgg_error_response(elgg_echo('error:missing_data'));
}

if (!$user->canEdit() && !$group->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

// If join request made
Expand Down
8 changes: 6 additions & 2 deletions mod/groups/actions/groups/membership/delete_request.php
Expand Up @@ -9,8 +9,12 @@
$user = get_user($user_guid);
$group = get_entity($group_guid);

if (!$user && !($group instanceof \ElggGroup)) {
return elgg_error_response();
if (!$user && !$group instanceof \ElggGroup) {
return elgg_error_response(elgg_echo('error:missing_data'));
}

if (!$user->canEdit() && !$group->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

// If join request made
Expand Down
6 changes: 5 additions & 1 deletion mod/groups/actions/groups/membership/join.php
Expand Up @@ -18,10 +18,14 @@
return get_entity($group_guid);
});

if (!$user || !($group instanceof \ElggGroup)) {
if (!$user || !$group instanceof \ElggGroup) {
return elgg_error_response(elgg_echo('groups:cantjoin'));
}

if (!$user->canEdit() && !$group->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

// join or request
$join = false;
if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
Expand Down
6 changes: 5 additions & 1 deletion mod/groups/actions/groups/membership/leave.php
Expand Up @@ -9,10 +9,14 @@
$user = get_user($user_guid);
$group = get_entity($group_guid);

if (!$user || !($group instanceof \ElggGroup)) {
if (!$user || !$group instanceof \ElggGroup) {
return elgg_error_response(elgg_echo('groups:cantleave'));
}

if (!$user->canEdit() && !$group->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

if ($group->getOwnerGUID() === $user->guid) {
// owner can't be removed
return elgg_error_response(elgg_echo('groups:cantleave'));
Expand Down

0 comments on commit d9fcad7

Please sign in to comment.