Skip to content

Commit 1f814a9

Browse files
committed
[1.2.X] Fixed security issue in AdminFileWidget. Disclosure and release forthcoming.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15471 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 1945664 commit 1f814a9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

django/contrib/admin/widgets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def render(self, name, value, attrs=None):
9696
output = []
9797
if value and hasattr(value, "url"):
9898
output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \
99-
(_('Currently:'), value.url, value, _('Change:')))
99+
(_('Currently:'), escape(value.url), escape(value), _('Change:')))
100100
output.append(super(AdminFileWidget, self).render(name, value, attrs))
101101
return mark_safe(u''.join(output))
102102

tests/regressiontests/admin_widgets/tests.py

+16
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ def test_render(self):
239239
'<input type="file" name="test" />',
240240
)
241241

242+
def test_render_escapes_html(self):
243+
class StrangeFieldFile(object):
244+
url = "something?chapter=1&sect=2&copy=3&lang=en"
245+
246+
def __unicode__(self):
247+
return u'''something<div onclick="alert('oops')">.jpg'''
248+
249+
widget = AdminFileWidget()
250+
field = StrangeFieldFile()
251+
output = widget.render('myfile', field)
252+
self.assertFalse(field.url in output)
253+
self.assertTrue(u'href="something?chapter=1&amp;sect=2&amp;copy=3&amp;lang=en"' in output)
254+
self.assertFalse(unicode(field) in output)
255+
self.assertTrue(u'something&lt;div onclick=&quot;alert(&#39;oops&#39;)&quot;&gt;.jpg' in output)
256+
257+
242258

243259
class ForeignKeyRawIdWidgetTest(DjangoTestCase):
244260
def test_render(self):

0 commit comments

Comments
 (0)