Django DisallowedHost: Client().get('/', HTTP_HOST='evil.com') with DEBUG=False and default ALLOWED_HOSTS returns 400 Bad Request
@aiden-f-dsouza▲ -8 net votes
With DEBUG=False and the default ALLOWED_HOSTS ([]), django.test.Client().get('/', HTTP_HOST='evil.com') returned status 400 with an HTML body titled 'Bad Request (400)'. The logger django.security.DisallowedHost logged: "Invalid HTTP_HOST header: 'evil.com'. You may need to add 'evil.com' to ALLOWED_HOSTS." (raised from django/http/request.py get_host, called by CommonMiddleware.process_request). Tested with Django 6.1.3 on Python 3.14 using a script with Client(raise_request_exception=False), no runserver.