Skip to content
Snippets Groups Projects
Verified Commit 6072f51a authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Rate limit invite endpoint

To prevent hammering on the invite endpoint we throttle requests to the
endpoint to 100/day per ip.

Resolves: GREG-84
parent 334b011e
No related branches found
No related tags found
1 merge request!134Rate limit invite endpoint
Pipeline #99946 passed
...@@ -268,6 +268,17 @@ INTERNAL_RK_PREFIX = "no.{instance}.greg".format(instance=INSTANCE_NAME) ...@@ -268,6 +268,17 @@ INTERNAL_RK_PREFIX = "no.{instance}.greg".format(instance=INSTANCE_NAME)
FEIDE_SOURCE = "feide" FEIDE_SOURCE = "feide"
# Rate limit settings of invite endpoint
REST_FRAMEWORK = {
"DEFAULT_THROTTLE_CLASSES": [
"rest_framework.throttling.AnonRateThrottle",
],
"DEFAULT_THROTTLE_RATES": {
"anon": "100/day",
},
}
# Used by the OU import from orgreg to distinguish the OuIdentifiers from others # Used by the OU import from orgreg to distinguish the OuIdentifiers from others
ORGREG_SOURCE = "orgreg" ORGREG_SOURCE = "orgreg"
ORGREG_NAME = "orgreg_id" ORGREG_NAME = "orgreg_id"
......
...@@ -45,6 +45,14 @@ SESSION_COOKIE_SAMESITE = "Lax" ...@@ -45,6 +45,14 @@ SESSION_COOKIE_SAMESITE = "Lax"
SESSION_COOKIE_AGE = 1209600 # two weeks for easy development SESSION_COOKIE_AGE = 1209600 # two weeks for easy development
# Disable throttling in development, uncomment CACHES to test
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
}
try: try:
from .local import * from .local import *
except ImportError: except ImportError:
......
...@@ -27,6 +27,13 @@ ALLOWED_HOSTS = ( ...@@ -27,6 +27,13 @@ ALLOWED_HOSTS = (
else [] else []
) )
# This is the default values for CACHES, only present for clarity
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
}
}
try: try:
from .local import * from .local import *
......
...@@ -11,6 +11,7 @@ from rest_framework.generics import CreateAPIView, GenericAPIView, DestroyAPIVie ...@@ -11,6 +11,7 @@ from rest_framework.generics import CreateAPIView, GenericAPIView, DestroyAPIVie
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.throttling import AnonRateThrottle
from rest_framework.views import APIView from rest_framework.views import APIView
from greg.models import Identity, InvitationLink, Person from greg.models import Identity, InvitationLink, Person
...@@ -96,6 +97,7 @@ class InvitationView(CreateAPIView, DestroyAPIView): ...@@ -96,6 +97,7 @@ class InvitationView(CreateAPIView, DestroyAPIView):
class CheckInvitationView(APIView): class CheckInvitationView(APIView):
authentication_classes = [] authentication_classes = []
permission_classes = [AllowAny] permission_classes = [AllowAny]
throttle_classes = [AnonRateThrottle]
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment