auto redirect invalid hostnames

This commit is contained in:
mein Name 2025-02-09 15:05:04 -05:00 committed by Henri Dickson
parent a527108c03
commit 2d7ff41de5

View file

@ -1,6 +1,7 @@
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.cache import cache from django.core.cache import cache
from django.core.exceptions import DisallowedHost
from django.http import HttpRequest, JsonResponse from django.http import HttpRequest, JsonResponse
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.urls import reverse from django.urls import reverse
@ -81,6 +82,9 @@ def nodeinfo2(request):
def error_400(request, exception=None): def error_400(request, exception=None):
if isinstance(exception, DisallowedHost):
url = settings.SITE_INFO["site_url"] + request.get_full_path()
return redirect(url, permanent=True)
return render(request, "400.html", status=400, context={"exception": exception}) return render(request, "400.html", status=400, context={"exception": exception})