Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1abcf3a

Browse files
aaugustinapollo13
authored andcommitted
[1.6.x] Dropped fix_IE_for_vary/attach.
This is a security fix. Disclosure following shortly.
1 parent e05a622 commit 1abcf3a

File tree

4 files changed

+1
-103
lines changed

4 files changed

+1
-103
lines changed

django/core/handlers/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class BaseHandler(object):
2323
response_fixes = [
2424
http.fix_location_header,
2525
http.conditional_content_removal,
26-
http.fix_IE_for_attach,
27-
http.fix_IE_for_vary,
2826
]
2927

3028
def __init__(self):

django/http/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
HttpResponseRedirect, HttpResponseNotModified, HttpResponseBadRequest,
77
HttpResponseForbidden, HttpResponseNotFound, HttpResponseNotAllowed,
88
HttpResponseGone, HttpResponseServerError, Http404, BadHeaderError)
9-
from django.http.utils import (fix_location_header, conditional_content_removal,
10-
fix_IE_for_attach, fix_IE_for_vary)
9+
from django.http.utils import fix_location_header, conditional_content_removal

django/http/utils.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,58 +39,3 @@ def conditional_content_removal(request, response):
3939
else:
4040
response.content = b''
4141
return response
42-
43-
44-
def fix_IE_for_attach(request, response):
45-
"""
46-
This function will prevent Django from serving a Content-Disposition header
47-
while expecting the browser to cache it (only when the browser is IE). This
48-
leads to IE not allowing the client to download.
49-
"""
50-
useragent = request.META.get('HTTP_USER_AGENT', '').upper()
51-
if 'MSIE' not in useragent and 'CHROMEFRAME' not in useragent:
52-
return response
53-
54-
offending_headers = ('no-cache', 'no-store')
55-
if response.has_header('Content-Disposition'):
56-
try:
57-
del response['Pragma']
58-
except KeyError:
59-
pass
60-
if response.has_header('Cache-Control'):
61-
cache_control_values = [value.strip() for value in
62-
response['Cache-Control'].split(',')
63-
if value.strip().lower() not in offending_headers]
64-
65-
if not len(cache_control_values):
66-
del response['Cache-Control']
67-
else:
68-
response['Cache-Control'] = ', '.join(cache_control_values)
69-
70-
return response
71-
72-
73-
def fix_IE_for_vary(request, response):
74-
"""
75-
This function will fix the bug reported at
76-
http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global
77-
by clearing the Vary header whenever the mime-type is not safe
78-
enough for Internet Explorer to handle. Poor thing.
79-
"""
80-
useragent = request.META.get('HTTP_USER_AGENT', '').upper()
81-
if 'MSIE' not in useragent and 'CHROMEFRAME' not in useragent:
82-
return response
83-
84-
# These mime-types that are decreed "Vary-safe" for IE:
85-
safe_mime_types = ('text/html', 'text/plain', 'text/sgml')
86-
87-
# The first part of the Content-Type field will be the MIME type,
88-
# everything after ';', such as character-set, can be ignored.
89-
mime_type = response.get('Content-Type', '').partition(';')[0]
90-
if mime_type not in safe_mime_types:
91-
try:
92-
del response['Vary']
93-
except KeyError:
94-
pass
95-
96-
return response

tests/utils_tests/test_http.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -67,50 +67,6 @@ def test_urlencode(self):
6767
]
6868
self.assertTrue(result in acceptable_results)
6969

70-
def test_fix_IE_for_vary(self):
71-
"""
72-
Regression for #16632.
73-
74-
`fix_IE_for_vary` shouldn't crash when there's no Content-Type header.
75-
"""
76-
77-
# functions to generate responses
78-
def response_with_unsafe_content_type():
79-
r = HttpResponse(content_type="text/unsafe")
80-
r['Vary'] = 'Cookie'
81-
return r
82-
83-
def no_content_response_with_unsafe_content_type():
84-
# 'Content-Type' always defaulted, so delete it
85-
r = response_with_unsafe_content_type()
86-
del r['Content-Type']
87-
return r
88-
89-
# request with & without IE user agent
90-
rf = RequestFactory()
91-
request = rf.get('/')
92-
ie_request = rf.get('/', HTTP_USER_AGENT='MSIE')
93-
94-
# not IE, unsafe_content_type
95-
response = response_with_unsafe_content_type()
96-
utils.fix_IE_for_vary(request, response)
97-
self.assertTrue('Vary' in response)
98-
99-
# IE, unsafe_content_type
100-
response = response_with_unsafe_content_type()
101-
utils.fix_IE_for_vary(ie_request, response)
102-
self.assertFalse('Vary' in response)
103-
104-
# not IE, no_content
105-
response = no_content_response_with_unsafe_content_type()
106-
utils.fix_IE_for_vary(request, response)
107-
self.assertTrue('Vary' in response)
108-
109-
# IE, no_content
110-
response = no_content_response_with_unsafe_content_type()
111-
utils.fix_IE_for_vary(ie_request, response)
112-
self.assertFalse('Vary' in response)
113-
11470
def test_base36(self):
11571
# reciprocity works
11672
for n in [0, 1, 1000, 1000000]:

0 commit comments

Comments
 (0)