From b9b38ae5d2be9c55730e5b115d6b588b89503c7a Mon Sep 17 00:00:00 2001 From: henmohr Date: Thu, 10 Sep 2026 00:13:31 +0800 Subject: [PATCH 1/2] feat: Nextcloud 35 compatibility improvements - Update PHP platform requirement from 8.1 to 8.3 in composer.json - Refactor InjectionMiddleware to use IAddress::matches() public API instead of direct Range::contains() calls - Update copyright year The app already declared max-version=35 in info.xml. These changes improve code quality and ensure proper use of public OCP interfaces. Signed-off-by: henmohr --- appinfo/info.xml | 2 +- composer.json | 2 +- lib/Middleware/InjectionMiddleware.php | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) 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..a67174f 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' => (string)$ip]); throw new OCSException('', Http::STATUS_UNAUTHORIZED); } } From 34fa356f389115aac23e72dd7e6634357bd050c7 Mon Sep 17 00:00:00 2001 From: henmohr Date: Thu, 10 Sep 2026 00:22:26 +0800 Subject: [PATCH 2/2] fix: CS fixer and Psalm issues - Add space after fn in arrow function (CS fixer requirement) - Use $remoteAddress directly in log instead of casting Address to string - Remove unused UndefinedClass baseline entry for OC_Helper Signed-off-by: henmohr --- lib/Middleware/InjectionMiddleware.php | 4 ++-- tests/psalm-baseline.xml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index a67174f..c850b2a 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -56,13 +56,13 @@ private function restrictIp(): void { return; } $rangeObjects = array_map( - fn(string $range) => new \OC\Security\Ip\Range($range), + fn (string $range) => new \OC\Security\Ip\Range($range), $ranges ); if ($ip->matches(...$rangeObjects)) { return; } - $this->logger->error('Unauthorized access to API', ['IP' => (string)$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 @@ -