Skip to content
Merged
Show file tree
Hide file tree
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
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]>
  • Loading branch information
nc-fkl authored and andrey18106 committed Mar 18, 2024
commit f3a4abd98cc84f3ecdfd4421015d310a731ecb2d
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
$c->get(IRequest::class),
$c->get(IUserSession::class),
$c->get(IControllerMethodReflector::class),
$c->get(OC\Security\RateLimiting\Limiter::class)
$c->get(OC\Security\RateLimiting\Limiter::class),
$c->get(ISession::class)
)
);
$dispatcher->registerMiddleware(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Middleware;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use ReflectionMethod;

Expand Down Expand Up @@ -70,6 +71,7 @@ public function __construct(
protected IUserSession $userSession,
protected ControllerMethodReflector $reflector,
protected Limiter $limiter,
protected ISession $session,
) {
}

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

if ($this->session->exists('app_api_system')) {
// Bypass rate limiting for app_api
return;
}

if ($this->userSession->isLoggedIn()) {
$rateLimit = $this->readLimitFromAnnotationOrAttribute($controller, $methodName, 'UserRateThrottle', UserRateLimit::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -77,6 +78,7 @@ class RateLimitingMiddlewareTest extends TestCase {
private IUserSession|MockObject $userSession;
private ControllerMethodReflector $reflector;
private Limiter|MockObject $limiter;
private ISession|MockObject $session;
private RateLimitingMiddleware $rateLimitingMiddleware;

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

$this->rateLimitingMiddleware = new RateLimitingMiddleware(
$this->request,
$this->userSession,
$this->reflector,
$this->limiter
$this->limiter,
$this->session
);
}

Expand Down