Skip to content

Commit ca655ba

Browse files
nc-fklAltahrim
authored andcommitted
fix: add check for app_api_system session flag to bypass rate limit
Signed-off-by: Florian Klinger <[email protected]> Signed-off-by: Andrey Borysenko <[email protected]>
1 parent 88859aa commit ca655ba

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
302302
$c->get(IRequest::class),
303303
$c->get(IUserSession::class),
304304
$c->get(IControllerMethodReflector::class),
305-
$c->get(OC\Security\RateLimiting\Limiter::class)
305+
$c->get(OC\Security\RateLimiting\Limiter::class),
306+
$c->get(ISession::class)
306307
)
307308
);
308309
$dispatcher->registerMiddleware(

lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCP\AppFramework\Http\TemplateResponse;
4141
use OCP\AppFramework\Middleware;
4242
use OCP\IRequest;
43+
use OCP\ISession;
4344
use OCP\IUserSession;
4445
use ReflectionMethod;
4546

@@ -70,6 +71,7 @@ public function __construct(
7071
protected IUserSession $userSession,
7172
protected ControllerMethodReflector $reflector,
7273
protected Limiter $limiter,
74+
protected ISession $session,
7375
) {
7476
}
7577

@@ -81,6 +83,11 @@ public function beforeController(Controller $controller, string $methodName): vo
8183
parent::beforeController($controller, $methodName);
8284
$rateLimitIdentifier = get_class($controller) . '::' . $methodName;
8385

86+
if ($this->session->exists('app_api_system')) {
87+
// Bypass rate limiting for app_api
88+
return;
89+
}
90+
8491
if ($this->userSession->isLoggedIn()) {
8592
$rateLimit = $this->readLimitFromAnnotationOrAttribute($controller, $methodName, 'UserRateThrottle', UserRateLimit::class);
8693

tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCP\AppFramework\Http\DataResponse;
3838
use OCP\AppFramework\Http\TemplateResponse;
3939
use OCP\IRequest;
40+
use OCP\ISession;
4041
use OCP\IUser;
4142
use OCP\IUserSession;
4243
use PHPUnit\Framework\MockObject\MockObject;
@@ -77,6 +78,7 @@ class RateLimitingMiddlewareTest extends TestCase {
7778
private IUserSession|MockObject $userSession;
7879
private ControllerMethodReflector $reflector;
7980
private Limiter|MockObject $limiter;
81+
private ISession|MockObject $session;
8082
private RateLimitingMiddleware $rateLimitingMiddleware;
8183

8284
protected function setUp(): void {
@@ -86,12 +88,14 @@ protected function setUp(): void {
8688
$this->userSession = $this->createMock(IUserSession::class);
8789
$this->reflector = new ControllerMethodReflector();
8890
$this->limiter = $this->createMock(Limiter::class);
91+
$this->session = $this->createMock(ISession::class);
8992

9093
$this->rateLimitingMiddleware = new RateLimitingMiddleware(
9194
$this->request,
9295
$this->userSession,
9396
$this->reflector,
94-
$this->limiter
97+
$this->limiter,
98+
$this->session
9599
);
96100
}
97101

0 commit comments

Comments
 (0)