Skip to content

Commit c7ea1ee

Browse files
committed
fix(apps): configuration to bypass checks for services
Onlyoffice server sends requests directly to the nextcloud instance. Add configuration settings `allow_ip_ranges` and `allow_path_prefix` to allow these requests to bypass tos checks. Fixes #771. Signed-off-by: Max <[email protected]>
1 parent 55c6b93 commit c7ea1ee

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ Default is enabled: `1`
2828
./occ config:app:set terms_of_service tos_for_users --value '0'
2929
```
3030

31+
## 🔌 Allow access from other services
32+
33+
Some other services such as office suites communicate directly with the Nextcloud server.
34+
For Nextcloud Office and Officeonline the `wopi_allowlist` settings of the respective apps are taken into account.
35+
36+
To allow other services to bypass the terms of service check:
37+
* Set `allow_ip_ranges` to match the ip addresses of the servers in question.
38+
* Set `allow_path_prefix` to the paths that access should be granted to.
39+
40+
Default for `allow_ip_ranges` is none: ``
41+
Default for `allow_path_prefix` is none: ``
42+
43+
```
44+
./occ config:app:set terms_of_service allow_ip_range --value '10.0.0.5,10.0.0.6'
45+
./occ config:app:set terms_of_service allow_path_prefix --value '/apps/onlyoffice/download'
46+
```
47+
3148
## 🏗️ Development setup
3249

3350
1. Clone the repository

lib/Checker.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public function currentUserHasSigned(): bool {
8888
}
8989
}
9090

91-
if ($this->isValidWOPIRequest()) {
92-
// Richdocuments and Collabora doing WOPI requests for the user
91+
if ($this->isAllowedRequest()) {
92+
// Services such as Collabora doing requests for the user
9393
return true;
9494
}
9595

@@ -126,27 +126,41 @@ public function currentUserHasSigned(): bool {
126126
return false;
127127
}
128128

129-
protected function isValidWOPIRequest(): bool {
130-
return $this->isWOPIRemoteAddress()
131-
&& $this->isAllowedAppPath()
129+
protected function isAllowedRequest(): bool {
130+
return $this->isRequestAllowedInConfig()
131+
|| $this->isValidWOPIRequest('richdocuments')
132+
|| $this->isValidWOPIRequest('officeonline');
133+
}
134+
135+
protected function isRequestAllowedInConfig(): bool {
136+
$allowedPath = $this->config->getAppValue(Application::APPNAME, 'allow_path_prefix');
137+
$allowedRanges = $this->allowedRangeForApp(Application::APPNAME, 'allow_ip_ranges');
138+
return $this->isRemoteAddressInRanges($allowedRanges)
139+
&& $this->isPathInfoStartingWith($allowedPath)
140+
&& $this->isAllowedScriptName();
141+
}
142+
143+
protected function isValidWOPIRequest(string $app): bool {
144+
$allowedPath = '/apps/' . $app . '/wopi/';
145+
$allowedRanges = $this->allowedRangeForApp($app, 'wopi_allowlist');
146+
return $this->isRemoteAddressInRanges($allowedRanges)
147+
&& $this->isPathInfoStartingWith($allowedPath)
132148
&& $this->isAllowedScriptName();
133149
}
134150

135-
protected function isAllowedAppPath(): bool {
136-
return strpos($this->request->getPathInfo(), '/apps/richdocuments/wopi/') === 0
137-
|| strpos($this->request->getPathInfo(), '/apps/officeonline/wopi/') === 0;
151+
protected function isPathInfoStartingWith(string $allowedPath): bool {
152+
// no path allowed
153+
if ($allowedPath === '') {
154+
return false;
155+
}
156+
return strpos($this->request->getPathInfo(), $allowedPath) === 0;
138157
}
139158

140159
protected function isAllowedScriptName(): bool {
141160
return substr($this->request->getScriptName(), 0 - strlen('/index.php')) === '/index.php';
142161
}
143162

144-
protected function isWOPIRemoteAddress(): bool {
145-
$allowedRanges = array_merge(
146-
$this->allowedRangeForApp('richdocuments'),
147-
$this->allowedRangeForApp('officeonline')
148-
);
149-
163+
protected function isRemoteAddressInRanges(array $allowedRanges): bool {
150164
$userIp = $this->request->getRemoteAddress();
151165
foreach ($allowedRanges as $range) {
152166
try {
@@ -164,8 +178,8 @@ protected function isWOPIRemoteAddress(): bool {
164178
return false;
165179
}
166180

167-
private function allowedRangeForApp(string $appId): array {
168-
$allowedRangesString = $this->config->getAppValue($appId, 'wopi_allowlist');
181+
private function allowedRangeForApp(string $appId, string: $configKey): array {
182+
$allowedRangesString = $this->config->getAppValue($appId, $configKey);
169183
if ($allowedRangesString === '') {
170184
return [];
171185
}

0 commit comments

Comments
 (0)