From f60459fe998d830f50cb722de0cc3f4d4191f9b5 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 4 Jan 2024 10:04:35 +0100 Subject: [PATCH] fix(appointments): Rate limit config creation and booking Abusing the appointment config endpoint can lead to additional server load. Sending bulks of booking requests can lead to mass notifications and emails and server load, too. Signed-off-by: Christoph Wurst --- lib/Controller/AppointmentConfigController.php | 3 +++ lib/Controller/BookingController.php | 7 +++++++ src/components/AppointmentConfigModal.vue | 11 ++++++++++- src/components/Appointments/AppointmentDetails.vue | 8 ++++++++ src/views/Appointments/Booking.vue | 9 ++++++++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/Controller/AppointmentConfigController.php b/lib/Controller/AppointmentConfigController.php index 8af29cb7d..33b131040 100644 --- a/lib/Controller/AppointmentConfigController.php +++ b/lib/Controller/AppointmentConfigController.php @@ -35,6 +35,7 @@ use OCA\Calendar\Service\Appointments\AppointmentConfigService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\UserRateLimit; use OCP\IRequest; use Psr\Log\LoggerInterface; use function array_keys; @@ -148,7 +149,9 @@ private function validateAvailability(array $availability): void { * @param int|null $end * @param int|null $futureLimit * @return JsonResponse + * @UserRateThrottle(limit=10, period=1200) */ + #[UserRateLimit(limit: 10, period: 1200)] public function create( string $name, string $description, diff --git a/lib/Controller/BookingController.php b/lib/Controller/BookingController.php index 4339c1430..f1142d919 100644 --- a/lib/Controller/BookingController.php +++ b/lib/Controller/BookingController.php @@ -38,6 +38,8 @@ use OCA\Calendar\Service\Appointments\BookingService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\AnonRateLimit; +use OCP\AppFramework\Http\Attribute\UserRateLimit; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Utility\ITimeFactory; @@ -163,7 +165,12 @@ public function getBookableSlots(int $appointmentConfigId, * @param string $description * @param string $timeZone * @return JsonResponse + * + * @AnonRateThrottle(limit=10, period=1200) + * @UserRateThrottle(limit=10, period=300) */ + #[AnonRateLimit(limit: 10, period: 1200)] + #[UserRateLimit(limit: 10, period: 300)] public function bookSlot(int $appointmentConfigId, int $start, int $end, diff --git a/src/components/AppointmentConfigModal.vue b/src/components/AppointmentConfigModal.vue index 4e4975ab2..30defdbff 100644 --- a/src/components/AppointmentConfigModal.vue +++ b/src/components/AppointmentConfigModal.vue @@ -127,7 +127,10 @@ -