Last active
February 5, 2020 08:19
-
-
Save rrafal/e176f7f0de255fc16fa4 to your computer and use it in GitHub Desktop.
Django logging filter for Invalid HTTP_HOST header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IgnoreHostError(logging.Filter): | |
def filter(self, record): | |
from django.core.exceptions import SuspiciousOperation | |
if record.name == 'django.security.DisallowedHost': | |
return False | |
if record.name == 'django.core.exceptions.DisallowedHost': | |
return False | |
if record.exc_info: | |
exc_value = record.exc_info[1] | |
if isinstance(exc_value, SuspiciousOperation): | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment