summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ab20697)
raw | patch | inline | side by side (parent: ab20697)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 24 Jun 2003 03:30:40 +0000 (03:30 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 24 Jun 2003 03:30:40 +0000 (03:30 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1752 57a73879-2fb5-44c3-a270-3262357dd7e2
CHANGES.txt | patch | blob | history | |
roundup/cgi/client.py | patch | blob | history | |
test/test_cgi.py | patch | blob | history |
diff --git a/CHANGES.txt b/CHANGES.txt
index 30690e3b2954c555dbab1287fb83af8d32ba9e45..247b7e4218e0510d9eba63151ade45659a6dad4b 100644 (file)
--- a/CHANGES.txt
+++ b/CHANGES.txt
- handle deprecation of FCNTL in python2.2+ (sf bug 756756)
- handle missing Subject: line (sf bug 755331)
- handle New User creation (sf bug 754510)
+- fix hackish message escaping (sf bug 757128)
2003-06-10 0.6.0b3
diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py
index 03aa4ab44875d8ee0b671dc9c9407c78adcccdb9..1394120c8ac535cd30eab7a8c0024cd2c93a6bc0 100644 (file)
--- a/roundup/cgi/client.py
+++ b/roundup/cgi/client.py
-# $Id: client.py,v 1.119 2003-06-10 22:55:30 richard Exp $
+# $Id: client.py,v 1.120 2003-06-24 03:30:30 richard Exp $
__doc__ = """
WWW request handler (also used in the stand-alone server).
description="User may manipulate user Roles through the web")
security.addPermissionToRole('Admin', p)
-def clean_message(match, ok={'a':1,'i':1,'b':1,'br':1}):
+# used to clean messages passed through CGI variables - HTML-escape any tag
+# that isn't <a href="">, <i>, <b> and <br> (including XHTML variants) so
+# that people can't pass through nasties like <script>, <iframe>, ...
+CLEAN_MESSAGE_RE = r'(<(/?(.*?)(\s*href="[^"]")?\s*/?)>)'
+def clean_message(message, mc=re.compile(CLEAN_MESSAGE_RE, re.I)):
+ return mc.sub(clean_message_callback, message)
+def clean_message_callback(match, ok={'a':1,'i':1,'b':1,'br':1}):
''' Strip all non <a>,<i>,<b> and <br> tags from a string
'''
- if ok.has_key(match.group(2)):
+ if ok.has_key(match.group(3).lower()):
return match.group(1)
return '<%s>'%match.group(2)
# reopen the database as the correct user
self.opendb(self.user)
- def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)'),
- mc=re.compile(r'(</?(.*?)>)')):
+ def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')):
''' Determine the context of this page from the URL:
The URL path after the instance identifier is examined. The path
template_override = self.form[key].value
elif self.FV_OK_MESSAGE.match(key):
ok_message = self.form[key].value
- ok_message = mc.sub(clean_message, ok_message)
+ ok_message = clean_message(ok_message)
elif self.FV_ERROR_MESSAGE.match(key):
error_message = self.form[key].value
- error_message = mc.sub(clean_message, error_message)
+ error_message = clean_message(error_message)
# determine the classname and possibly nodeid
path = self.path.split('/')
diff --git a/test/test_cgi.py b/test/test_cgi.py
index 92e0a58793a637c232ad1410e764be14aefde5bc..be73124e9e90a5d8e9ee05f98d5671826bf4cc3a 100644 (file)
--- a/test/test_cgi.py
+++ b/test/test_cgi.py
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
-# $Id: test_cgi.py,v 1.16 2003-05-09 01:47:50 richard Exp $
+# $Id: test_cgi.py,v 1.17 2003-06-24 03:30:40 richard Exp $
import unittest, os, shutil, errno, sys, difflib, cgi, re
TRACKER_NAME = 'testing testing'
TRACKER_WEB = 'http://testing.testing/'
+cm = client.clean_message
+class MessageTestCase(unittest.TestCase):
+ def testCleanMessageOK(self):
+ self.assertEqual(cm('<br>x<br />'), '<br>x<br />')
+ self.assertEqual(cm('<i>x</i>'), '<i>x</i>')
+ self.assertEqual(cm('<b>x</b>'), '<b>x</b>')
+ self.assertEqual(cm('<a href="y">x</a>'),
+ '<a href="y">x</a>')
+ self.assertEqual(cm('<BR>x<BR />'), '<BR>x<BR />')
+ self.assertEqual(cm('<I>x</I>'), '<I>x</I>')
+ self.assertEqual(cm('<B>x</B>'), '<B>x</B>')
+ self.assertEqual(cm('<A HREF="y">x</A>'),
+ '<A HREF="y">x</A>')
+
+ def testCleanMessageBAD(self):
+ self.assertEqual(cm('<script>x</script>'),
+ '<script>x</script>')
+ self.assertEqual(cm('<iframe>x</iframe>'),
+ '<iframe>x</iframe>')
+
class FormTestCase(unittest.TestCase):
def setUp(self):
self.dirname = '_test_cgi_form'
[('issue', None, 'files', [('file', '-1')])]))
def suite():
- l = [unittest.makeSuite(FormTestCase),
+ l = [
+ unittest.makeSuite(FormTestCase),
+ unittest.makeSuite(MessageTestCase),
]
return unittest.TestSuite(l)