Open source video conferencing app powered by LiveKit. Built with Django and React.
ποΈ(backend) add a daily cap on room creation
lebaudantoine059e5f1ec4ce
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fa986657..5f511c17 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ and this project adheres to### Added- π(backend) throttle meeting link generation+- ποΈ(backend) add a daily cap on room creation## [1.33.0] - 2026-09-30diff --git a/docs/installation/kubernetes.md b/docs/installation/kubernetes.mdindex cd86f468..9f939921 100644--- a/docs/installation/kubernetes.md+++ b/docs/installation/kubernetes.md@@ -334,6 +334,7 @@ These are the environmental options available on meet backend.| REDIS_URL | Redis endpoint | redis://redis:6379/1 || SESSION_COOKIE_AGE | Session cookie expiration in seconds | 43200 (12 hours) || ROOM_CREATION_THROTTLE_RATES | Room creation throttle rate per authenticated user | 50/minute | 50/minute |+| ROOM_CREATION_DAILY_THROTTLE_RATES | Daily room creation cap per authenticated user | 1000/day || REQUEST_ENTRY_THROTTLE_RATES | Entry request throttle rates | 150/minute || CREATION_CALLBACK_THROTTLE_RATES | Creation callback throttle rates | 600/minute || SPECTACULAR_SETTINGS_ENABLE_DJANGO_DEPLOY_CHECK | Enable Django deploy check | false |diff --git a/src/backend/core/api/throttling.py b/src/backend/core/api/throttling.pyindex be2102b1..f12658ae 100644--- a/src/backend/core/api/throttling.py+++ b/src/backend/core/api/throttling.py@@ -37,6 +37,16 @@ class RoomCreationUserRateThrottle(MonitoredUserRateThrottle):return super().get_cache_key(request, view)+class RoomCreationDailyUserRateThrottle(RoomCreationUserRateThrottle):+ """Cap room creation per authenticated user over a day.++ Complements the short-term RoomCreationUserRateThrottle, which absorbs+ bursts but lets a user steadily create rooms over hours or days.+ """++ scope = "room_creation_daily"++class RequestEntryAuthenticatedUserRateThrottle(MonitoredUserRateThrottle):"""Throttle authenticated user requesting room entry"""diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.pyindex 48d74f03..68a5fc48 100644--- a/src/backend/core/api/viewsets.py+++ b/src/backend/core/api/viewsets.py@@ -180,7 +180,10 @@ class RoomViewSet(permission_classes = [permissions.RoomPermissions]queryset = models.Room.objects.all()serializer_class = serializers.RoomSerializer- throttle_classes = [throttling.RoomCreationUserRateThrottle]+ throttle_classes = [+ throttling.RoomCreationUserRateThrottle,+ throttling.RoomCreationDailyUserRateThrottle,+ ]def get_object(self):"""Allow getting a room by its slug."""diff --git a/src/backend/core/tests/rooms/test_api_rooms_create.py b/src/backend/core/tests/rooms/test_api_rooms_create.pyindex bc022ab3..1f9dc21b 100644--- a/src/backend/core/tests/rooms/test_api_rooms_create.py+++ b/src/backend/core/tests/rooms/test_api_rooms_create.py@@ -9,6 +9,10 @@ from django.core.cache import cacheimport pytestfrom rest_framework.test import APIClient+from ...api.throttling import (+ RoomCreationDailyUserRateThrottle,+ RoomCreationUserRateThrottle,+)from ...factories import RoomFactory, UserFactoryfrom ...models import Room, RoomAccessLevel@@ -373,3 +377,84 @@ def test_api_rooms_create_throttle_does_not_limit_other_actions(room_creation_th).status_code== 200)+++def daily_room_creation_throttle(monkeypatch):+ """Use a tiny daily cap, a loose burst limit and a controllable clock.++ Rates are patched with monkeypatch.setitem so they are restored after the+ test. Returns a one-item list holding the current fake timestamp.+ """+ rates = RoomCreationDailyUserRateThrottle.THROTTLE_RATES+ monkeypatch.setitem(rates, "room_creation", "100/minute")+ monkeypatch.setitem(rates, "room_creation_daily", "3/day")+ now = [1_000_000.0]+ monkeypatch.setattr(RoomCreationUserRateThrottle, "timer", lambda self: now[0])+ return now+++def test_api_rooms_create_daily_throttled(daily_room_creation_throttle):+ """The daily cap still applies once the short-term window has elapsed."""+ now = daily_room_creation_throttle+ client = APIClient()+ client.force_login(UserFactory())++ for index in range(3):+ response = client.post("/api/v1.0/rooms/", {"name": f"Room {index}"})+ assert response.status_code == 201+ now[0] += 120 # Spread creations beyond the short-term window.++ response = client.post("/api/v1.0/rooms/", {"name": "Blocked room"})+ assert response.status_code == 429+ assert int(response["Retry-After"]) > 60+ assert Room.objects.count() == 3+++def test_api_rooms_create_daily_throttle_resets(daily_room_creation_throttle):+ """Room creation is allowed again once a day has passed."""+ now = daily_room_creation_throttle+ client = APIClient()+ client.force_login(UserFactory())++ for index in range(3):+ response = client.post("/api/v1.0/rooms/", {"name": f"Room {index}"})+ assert response.status_code == 201++ response = client.post("/api/v1.0/rooms/", {"name": "Blocked room"})+ assert response.status_code == 429++ now[0] += 24 * 60 * 60 + 1+ response = client.post("/api/v1.0/rooms/", {"name": "Next day room"})+ assert response.status_code == 201+++def test_api_rooms_create_daily_throttle_per_user(daily_room_creation_throttle):+ """Each user has its own daily cap."""+ client = APIClient()+ client.force_login(UserFactory())+ for index in range(3):+ response = client.post("/api/v1.0/rooms/", {"name": f"Room {index}"})+ assert response.status_code == 201+ assert client.post("/api/v1.0/rooms/", {"name": "Blocked"}).status_code == 429++ client.force_login(UserFactory())+ response = client.post("/api/v1.0/rooms/", {"name": "Other user room"})+ assert response.status_code == 201+++def test_api_rooms_create_daily_throttle_does_not_limit_other_actions(+ daily_room_creation_throttle,+):+ """Reaching the daily cap leaves listing and updating available."""+ client = APIClient()+ client.force_login(UserFactory())+ for index in range(3):+ response = client.post("/api/v1.0/rooms/", {"name": f"Room {index}"})+ assert response.status_code == 201+ room_id = response.json()["id"]++ assert client.post("/api/v1.0/rooms/", {"name": "Blocked"}).status_code == 429+ assert client.get("/api/v1.0/rooms/").status_code == 200+ response = client.patch(f"/api/v1.0/rooms/{room_id}/", {"name": "Renamed"})+ assert response.status_code == 200diff --git a/src/backend/meet/settings.py b/src/backend/meet/settings.pyindex 78bd4ff1..abd462ad 100755--- a/src/backend/meet/settings.py+++ b/src/backend/meet/settings.py@@ -366,6 +366,11 @@ class Base(Configuration):environ_name="ROOM_CREATION_THROTTLE_RATES",environ_prefix=None,),+ "room_creation_daily": values.Value(+ default="1000/day",+ environ_name="ROOM_CREATION_DAILY_THROTTLE_RATES",+ environ_prefix=None,+ ),"request_entry": values.Value(default="150/minute",environ_name="REQUEST_ENTRY_THROTTLE_RATES",