Fixes: add debugging log

This commit is contained in:
Egor Pavlovich Gorbunov 2025-06-05 19:08:13 +03:00
parent 8e7a6caae9
commit b01041d150

View file

@ -14,6 +14,8 @@ from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.exceptions import InvalidToken
from sentry_sdk import capture_exception
from evibes.settings import DEBUG
logger = logging.getLogger(__name__)
@ -70,6 +72,8 @@ class BlockInvalidHostMiddleware:
allowed_hosts = getenv("ALLOWED_HOSTS").split(" ")
if not hasattr(request, "META"):
return BadRequest("Invalid Request")
if DEBUG:
logger.debug(f"Checking {request.META.get("HTTP_HOST")} for presence in ALLOWED_HOSTS({allowed_hosts})")
if request.META.get("HTTP_HOST") not in allowed_hosts and "*" not in allowed_hosts:
return HttpResponseForbidden("Invalid Host Header")
return self.get_response(request)