Skip to content

Commit 406e473

Browse files
authored
feat(login): add throttling option for the /api/v1/tokens endpoint (#8647)
1 parent 1a2bf46 commit 406e473

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

api/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ DJANGO_REFRESH_TOKEN_LIFETIME=1440
1919
DJANGO_CACHE_MAX_AGE=3600
2020
DJANGO_STALE_WHILE_REVALIDATE=60
2121
DJANGO_SECRETS_ENCRYPTION_KEY=""
22+
# 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
23+
DJANGO_THROTTLE_TOKEN_OBTAIN=50/minute
2224
# Decide whether to allow Django manage database table partitions
2325
DJANGO_MANAGE_DB_PARTITIONS=[True|False]
2426
DJANGO_CELERY_DEADLOCK_ATTEMPTS=5

api/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to the **Prowler API** are documented in this file.
77
### Added
88
- 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)
99
- `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)
10+
- Throttling options for `/api/v1/tokens` using the `DJANGO_THROTTLE_TOKEN_OBTAIN` environment variable [(#8647)](https://github.com/prowler-cloud/prowler/pull/8647)
1011

1112
---
1213

api/src/backend/api/v1/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ def _resolve_path_parameters(self, _path_variables):
215215
description="Obtain a token by providing valid credentials and an optional tenant ID.",
216216
)
217217
class CustomTokenObtainView(GenericAPIView):
218+
throttle_scope = "token-obtain"
219+
218220
resource_name = "tokens"
219221
serializer_class = TokenSerializer
220222
http_method_names = ["post"]

api/src/backend/config/django/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@
108108
),
109109
"TEST_REQUEST_DEFAULT_FORMAT": "vnd.api+json",
110110
"JSON_API_UNIFORM_EXCEPTIONS": True,
111+
"DEFAULT_THROTTLE_CLASSES": [
112+
"rest_framework.throttling.ScopedRateThrottle",
113+
],
114+
"DEFAULT_THROTTLE_RATES": {
115+
"token-obtain": env("DJANGO_THROTTLE_TOKEN_OBTAIN", default=None),
116+
},
111117
}
112118

113119
SPECTACULAR_SETTINGS = {

0 commit comments

Comments
 (0)