티스토리 수익 글 보기

티스토리 수익 글 보기

[1.4.x] Dropped fix_IE_for_vary/attach. · django/django@28e2330 · GitHub
Skip to content
/ django Public

Commit 28e2330

Browse files
aaugustintimgraham
authored andcommitted
[1.4.x] Dropped fix_IE_for_vary/attach.
This is a security fix. Disclosure following shortly.
1 parent e181261 commit 28e2330

File tree

3 files changed

+0
100
lines changed

3 files changed

+0
100
lines changed

django/core/handlers/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class BaseHandler(object):
1414
response_fixes = [
1515
http.fix_location_header,
1616
http.conditional_content_removal,
17-
http.fix_IE_for_attach,
18-
http.fix_IE_for_vary,
1917
]
2018

2119
def __init__(self):

django/http/utils.py

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

tests/regressiontests/utils/http.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,50 +56,6 @@ def test_urlencode(self):
5656
]
5757
self.assertTrue(result in acceptable_results)
5858

59-
def test_fix_IE_for_vary(self):
60-
"""
61-
Regression for #16632.
62-
63-
`fix_IE_for_vary` shouldn't crash when there's no Content-Type header.
64-
"""
65-
66-
# functions to generate responses
67-
def response_with_unsafe_content_type():
68-
r = HttpResponse(content_type="text/unsafe")
69-
r['Vary'] = 'Cookie'
70-
return r
71-
72-
def no_content_response_with_unsafe_content_type():
73-
# 'Content-Type' always defaulted, so delete it
74-
r = response_with_unsafe_content_type()
75-
del r['Content-Type']
76-
return r
77-
78-
# request with & without IE user agent
79-
rf = RequestFactory()
80-
request = rf.get('/')
81-
ie_request = rf.get('/', HTTP_USER_AGENT='MSIE')
82-
83-
# not IE, unsafe_content_type
84-
response = response_with_unsafe_content_type()
85-
utils.fix_IE_for_vary(request, response)
86-
self.assertTrue('Vary' in response)
87-
88-
# IE, unsafe_content_type
89-
response = response_with_unsafe_content_type()
90-
utils.fix_IE_for_vary(ie_request, response)
91-
self.assertFalse('Vary' in response)
92-
93-
# not IE, no_content
94-
response = no_content_response_with_unsafe_content_type()
95-
utils.fix_IE_for_vary(request, response)
96-
self.assertTrue('Vary' in response)
97-
98-
# IE, no_content
99-
response = no_content_response_with_unsafe_content_type()
100-
utils.fix_IE_for_vary(ie_request, response)
101-
self.assertFalse('Vary' in response)
102-
10359
def test_base36(self):
10460
# reciprocity works
10561
for n in [0, 1, 1000, 1000000, sys.maxint]:

0 commit comments

Comments
 (0)