Skip to content

Commit d9dfa09

Browse files
authored
Merge pull request #10 from LibreSign/chore/log-unauthorized-accessxz
chore: log unauthorized access
2 parents 7c96958 + 21246c4 commit d9dfa09

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ Available features:
1616
occ app:enable admin_group_manager
1717
occ app:enable groupquota
1818
```
19+
- Allowed IP
20+
21+
By security, this API only receive requests from a specific IP.
22+
- Run a tail with grep to watch by the word "Unauthorized access".
23+
```bash
24+
tail -f data/nextcloud.log|grep "Unauthorized access"
25+
```
26+
- Do a request to API endpoint and go back to terminal to check the logs and get the IP.
27+
- With the IP, run the follow command:
28+
```bash
29+
occ config:system:set admin_group_manager_allowed_ip --value <theIdentifiedIp>
30+
```
1931

2032
## Performance improving
2133
Systemd service

lib/Middleware/InjectionMiddleware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
use OCP\AppFramework\OCS\OCSException;
1717
use OCP\IConfig;
1818
use OCP\IRequest;
19+
use Psr\Log\LoggerInterface;
1920

2021
class InjectionMiddleware extends Middleware {
2122

2223
public function __construct(
2324
private IRequest $request,
2425
private IConfig $config,
26+
private LoggerInterface $logger,
2527
) {
2628
$this->request = $request;
2729
}
@@ -49,6 +51,7 @@ private function restrictIp(): void {
4951
$ip = $this->request->getRemoteAddress();
5052
$allowed = $this->config->getSystemValue('admin_group_manager_allowed_ip');
5153
if ($allowed !== $ip) {
54+
$this->logger->error('Unauthorized access to API', ['IP' => $ip]);
5255
throw new OCSException('', Http::STATUS_UNAUTHORIZED);
5356
}
5457
}

0 commit comments

Comments
 (0)