Configure django-allauth to use X-Real-IP for rate limiting

Also remove the unused get_client_ip helper

See: https://docs.allauth.org/en/latest/release-notes/recent.html#id3
This commit is contained in:
FuzzyGrim
2026-03-31 21:42:03 +02:00
parent d8306c760c
commit fc2bf094a0
3 changed files with 3 additions and 15 deletions

View File

@@ -39,6 +39,7 @@ http {
location / {
proxy_pass http://app_server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
}
@@ -47,6 +48,7 @@ http {
access_log off;
proxy_pass http://app_server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
}

View File

@@ -542,6 +542,7 @@ CELERY_BEAT_SCHEDULE = {
},
}
# Allauth settings
ALLAUTH_TRUSTED_CLIENT_IP_HEADER = "X-Real-IP"
if CSRF_TRUSTED_ORIGINS:
# Check if all origins start with http:// or https://
all_http = all(

View File

@@ -8,21 +8,6 @@ from django.utils import timezone
import integrations
def get_client_ip(request):
"""Return the client's IP address.
Used when logging for user registration and login.
"""
# get the user's IP address
ip_address = request.headers.get("x-forwarded-for")
# if the IP address is not available in HTTP_X_FORWARDED_FOR
if not ip_address:
ip_address = request.META.get("REMOTE_ADDR")
return ip_address
def process_task_result(task):
"""Process task result based on status and format appropriately."""
if task.status == "FAILURE":