Opened 8 years ago

Closed 8 years ago

#27853 closed Bug (duplicate)

When AdminEmailHandler is configured with include_html, DisallowedHost causes a 500 instead of a 400

Reported by: Douglas Thrift Owned by: nobody
Component: Error reporting Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It looks like when AdminEmailHandler is configured with include_html a DisallowedHost causes a 500 instead of a 400 because it is trying to render the HTML error page for that to include in the email, but trying to render that HTML is triggering its own DisallowedHost because it thinks it is being requested by the same disallowed host rather than ignoring it since it is rendering for an email.

Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
    'request': request
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1193, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1286, in _log
    self.handle(record)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1296, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 759, in handle
    self.emit(record)
  File "/usr/local/lib/python2.7/site-packages/django/utils/log.py", line 128, in emit
    html_message = reporter.get_traceback_html() if self.include_html else None
  File "/usr/local/lib/python2.7/site-packages/django/views/debug.py", line 384, in get_traceback_html
    return t.render(c)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 210, in render
    return self._render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 202, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 905, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 329, in render
    return nodelist.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 905, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/debug.py", line 89, in render
    output = self.filter_expression.resolve(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 648, in resolve
    obj = self.var.resolve(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 789, in resolve
    value = self._resolve_lookup(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 849, in _resolve_lookup
    current = current()
  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", line 152, in build_absolute_uri
    host=self.get_host(),
  File "/usr/local/lib/python2.7/site-packages/django/http/request.py", line 102, in get_host
    raise DisallowedHost(msg)
DisallowedHost: Invalid HTTP_HOST header: 'localhost:8000'. You may need to add u'localhost' to ALLOWED_HOSTS.
[17/Feb/2017 06:48:12] "GET / HTTP/1.1" 500 59

Change History (1)

comment:1 by Tim Graham, 8 years ago

Component: Core (Mail)Error reporting
Resolution: duplicate
Status: newclosed

Duplicate of #25099 (see ticket:25099#comment:9). It's fixed in Django 1.9.

Note: See TracTickets for help on using tickets.
Back to Top