mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed CVE-2016-9014 -- Validated Host header when DEBUG=True.
This is a security fix.
This commit is contained in:
parent
da7910d483
commit
7fe2d8d940
7 changed files with 95 additions and 21 deletions
|
@ -779,21 +779,22 @@ class HostValidationTests(SimpleTestCase):
|
|||
self.assertEqual(request.get_port(), '8080')
|
||||
|
||||
@override_settings(DEBUG=True, ALLOWED_HOSTS=[])
|
||||
def test_host_validation_disabled_in_debug_mode(self):
|
||||
"""If ALLOWED_HOSTS is empty and DEBUG is True, all hosts pass."""
|
||||
request = HttpRequest()
|
||||
request.META = {
|
||||
'HTTP_HOST': 'example.com',
|
||||
}
|
||||
self.assertEqual(request.get_host(), 'example.com')
|
||||
def test_host_validation_in_debug_mode(self):
|
||||
"""
|
||||
If ALLOWED_HOSTS is empty and DEBUG is True, variants of localhost are
|
||||
allowed.
|
||||
"""
|
||||
valid_hosts = ['localhost', '127.0.0.1', '[::1]']
|
||||
for host in valid_hosts:
|
||||
request = HttpRequest()
|
||||
request.META = {'HTTP_HOST': host}
|
||||
self.assertEqual(request.get_host(), host)
|
||||
|
||||
# Invalid hostnames would normally raise a SuspiciousOperation,
|
||||
# but we have DEBUG=True, so this check is disabled.
|
||||
request = HttpRequest()
|
||||
request.META = {
|
||||
'HTTP_HOST': "invalid_hostname.com",
|
||||
}
|
||||
self.assertEqual(request.get_host(), "invalid_hostname.com")
|
||||
# Other hostnames raise a SuspiciousOperation.
|
||||
with self.assertRaises(SuspiciousOperation):
|
||||
request = HttpRequest()
|
||||
request.META = {'HTTP_HOST': 'example.com'}
|
||||
request.get_host()
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=[])
|
||||
def test_get_host_suggestion_of_allowed_host(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue