#27853: When AdminEmailHandler is configured with include_html, DisallowedHost
causes a 500 instead of a 400
------------------------------------------+------------------------
               Reporter:  Douglas Thrift  |          Owner:  nobody
                   Type:  Bug             |         Status:  new
              Component:  Core (Mail)     |        Version:  1.8
               Severity:  Normal          |       Keywords:
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+------------------------
 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
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27853>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.37e638bbe57c3df05e42dbffba9ba3ca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to