feat: limit the maximum number of webhooks per Watchlist

This commit is contained in:
Maël Gangloff 2024-08-18 18:25:11 +02:00
parent 050c82bea9
commit e1e54d9e26
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
3 changed files with 17 additions and 1 deletions

1
.env
View File

@ -70,3 +70,4 @@ OAUTH_SCOPE=
LIMITED_FEATURES=false
LIMIT_MAX_WATCHLIST=0
LIMIT_MAX_WATCHLIST_DOMAINS=0
LIMIT_MAX_WATCHLIST_WEBHOOKS=0

View File

@ -12,6 +12,7 @@ parameters:
limited_features: '%env(bool:LIMITED_FEATURES)%'
limit_max_watchlist: '%env(int:LIMIT_MAX_WATCHLIST)%'
limit_max_watchlist_domains: '%env(int:LIMIT_MAX_WATCHLIST_DOMAINS)%'
limit_max_watchlist_webhooks: '%env(int:LIMIT_MAX_WATCHLIST_DOMAINS)%'
services:
# default configuration for services in *this* file

View File

@ -102,7 +102,7 @@ class WatchListController extends AbstractController
*/
if ($this->getParameter('limited_features')) {
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
$this->logger->notice('User {username} tried to create a Watchlist. The maximum number of domains has been reached for this Watchlist', [
$this->logger->notice('User {username} tried to create a Watchlist. The maximum number of domains has been reached.', [
'username' => $user->getUserIdentifier(),
]);
throw new AccessDeniedHttpException('You have exceeded the maximum number of domain names allowed in this Watchlist');
@ -132,6 +132,13 @@ class WatchListController extends AbstractController
throw new AccessDeniedHttpException("It is forbidden to register the same domain name twice in your watchlists with limited mode ($ldhName)");
}
}
if (null !== $watchList->getWebhookDsn() && count($watchList->getWebhookDsn()) > (int) $this->getParameter('limit_max_watchlist_webhooks')) {
$this->logger->notice('User {username} tried to create a Watchlist. The maximum number of webhooks has been reached.', [
'username' => $user->getUserIdentifier(),
]);
throw new AccessDeniedHttpException('You have exceeded the maximum number of webhooks allowed in this Watchlist');
}
}
$user = $this->getUser();
@ -211,6 +218,13 @@ class WatchListController extends AbstractController
throw new AccessDeniedHttpException("It is forbidden to register the same domain name twice in your watchlists with limited mode ($ldhName)");
}
}
if (null !== $watchList->getWebhookDsn() && count($watchList->getWebhookDsn()) > (int) $this->getParameter('limit_max_watchlist_webhooks')) {
$this->logger->notice('User {username} tried to update a Watchlist. The maximum number of webhooks has been reached.', [
'username' => $user->getUserIdentifier(),
]);
throw new AccessDeniedHttpException('You have exceeded the maximum number of webhooks allowed in this Watchlist');
}
}
$this->logger->info('User {username} updates a Watchlist ({token}).', [