Skip to content
Merged
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
16 changes: 9 additions & 7 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private function getUriEncodedParams(array $params): string {
* More info in docs: https://cloud-py-api.github.io/app_api/authentication.html
*/
public function validateExAppRequestToNC(IRequest $request, bool $isDav = false): bool {
$this->throttler->sleepDelayOrThrowOnMax($request->getRemoteAddress(), Application::APP_ID);
$delay = $this->throttler->sleepDelayOrThrowOnMax($request->getRemoteAddress(), Application::APP_ID);

$exAppId = $request->getHeader('EX-APP-ID');
if (!$exAppId) {
Expand Down Expand Up @@ -346,7 +346,7 @@ public function validateExAppRequestToNC(IRequest $request, bool $isDav = false)
}
}

return $this->finalizeRequestToNC($exApp, $userId, $request);
return $this->finalizeRequestToNC($exApp, $userId, $request, $delay);
} else {
$this->logger->error(sprintf('Invalid signature for ExApp: %s and user: %s.', $exApp->getAppid(), $userId !== '' ? $userId : 'null'));
$this->throttler->registerAttempt(Application::APP_ID, $request->getRemoteAddress(), [
Expand All @@ -364,7 +364,7 @@ public function validateExAppRequestToNC(IRequest $request, bool $isDav = false)
* - sets active user (null if not a user context)
* - updates ExApp last response time
*/
private function finalizeRequestToNC(ExApp $exApp, string $userId, IRequest $request): bool {
private function finalizeRequestToNC(ExApp $exApp, string $userId, IRequest $request, int $delay): bool {
if ($userId !== '') {
$activeUser = $this->userManager->get($userId);
if ($activeUser === null) {
Expand All @@ -379,10 +379,12 @@ private function finalizeRequestToNC(ExApp $exApp, string $userId, IRequest $req
$this->session->set('app_api', true);
$this->session->set('app_api_system', true); // TODO: Remove after drop support NC29

$this->throttler->resetDelay($request->getRemoteAddress(), Application::APP_ID, [
'appid' => $request->getHeader('EX-APP-ID'),
'userid' => $userId,
]);
if ($delay) {
$this->throttler->resetDelay($request->getRemoteAddress(), Application::APP_ID, [
'appid' => $request->getHeader('EX-APP-ID'),
'userid' => $userId,
]);
}
return true;
}

Expand Down