diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php index e2308e300c1..1da09a0b903 100644 --- a/lib/Controller/SignalingController.php +++ b/lib/Controller/SignalingController.php @@ -53,12 +53,10 @@ use OCP\DB\Exception; use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; -use OCP\IConfig; use OCP\IDBConnection; use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; -use OCP\Security\Bruteforce\IThrottler; use Psr\Log\LoggerInterface; /** @@ -72,7 +70,6 @@ class SignalingController extends OCSController { public function __construct( string $appName, IRequest $request, - IConfig $serverConfig, private Config $talkConfig, private \OCA\Talk\Signaling\Manager $signalingManager, private TalkSession $session, @@ -86,7 +83,6 @@ public function __construct( private IEventDispatcher $dispatcher, private ITimeFactory $timeFactory, private IClientService $clientService, - IThrottler $throttler, private LoggerInterface $logger, private ?string $userId, ) { diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index 0c0a939038d..7f48a4eaccf 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -57,6 +57,7 @@ use OCP\Federation\ICloudIdManager; use OCP\IRequest; use OCP\Security\Bruteforce\IThrottler; +use OCP\Security\Bruteforce\MaxDelayReached; class InjectionMiddleware extends Middleware { protected bool $isTalkFederation = false; @@ -316,7 +317,11 @@ public function afterException($controller, $methodName, \Exception $exception): $action = $protection->getAction(); if ('talkRoomToken' === $action) { - $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); + try { + $this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), $action); + } catch (MaxDelayReached $e) { + throw new OCSException($e->getMessage(), Http::STATUS_TOO_MANY_REQUESTS); + } $this->throttler->registerAttempt($action, $this->request->getRemoteAddress(), [ 'token' => $this->request->getParam('token') ?? '', ]); diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php index ebd70619565..6118636504d 100644 --- a/tests/php/Controller/SignalingControllerTest.php +++ b/tests/php/Controller/SignalingControllerTest.php @@ -136,7 +136,6 @@ public function setUp(): void { $this->messages = $this->createMock(Messages::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->clientService = $this->createMock(IClientService::class); - $this->throttler = $this->createMock(IThrottler::class); $this->logger = $this->createMock(LoggerInterface::class); $this->recreateSignalingController(); } @@ -145,7 +144,6 @@ private function recreateSignalingController() { $this->controller = new CustomInputSignalingController( 'spreed', $this->createMock(IRequest::class), - $this->serverConfig, $this->config, $this->signalingManager, $this->session, @@ -159,7 +157,6 @@ private function recreateSignalingController() { $this->dispatcher, $this->timeFactory, $this->clientService, - $this->throttler, $this->logger, $this->userId );