Skip to content

Commit 972b4ad

Browse files
committed
fix: normalize missing bruteforce_protection and headers_to_exclude on ExApp routes
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent 75a8c7b commit 972b4ad

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

lib/Controller/ExAppProxyController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
1616
use OCA\AppAPI\AppInfo\Application;
1717
use OCA\AppAPI\Db\ExApp;
18+
use OCA\AppAPI\Db\ExAppMapper;
1819
use OCA\AppAPI\Db\ExAppRouteAccessLevel;
1920
use OCA\AppAPI\ProxyResponse;
2021
use OCA\AppAPI\Service\AppAPIService;
@@ -261,9 +262,7 @@ private function prepareProxy(
261262
);
262263
return null;
263264
}
264-
$bruteforceProtection = isset($route['bruteforce_protection'])
265-
? json_decode($route['bruteforce_protection'], true)
266-
: [];
265+
$bruteforceProtection = ExAppMapper::parseJsonList($route['bruteforce_protection'] ?? null);
267266
if (!empty($bruteforceProtection)) {
268267
$delay = $this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), Application::APP_ID);
269268
}
@@ -350,8 +349,10 @@ private function passesExAppProxyRouteAccessLevelCheck(int $accessLevel): bool {
350349
}
351350

352351
private function buildHeadersWithExclude(array $route, array $headers): array {
353-
$headersToExclude = json_decode($route['headers_to_exclude'], true);
354-
$headersToExclude = array_map('strtolower', $headersToExclude);
352+
$headersToExclude = array_map(
353+
'strtolower',
354+
array_filter(ExAppMapper::parseJsonList($route['headers_to_exclude'] ?? null), 'is_string')
355+
);
355356

356357
if (!in_array('x-origin-ip', $headersToExclude)) {
357358
$headersToExclude[] = 'x-origin-ip';

lib/Db/ExAppMapper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ public function __construct(IDBConnection $db) {
2525
parent::__construct($db, 'ex_apps');
2626
}
2727

28+
/**
29+
* Decode a JSON-list column (`bruteforce_protection`, `headers_to_exclude`) into an array,
30+
* tolerating NULL / non-string / malformed values from legacy rows.
31+
*/
32+
public static function parseJsonList(mixed $raw): array {
33+
if (!is_string($raw)) {
34+
return [];
35+
}
36+
$decoded = json_decode($raw, true);
37+
return is_array($decoded) ? $decoded : [];
38+
}
39+
2840
/**
2941
* @throws Exception
3042
*

lib/Service/ExAppService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,8 @@ public function getExApps(): array {
418418
public function registerExAppRoutes(ExApp $exApp, array $routes): ?ExApp {
419419
try {
420420
$this->exAppMapper->registerExAppRoutes($exApp, $routes);
421-
$exApp->setRoutes($routes);
422-
return $exApp;
423-
} catch (Exception $e) {
421+
return $this->exAppMapper->findByAppId($exApp->getAppid());
422+
} catch (Exception|MultipleObjectsReturnedException|DoesNotExistException $e) {
424423
$this->logger->error(sprintf('Error while registering ExApp %s routes: %s. Routes: %s', $exApp->getAppid(), $e->getMessage(), json_encode($routes)));
425424
return null;
426425
}

lib/Service/HarpService.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use GuzzleHttp\Exception\ClientException;
1414
use OCA\AppAPI\Db\DaemonConfig;
1515
use OCA\AppAPI\Db\ExApp;
16+
use OCA\AppAPI\Db\ExAppMapper;
1617
use OCA\AppAPI\DeployActions\ManualActions;
1718
use OCP\ICertificateManager;
1819
use OCP\IConfig;
@@ -116,14 +117,10 @@ public function getHarpExApp(ExApp $exApp): array {
116117
'host' => $this->getExAppHost($exApp),
117118
'port' => $exApp->getPort(),
118119
'routes' => array_map(function ($route) {
119-
$bruteforceList = json_decode($route['bruteforce_protection'], true);
120-
if (!$bruteforceList) {
121-
$bruteforceList = [];
122-
}
123120
return [
124121
'url' => $route['url'],
125122
'access_level' => $route['access_level'],
126-
'bruteforce_protection' => $bruteforceList,
123+
'bruteforce_protection' => ExAppMapper::parseJsonList($route['bruteforce_protection'] ?? null),
127124
];
128125
}, $exApp->getRoutes()),
129126
];

0 commit comments

Comments
 (0)