Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<summary>Admin group manager</summary>
<description><![CDATA[
Manage routines associates to admin groups]]></description>
<version>0.1.1</version>
<version>0.2.0</version>
<licence>agpl</licence>
<author mail="vitor@librecode.coop" >Vitor Mattos</author>
<namespace>AdminGroupManager</namespace>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bamarni/composer-bin-plugin": true
},
"platform": {
"php": "8.1"
"php": "8.3"
}
},
"scripts": {
Expand Down
22 changes: 11 additions & 11 deletions lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
1 change: 0 additions & 1 deletion tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<code><![CDATA[Users]]></code>
<code><![CDATA[Users]]></code>
<code><![CDATA[Users]]></code>
<code><![CDATA[\OC_Helper]]></code>
</UndefinedClass>
</file>
</files>
Loading