Skip to content

Commit eb2ae2c

Browse files
author
Konrad Michalik
authored
Merge pull request #12 from xima-media/validate-usergroup-access
fix: validate backend user and userGroups access in NewsRepository
2 parents 5c6c765 + a826582 commit eb2ae2c

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Classes/Domain/Repository/NewsRepository.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,26 @@ public function __construct(
4141

4242
public function findAllByCurrentUser(int|null $limit = null): array|null
4343
{
44-
$userGroups = array_keys($GLOBALS['BE_USER']->userGroups);
44+
// Validate backend user exists and is authenticated
45+
if (!isset($GLOBALS['BE_USER']) || !is_object($GLOBALS['BE_USER'])) {
46+
return [];
47+
}
48+
49+
$backendUser = $GLOBALS['BE_USER'];
50+
51+
// Validate user groups property exists and is an array
52+
if (!property_exists($backendUser, 'userGroups') || !is_array($backendUser->userGroups)) {
53+
return [];
54+
}
55+
56+
$userGroups = array_keys($backendUser->userGroups);
4557
$cacheIdentifier = $this->cache->generateCacheIdentifier($userGroups);
4658
if ($this->cache->has($cacheIdentifier)) {
4759
return $this->cache->get($cacheIdentifier);
4860
}
4961

50-
if ($GLOBALS['BE_USER']->isAdmin()) {
62+
// Check if user has admin privileges
63+
if (method_exists($backendUser, 'isAdmin') && $backendUser->isAdmin()) {
5164
$result = $this->findAll()->toArray();
5265
$this->cache->set($cacheIdentifier, $result);
5366
return $result;

0 commit comments

Comments
 (0)