Skip to content

Commit f13303e

Browse files
authored
Set up ScopedRateThrottle for endpoint-specific rate limits (#3581)
* fix: Update node and CI workflows - Update node version to latest LTS - Copy/paste pyjs dockerfile - temporarily ignore optional deps - Pytest no longer on PATH - Ignore tsc error - Remove coverage step - suppress eslint errors * Set up ScopedRateThrottle for endpoint-specific rate limits PR #3544 disabled ratelimiting for AdminAPI views. This change improves control over rate limits and helps prevent over-throttling. - Removed global throttles (`AnonRateThrottle`, `UserRateThrottle`) - Added `ScopedRateThrottle` to control rate limits per endpoint - Defined custom rate to protect AdminAPI endpoints from DoS @W-17141510
1 parent 4954371 commit f13303e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

config/settings/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,12 @@ def safe_key() -> str:
456456
"rest_framework.authentication.SessionAuthentication",
457457
),
458458
'DEFAULT_THROTTLE_CLASSES': [
459-
'rest_framework.throttling.AnonRateThrottle',
460-
'rest_framework.throttling.UserRateThrottle'
459+
'rest_framework.throttling.ScopedRateThrottle',
461460
],
462461
'DEFAULT_THROTTLE_RATES': {
463462
'anon': '4/second',
464463
'user': '4/second',
464+
'admin_api': '150/minute',
465465
}
466466

467467
}

metadeploy/adminapi/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Meta:
138138
class PlanTemplateViewSet(AdminAPIViewSet):
139139
model_name = "PlanTemplate"
140140
serializer_base = PlanTemplateSerializer
141-
throttle_classes = []
141+
throttle_scope = 'admin_api'
142142

143143

144144
class PlanFilter(filters.FilterSet):
@@ -151,27 +151,27 @@ class PlanViewSet(AdminAPIViewSet):
151151
model_name = "Plan"
152152
serializer_base = PlanSerializer
153153
filterset_class = PlanFilter
154-
throttle_classes = []
154+
throttle_scope = 'admin_api'
155155

156156

157157
class PlanSlugViewSet(AdminAPIViewSet):
158158
model_name = "PlanSlug"
159-
throttle_classes = []
159+
throttle_scope = 'admin_api'
160160

161161

162162
class VersionViewSet(AdminAPIViewSet):
163163
model_name = "Version"
164-
throttle_classes = []
164+
throttle_scope = 'admin_api'
165165

166166

167167
class ProductCategoryViewSet(AdminAPIViewSet):
168168
model_name = "ProductCategory"
169-
throttle_classes = []
169+
throttle_scope = 'admin_api'
170170

171171

172172
class AllowedListViewSet(AdminAPIViewSet):
173173
model_name = "AllowedList"
174-
throttle_classes = []
174+
throttle_scope = 'admin_api'
175175

176176

177177
class AllowedListOrgSerializer(AdminAPISerializer):
@@ -181,7 +181,7 @@ class AllowedListOrgSerializer(AdminAPISerializer):
181181
class AllowedListOrgViewSet(AdminAPIViewSet):
182182
model_name = "AllowedListOrg"
183183
serializer_base = AllowedListOrgSerializer
184-
throttle_classes = []
184+
throttle_scope = 'admin_api'
185185

186186

187187
class TranslationViewSet(viewsets.ViewSet):
@@ -201,7 +201,7 @@ class TranslationViewSet(viewsets.ViewSet):
201201

202202
permission_classes = [IsAPIUser]
203203
model_name = "Translation"
204-
throttle_classes = []
204+
throttle_scope = 'admin_api'
205205

206206
def partial_update(self, request, pk=None):
207207
# Add or update a Translation record for each message

0 commit comments

Comments
 (0)