Opened 8 years ago

Closed 8 years ago

#26669 closed Bug (worksforme)

UnicodeDecodeError with non-ASCII string in 'Content-Type' header

Reported by: karech Owned by: nobody
Component: HTTP handling Version: 1.8
Severity: Normal Keywords: UnicodeDecodeError request META CONTENT_TYPE Content-Type
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If someone sends POST request with headers containing non-ASCII value for 'Content-Type', then django raises UnicodeDecodeError.

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/lib/python2.7/site-packages/django/contrib/staticfiles/", line 63, in __call__
    return self.application(environ, start_response)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/", line 189, in __call__
    response = self.get_response(request)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/", line 218, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/usr/lib/python2.7/site-packages/django/core/handlers/", line 261, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/usr/lib/python2.7/site-packages/django/views/", line 97, in technical_500_response
    html = reporter.get_traceback_html()
  File "/usr/lib/python2.7/site-packages/django/views/", line 383, in get_traceback_html
    c = Context(self.get_traceback_data(), use_l10n=False)
  File "/usr/lib/python2.7/site-packages/django/views/", line 328, in get_traceback_data
    frames = self.get_traceback_frames()
  File "/usr/lib/python2.7/site-packages/django/views/", line 501, in get_traceback_frames
    'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
  File "/usr/lib/python2.7/site-packages/django/views/", line 234, in get_traceback_frame_variables
    cleansed[name] = self.cleanse_special_types(request, value)
  File "/usr/lib/python2.7/site-packages/django/views/", line 191, in cleanse_special_types
    value = self.get_request_repr(value)
  File "/usr/lib/python2.7/site-packages/django/views/", line 122, in get_request_repr
    return build_request_repr(request, POST_override=self.get_post_parameters(request))
  File "/usr/lib/python2.7/site-packages/django/views/", line 186, in get_post_parameters
    return request.POST
  File "/usr/lib/python2.7/site-packages/django/core/handlers/", line 137, in _get_post
  File "/usr/lib/python2.7/site-packages/django/http/", line 253, in _load_post_and_files
    if self.META.get('CONTENT_TYPE', '').startswith('multipart/form-data'):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

How reproduce:

import requests

url = ''
headers = {'Content-Type': b'\xf0'}, headers=headers)

Change History (1)

comment:1 by Tim Graham, 8 years ago

Resolution: worksforme
Status: newclosed

Perhaps there's something missing in the report but I can't reproduce a crash. Perhaps you could provide a test for Django's test suite instead?

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