Skip to content

Commit e45f33f

Browse files
committed
Fix issue 2550848: HTML attachments should not be served as text/html
This adds whitelist of safe extensions based on analysis of all committed mime-types to bugs.python.org and issues.roun...org In future whitelist can be turned off with option 'render_unsafe_content' (like in Trac), but adding this new feature requires minor version bump.
1 parent a9d32b5 commit e45f33f

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

CHANGES.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@ Fixed:
120120
include the email addresses, depending on your installation you may
121121
want to further restrict this or add some attributes like ``address``
122122
and ``alternate_addresses``. (Ralf Schlatterbeck)
123-
- Security: Attached html files are not shipped as text/html by default,
124-
unless ``allow_html_file`` is specified in the configuration.
125-
Unfortunately some browsers want to be helpful and render other
126-
non-standard content types as html. We now change this to
127-
application/octet-stream whenever 'html' is contained in the string
128-
(case insensitive). Thanks to Kay Hayen for reporting and helping
129-
debug this. (Ralf Schlatterbeck)
130123
- Correctly recreate the database directory when re-initialising a tracker
131124
instance. (John Kristensen)
132125
- In case of an error, date fields would lose the calendar help, fixed.
@@ -140,6 +133,13 @@ Fixed:
140133
restore web presence for "Roundup�s Design Document" (anatoly techtonik)
141134
- Template jinja2: Updated URL to point to http://www.roundup-tracker.org/
142135
(Bernhard Reiter)
136+
- Security: Add mime-type whitelist for attachmens that can be safely
137+
rendered from Roundup without trigerring security bugs in browser
138+
plugins, XSS issues and spam. The option ``allow_html_file`` didn't
139+
provide protection for invalid content-type, in which case browser
140+
tried to guess the best one. Thanks to Kay Hayen for reporting and
141+
helping debug this. issue2550848 (Ralf Schlatterbeck, anatoly techtonik)
142+
143143

144144

145145
2013-07-06: 1.5.0

roundup/cgi/client.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,32 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
972972
raise Unauthorised(self._("You are not allowed to view "
973973
"this file."))
974974

975+
976+
# --- mime-type security
977+
# mime type detection is performed in cgi.form_parser
978+
979+
# everything not here is served as 'application/octet-stream'
980+
whitelist = [
981+
'text/plain',
982+
'text/x-csrc', # .c
983+
'text/x-chdr', # .h
984+
'text/x-patch', # .patch and .diff
985+
'text/x-python', # .py
986+
'text/xml',
987+
'text/csv',
988+
'text/css',
989+
'application/pdf',
990+
'image/gif',
991+
'image/jpeg',
992+
'image/png',
993+
'image/webp',
994+
'audio/ogg',
995+
'video/webm',
996+
]
997+
998+
if self.instance.config['WEB_ALLOW_HTML_FILE']:
999+
whitelist.append('text/html')
1000+
9751001
try:
9761002
mime_type = klass.get(nodeid, 'type')
9771003
except IndexError, e:
@@ -980,12 +1006,11 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
9801006
if not mime_type:
9811007
mime_type = 'text/plain'
9821008

983-
# if the mime_type is HTML-ish then make sure we're allowed to serve up
984-
# HTML-ish content
985-
if 'html' in str (mime_type).lower () :
986-
if not self.instance.config['WEB_ALLOW_HTML_FILE']:
987-
# do NOT serve the content up as HTML
988-
mime_type = 'application/octet-stream'
1009+
if mime_type not in whitelist:
1010+
mime_type = 'application/octet-stream'
1011+
1012+
# --/ mime-type security
1013+
9891014

9901015
# If this object is a file (i.e., an instance of FileClass),
9911016
# see if we can find it in the filesystem. If so, we may be

0 commit comments

Comments
 (0)