Skip to content

Commit 6e8a673

Browse files
author
Daniel Neto
committed
fix: Enhance category filtering by adding user group support in category retrieval
https://github.com/WWBN/AVideo/security/advisories/GHSA-73gr-r64q-7jh4#event-597450
1 parent 5d52371 commit 6e8a673

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

objects/categories.json.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
$_REQUEST['current'] = getCurrentPage();
1616

1717
$onlyWithVideos = false;
18-
$sameUserGroupAsMe = false;
1918
if(!empty($_GET['user'])){
2019
$onlyWithVideos = true;
21-
$sameUserGroupAsMe = true;
2220
}
21+
// Always apply user-group filtering using the logged-in user's real ID.
22+
// Guests get -1 so getUserGroups returns [], leaving only unrestricted categories visible.
23+
$currentUserId = User::getId();
24+
$sameUserGroupAsMe = !empty($currentUserId) ? intval($currentUserId) : -1;
2325

2426
$categories = Category::getAllCategories(true, $onlyWithVideos, false, $sameUserGroupAsMe);
25-
$total = Category::getTotalCategories(true, $onlyWithVideos);
27+
$total = Category::getTotalCategories(true, $onlyWithVideos, false, $sameUserGroupAsMe);
2628
//$breaks = array('<br />', '<br>', '<br/>');
2729
foreach ($categories as $key => $value) {
2830
$categories[$key]['iconHtml'] = "<span class='$value[iconClass]'></span>";

objects/category.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ public function delete()
975975
return sqlDAL::writeSql($sql, "i", [$this->id]);
976976
}
977977

978-
public static function getTotalCategories($filterCanAddVideoOnly = false, $onlyWithVideos = false, $onlySuggested = false)
978+
public static function getTotalCategories($filterCanAddVideoOnly = false, $onlyWithVideos = false, $onlySuggested = false, $sameUserGroupAsMe = false)
979979
{
980980
global $global, $config;
981981

@@ -1023,6 +1023,17 @@ public static function getTotalCategories($filterCanAddVideoOnly = false, $onlyW
10231023
}
10241024
$sql .= ")";
10251025
}
1026+
if ($sameUserGroupAsMe) {
1027+
$users_groups = UserGroups::getUserGroups($sameUserGroupAsMe);
1028+
$users_groups_id = array(0);
1029+
foreach ($users_groups as $value) {
1030+
$users_groups_id[] = $value['id'];
1031+
}
1032+
$sql .= " AND ("
1033+
. "(SELECT count(*) FROM categories_has_users_groups chug WHERE c.id = chug.categories_id) = 0 OR "
1034+
. "(SELECT count(*) FROM categories_has_users_groups chug2 WHERE c.id = chug2.categories_id AND users_groups_id IN (" . implode(',', $users_groups_id) . ")) >= 1 "
1035+
. ")";
1036+
}
10261037
$sql .= BootGrid::getSqlSearchFromPost(['name']);
10271038
//echo $sql;exit;
10281039
$res = sqlDAL::readSql($sql);

0 commit comments

Comments
 (0)