comparison test/test_cgi.py @ 4851:24b8011cd2dc

Fix XSS in issue2550817 Note that the code that triggers that particular bug is no longer in roundup core. But the change to the templates we suggest is a *lot* safer as it always escapes the error and ok messages now. If you are upgrading: you *MUST* read doc/upgrading.txt and do the necessary changes to your templates, the escaping now happens in the template and not in the roundup code. So if you don't make the necessary changes *you are vulnerable*.
author Ralf Schlatterbeck <rsc@runtux.com>
date Fri, 20 Dec 2013 18:24:10 +0100
parents dad18ee491a9
children ca692423e401
comparison
equal deleted inserted replaced
4850:6998ad77841e 4851:24b8011cd2dc
41 return form 41 return form
42 42
43 cm = client.clean_message 43 cm = client.clean_message
44 class MessageTestCase(unittest.TestCase): 44 class MessageTestCase(unittest.TestCase):
45 # Note: We used to allow some html tags in error message. Now *only* 45 # Note: We used to allow some html tags in error message. Now *only*
46 # newlines are allowed which are translated to <br />. 46 # newlines are allowed and messages are split at newlines.
47 # All other tags are escaped. 47 # Note that tags are no longer escaped, see doc/upgrading.txt for
48 # the changes needed in the templates (Migrating from 1.5.0 to 1.5.1)
48 def testCleanMessageOK(self): 49 def testCleanMessageOK(self):
49 self.assertEqual(cm('a\nb'), 'a<br />\nb') 50 self.assertEqual(cm('a'), ['a'])
50 self.assertEqual(cm('a\nb\nc\n'), 'a<br />\nb<br />\nc<br />\n') 51 self.assertEqual(cm('a\nb'), ['a','b'])
51 52 self.assertEqual(cm('a\nb\nc\n'), ['a','b','c',''])
52 def testCleanMessageBAD(self):
53 self.assertEqual(cm('<script>x</script>'),
54 '&lt;script&gt;x&lt;/script&gt;')
55 self.assertEqual(cm('<iframe>x</iframe>'),
56 '&lt;iframe&gt;x&lt;/iframe&gt;')
57 self.assertEqual(cm('<<script >>alert(42);5<</script >>'),
58 '&lt;&lt;script &gt;&gt;alert(42);5&lt;&lt;/script &gt;&gt;')
59 self.assertEqual(cm('<a href="y">x</a>'),
60 '&lt;a href="y"&gt;x&lt;/a&gt;')
61 self.assertEqual(cm('<A HREF="y">x</A>'),
62 '&lt;A HREF="y"&gt;x&lt;/A&gt;')
63 self.assertEqual(cm('<br>x<br />'), '&lt;br&gt;x&lt;br /&gt;')
64 self.assertEqual(cm('<i>x</i>'), '&lt;i&gt;x&lt;/i&gt;')
65 self.assertEqual(cm('<b>x</b>'), '&lt;b&gt;x&lt;/b&gt;')
66 self.assertEqual(cm('<BR>x<BR />'), '&lt;BR&gt;x&lt;BR /&gt;')
67 self.assertEqual(cm('<I>x</I>'), '&lt;I&gt;x&lt;/I&gt;')
68 self.assertEqual(cm('<B>x</B>'), '&lt;B&gt;x&lt;/B&gt;')
69 53
70 class FormTestCase(unittest.TestCase): 54 class FormTestCase(unittest.TestCase):
71 def setUp(self): 55 def setUp(self):
72 self.dirname = '_test_cgi_form' 56 self.dirname = '_test_cgi_form'
73 # set up and open a tracker 57 # set up and open a tracker

Roundup Issue Tracker: http://roundup-tracker.org/