Skip to content

Commit 5fd513e

Browse files
committed
Added a logging filter to filter out the 'Invalid HTTP_HOST' emails.
- Legacy-Id: 7263
1 parent ad11947 commit 5fd513e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

ietf/settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@
105105
LOGGING = DEFAULT_LOGGING.copy()
106106
LOGGING['handlers']['mail_admins']['include_html'] = True
107107

108+
# Filter out "Invalid HTTP_HOST" emails
109+
# Based on http://www.tiwoc.de/blog/2013/03/django-prevent-email-notification-on-suspiciousoperation/
110+
from django.core.exceptions import SuspiciousOperation
111+
def skip_suspicious_operations(record):
112+
if record.exc_info:
113+
exc_value = record.exc_info[1]
114+
if isinstance(exc_value, SuspiciousOperation):
115+
return False
116+
return True
117+
LOGGING['filters']['skip_suspicious_operations'] = {
118+
'()': 'django.utils.log.CallbackFilter',
119+
'callback': skip_suspicious_operations,
120+
}
121+
LOGGING['handlers']['mail_admins']['filters'] += [ 'skip_suspicious_operations' ]
122+
108123
SESSION_COOKIE_AGE = 43200 # 12 hours
109124
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
110125
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

0 commit comments

Comments
 (0)