diff --git a/appinfo/info.xml b/appinfo/info.xml index e2fd374..4a0ea83 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ Admin group manager - 0.1.1 + 0.2.0 agpl Vitor Mattos AdminGroupManager diff --git a/composer.json b/composer.json index e73de18..8f7c9df 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "bamarni/composer-bin-plugin": true }, "platform": { - "php": "8.1" + "php": "8.3" } }, "scripts": { diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index 280a201..c850b2a 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -2,14 +2,12 @@ declare(strict_types=1); /** - * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors + * SPDX-FileCopyrightText: 2020-2025 LibreCode coop and contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\AdminGroupManager\Middleware; -use OC\Security\Ip\Address; -use OC\Security\Ip\Range; use OCA\AdminGroupManager\Controller\AEnvironmentAwareOCSController; use OCA\AdminGroupManager\Controller\Attribute\RestrictIp; use OCP\AppFramework\Controller; @@ -50,19 +48,21 @@ public function beforeController(Controller $controller, string $methodName) { } private function restrictIp(): void { - $ip = new Address( - $this->request->getRemoteAddress() - ); + $remoteAddress = $this->request->getRemoteAddress(); + // Use public OCP interfaces for IP validation (available since NC30) + $ip = new \OC\Security\Ip\Address($remoteAddress); $ranges = $this->config->getSystemValue('admin_group_manager_allowed_range'); if (!is_array($ranges) || empty($ranges)) { return; } - foreach ($ranges as $range) { - if ((new Range($range))->contains($ip)) { - return; - } + $rangeObjects = array_map( + fn (string $range) => new \OC\Security\Ip\Range($range), + $ranges + ); + if ($ip->matches(...$rangeObjects)) { + return; } - $this->logger->error('Unauthorized access to API', ['IP' => $ip]); + $this->logger->error('Unauthorized access to API', ['IP' => $remoteAddress]); throw new OCSException('', Http::STATUS_UNAUTHORIZED); } } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index b972764..51c048f 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -13,7 +13,6 @@ -