feat(backend): add throtteling by default (#11951)

* feat(backend): add throtteling by default

* add changelog entry

* ignore throtetling in debug mode

* increase threshold
This commit is contained in:
Matthias Mair
2026-08-10 18:41:15 +10:00
committed by GitHub
parent 1b20920e4a
commit 324b0ca012
4 changed files with 25 additions and 1 deletions
@@ -529,6 +529,8 @@ REST_FRAMEWORK = {
'DEFAULT_METADATA_CLASS': 'InvenTree.metadata.InvenTreeMetadata',
'DEFAULT_RENDERER_CLASSES': ['rest_framework.renderers.JSONRenderer'],
'TOKEN_MODEL': 'users.models.ApiToken',
'DEFAULT_THROTTLE_CLASSES': [],
'DEFAULT_THROTTLE_RATES': {},
}
if DEBUG:
@@ -544,6 +546,21 @@ if USE_JWT:
JWT_AUTH_REFRESH_COOKIE = 'inventree-token'
INSTALLED_APPS.append('rest_framework_simplejwt')
# Throtteling setup
THROTTLE_ANON = get_setting('INVENTREE_THROTTLE_ANON', 'throttle.anon', '20/minute')
THROTTLE_USER = get_setting('INVENTREE_THROTTLE_USER', 'throttle.user', '60/second')
if not DEBUG and THROTTLE_ANON and str(THROTTLE_ANON).lower() != 'none':
REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['anon'] = THROTTLE_ANON
REST_FRAMEWORK['DEFAULT_THROTTLE_CLASSES'].append(
'rest_framework.throttling.AnonRateThrottle'
)
if not DEBUG and THROTTLE_USER and str(THROTTLE_USER).lower() != 'none':
REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user'] = THROTTLE_USER
REST_FRAMEWORK['DEFAULT_THROTTLE_CLASSES'].append(
'rest_framework.throttling.UserRateThrottle'
)
# WSGI default setting
WSGI_APPLICATION = 'InvenTree.wsgi.application'
@@ -162,6 +162,11 @@ cors:
# regex:
# Throttling is applied to the API by default to make DoS attacks more difficult; these can be disabled by setting them to None.
# throttle:
# anon: '20/minute'
# user: '60/second'
# MEDIA_ROOT is the local filesystem location for storing uploaded files
#media_root: '/home/inventree/data/media'