diff --git a/api/.env.example b/api/.env.example index 76ea6de3d2..0be5388790 100644 --- a/api/.env.example +++ b/api/.env.example @@ -19,6 +19,8 @@ DJANGO_REFRESH_TOKEN_LIFETIME=1440 DJANGO_CACHE_MAX_AGE=3600 DJANGO_STALE_WHILE_REVALIDATE=60 DJANGO_SECRETS_ENCRYPTION_KEY="" +# Throttle, two options: Empty means no throttle; or if desired use one in DRF format: https://www.django-rest-framework.org/api-guide/throttling/#setting-the-throttling-policy +DJANGO_THROTTLE_TOKEN_OBTAIN=50/minute # Decide whether to allow Django manage database table partitions DJANGO_MANAGE_DB_PARTITIONS=[True|False] DJANGO_CELERY_DEADLOCK_ATTEMPTS=5 diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index f099949d07..67c2c928e5 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the **Prowler API** are documented in this file. ### Added - Integration with JIRA, enabling sending findings to a JIRA project [(#8622)](https://github.com/prowler-cloud/prowler/pull/8622), [(#8637)](https://github.com/prowler-cloud/prowler/pull/8637) - `GET /overviews/findings_severity` now supports `filter[status]` and `filter[status__in]` to aggregate by specific statuses (`FAIL`, `PASS`)[(#8186)](https://github.com/prowler-cloud/prowler/pull/8186) +- Throttling options for `/api/v1/tokens` using the `DJANGO_THROTTLE_TOKEN_OBTAIN` environment variable [(#8647)](https://github.com/prowler-cloud/prowler/pull/8647) --- diff --git a/api/src/backend/api/v1/views.py b/api/src/backend/api/v1/views.py index 27f3e324a9..f86c11ca72 100644 --- a/api/src/backend/api/v1/views.py +++ b/api/src/backend/api/v1/views.py @@ -215,6 +215,8 @@ class RelationshipViewSchema(JsonApiAutoSchema): description="Obtain a token by providing valid credentials and an optional tenant ID.", ) class CustomTokenObtainView(GenericAPIView): + throttle_scope = "token-obtain" + resource_name = "tokens" serializer_class = TokenSerializer http_method_names = ["post"] diff --git a/api/src/backend/config/django/base.py b/api/src/backend/config/django/base.py index 37d905ba58..6a67179640 100644 --- a/api/src/backend/config/django/base.py +++ b/api/src/backend/config/django/base.py @@ -108,6 +108,12 @@ REST_FRAMEWORK = { ), "TEST_REQUEST_DEFAULT_FORMAT": "vnd.api+json", "JSON_API_UNIFORM_EXCEPTIONS": True, + "DEFAULT_THROTTLE_CLASSES": [ + "rest_framework.throttling.ScopedRateThrottle", + ], + "DEFAULT_THROTTLE_RATES": { + "token-obtain": env("DJANGO_THROTTLE_TOKEN_OBTAIN", default=None), + }, } SPECTACULAR_SETTINGS = {