Skip to content

Commit 54ac539

Browse files
committed
Fix GHSA-59cf-4f4p-752w
KKT handlers (and similar) had permission to manage anonymous questions and community service. The code sometime only checked for the STUDENT_COUNCIL role and did not check if the user was an elected member of the student council. STUDENT_COUNCIL role is given to many people (including KKT handlers, committee members). This commit should fix these issues, a warning is also placed in `Role.php` to decrease the likelihood of making this mistake again.
1 parent c6740fb commit 54ac539

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

app/Exports/UsersExport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function sheets(): array
3131

3232
if(user()->can('viewSemesterEvaluation', User::class)) {
3333
$sheets[] = new SemesterEvaluationExport($this->includedUsers);
34-
if(user()->hasRole(Role::STUDENT_COUNCIL)) {
34+
if(user()->hasRole([Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS])) {
3535
$sheets[] = new StudentsCouncilFeedback($this->includedUsers);
3636
}
3737
}

app/Models/Role.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class Role extends Model
4545
public const DIRECTOR = 'director';
4646
public const STAFF = 'staff';
4747
public const LOCALE_ADMIN = 'locale-admin';
48+
/**
49+
* Danger: STUDENT_COUNCIL role is given to many users who ARE NOT actually part of the elected part of the student council (like KKT handlers, committee members).
50+
* It is generally a mistake if you simply check for the existence of this role. You usually need to check for the RoleObject as well.
51+
* You most likely would like to use STUDENT_COUNCIL => STUDENT_COUNCIL_LEADERS or STUDENT_COUNCIL => STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS
52+
* instead of STUDENT_COUNCIL in policies.
53+
*/
4854
public const STUDENT_COUNCIL = 'student-council';
4955
public const STUDENT_COUNCIL_SECRETARY = 'student-council-secretary';
5056
public const BOARD_OF_TRUSTEES_MEMBER = 'board-of-trustees-member';
@@ -81,6 +87,15 @@ class Role extends Model
8187
self::COMMUNICATION_LEADER,
8288
self::SPORT_LEADER,
8389
];
90+
public const STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS = [
91+
self::PRESIDENT,
92+
self::SCIENCE_VICE_PRESIDENT,
93+
self::ECONOMIC_VICE_PRESIDENT,
94+
self::CULTURAL_LEADER,
95+
self::COMMUNITY_LEADER,
96+
self::COMMUNICATION_LEADER,
97+
self::SPORT_LEADER,
98+
];
8499
public const COMMITTEE_REFERENTS = [
85100
self::CULTURAL_REFERENT,
86101
self::COMMUNITY_REFERENT,

app/Policies/AnswerSheetPolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class AnswerSheetPolicy
1818
public function administer(User $user): bool
1919
{
2020
return $user->isAdmin()
21-
|| $user->hasRole(Role::STUDENT_COUNCIL);
21+
|| $user->hasRole([Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS]);
2222
}
2323
}

app/Policies/CommunityServicePolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function create(User $user)
4040
*/
4141
public function approveAny(User $user)
4242
{
43-
return $user->hasRole([Role::STUDENT_COUNCIL]);
43+
return $user->hasRole([Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS]);
4444
}
4545

4646
/**

app/Policies/ReservableItemPolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function requestReservationForType(User $user, ReservableItemType $type):
4242
return $user->hasRole([Role::COLLEGIST, Role::TENANT]);
4343
case ReservableItemType::ROOM:
4444
return config('custom.room_reservation_open')
45-
&& $user->hasRole([Role::WORKSHOP_LEADER, Role::WORKSHOP_ADMINISTRATOR, Role::STUDENT_COUNCIL]);
45+
&& $user->hasRole([Role::WORKSHOP_LEADER, Role::WORKSHOP_ADMINISTRATOR, Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS]);
4646
default:
4747
throw new \Exception("unknown ReservableItemType");
4848
}

app/Policies/UserPolicy.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function viewAll(User $user): bool
3535
Role::SECRETARY,
3636
Role::DIRECTOR,
3737
Role::STUDENT_COUNCIL_SECRETARY,
38-
Role::STUDENT_COUNCIL => array_merge(Role::STUDENT_COUNCIL_LEADERS, Role::COMMITTEE_LEADERS),
38+
Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS,
3939
]);
4040
}
4141

@@ -68,7 +68,7 @@ public function viewAny(User $user): bool
6868
Role::WORKSHOP_ADMINISTRATOR,
6969
Role::WORKSHOP_LEADER,
7070
Role::STUDENT_COUNCIL_SECRETARY,
71-
Role::STUDENT_COUNCIL => array_merge(Role::STUDENT_COUNCIL_LEADERS, Role::COMMITTEE_LEADERS),
71+
Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS,
7272
]);
7373
}
7474

@@ -102,7 +102,7 @@ public function view(User $user, User $target): bool
102102
return $user->hasRole([
103103
Role::SECRETARY,
104104
Role::DIRECTOR,
105-
Role::STUDENT_COUNCIL => array_merge(Role::STUDENT_COUNCIL_LEADERS, Role::COMMITTEE_LEADERS),
105+
Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS,
106106
Role::STUDENT_COUNCIL_SECRETARY,
107107
]);
108108
})) || $target->workshops
@@ -128,7 +128,7 @@ public function updateAnyPermission(User $user, User $target, Role $role = null)
128128
if (!isset($role)) {
129129
return $user->hasRole([
130130
Role::SECRETARY,
131-
Role::STUDENT_COUNCIL => array_merge(Role::STUDENT_COUNCIL_LEADERS, Role::COMMITTEE_LEADERS),
131+
Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS,
132132
Role::STUDENT_COUNCIL_SECRETARY,
133133
Role::WORKSHOP_ADMINISTRATOR,
134134
Role::WORKSHOP_LEADER
@@ -182,7 +182,7 @@ public function updateAnyPermission(User $user, User $target, Role $role = null)
182182

183183
if ($role->name == Role::STUDENT_COUNCIL) {
184184
return $user->hasRole([
185-
Role::STUDENT_COUNCIL => array_merge(Role::STUDENT_COUNCIL_LEADERS, Role::COMMITTEE_LEADERS),
185+
Role::STUDENT_COUNCIL => Role::STUDENT_COUNCIL_LEADERS_AND_COMMITTEE_LEADERS,
186186
Role::STUDENT_COUNCIL_SECRETARY
187187
]);
188188
}

0 commit comments

Comments
 (0)