From f88cffbc17a0171f118f0feebfaebde32edb80df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Rie=C3=9F?= Date: Tue, 19 May 2026 11:27:41 +0200 Subject: [PATCH] Check if the directory exists before iterating --- library/Icinga/Security/Csp/Loader/DashboardCspLoader.php | 7 +++++-- .../Icinga/Security/Csp/Loader/NavigationCspLoader.php | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Security/Csp/Loader/DashboardCspLoader.php b/library/Icinga/Security/Csp/Loader/DashboardCspLoader.php index ffabb5374..3d2461ed1 100644 --- a/library/Icinga/Security/Csp/Loader/DashboardCspLoader.php +++ b/library/Icinga/Security/Csp/Loader/DashboardCspLoader.php @@ -90,11 +90,14 @@ class DashboardCspLoader implements CspLoader if ($this->allUsers) { $result = []; - foreach (new DirectoryIterator(Config::resolvePath('dashboards')) as $dir) { + $dashboardsDir = Config::resolvePath('dashboards'); + if (! is_dir($dashboardsDir)) { + return $result; + } + foreach (new DirectoryIterator($dashboardsDir) as $dir) { if ($dir->isDot() || ! $dir->isDir()) { continue; } - $user = new User($dir->getFilename()); $result = array_merge($result, $this->loadForUser($user)); } diff --git a/library/Icinga/Security/Csp/Loader/NavigationCspLoader.php b/library/Icinga/Security/Csp/Loader/NavigationCspLoader.php index 208e270d0..a82c9e2cf 100644 --- a/library/Icinga/Security/Csp/Loader/NavigationCspLoader.php +++ b/library/Icinga/Security/Csp/Loader/NavigationCspLoader.php @@ -117,12 +117,14 @@ class NavigationCspLoader implements CspLoader if ($this->allUsers) { foreach ($navigationTypes as $type => $typeConfig) { $result = array_merge($result, $this->loadConfig($type, $typeConfig)); - - foreach (new DirectoryIterator(Config::resolvePath('preferences')) as $userDir) { + $preferencesDir = Config::resolvePath('preferences'); + if (! is_dir($preferencesDir)) { + continue; + } + foreach (new DirectoryIterator($preferencesDir) as $userDir) { if ($userDir->isDot() || ! $userDir->isDir()) { continue; } - $result = array_merge($result, $this->loadConfig($type, $typeConfig, $userDir->getFilename())); } }