Skip to content

Commit 8fc8521

Browse files
author
Richard Jones
committed
backport fix for cross-site-scripting from HEAD
1 parent 118d051 commit 8fc8521

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

roundup/cgi/client.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# $Id: client.py,v 1.65.2.6 2003-03-19 02:50:12 richard Exp $
1+
<<<<<<< client.py
2+
# $Id: client.py,v 1.65.2.7 2003-06-10 22:59:22 richard Exp $
3+
=======
4+
# $Id: client.py,v 1.65.2.7 2003-06-10 22:59:22 richard Exp $
5+
>>>>>>> 1.119
26

37
__doc__ = """
48
WWW request handler (also used in the stand-alone server).
@@ -47,6 +51,13 @@ def initialiseSecurity(security):
4751
description="User may manipulate user Roles through the web")
4852
security.addPermissionToRole('Admin', p)
4953

54+
def clean_message(match, ok={'a':1,'i':1,'b':1,'br':1}):
55+
''' Strip all non <a>,<i>,<b> and <br> tags from a string
56+
'''
57+
if ok.has_key(match.group(2)):
58+
return match.group(1)
59+
return '&lt;%s&gt;'%match.group(2)
60+
5061
class Client:
5162
''' Instantiate to handle one CGI request.
5263
@@ -249,7 +260,8 @@ def determine_user(self):
249260
# reopen the database as the correct user
250261
self.opendb(self.user)
251262

252-
def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')):
263+
def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)'),
264+
mc=re.compile(r'(</?(.*?)>)')):
253265
''' Determine the context of this page from the URL:
254266
255267
The URL path after the instance identifier is examined. The path
@@ -331,9 +343,11 @@ def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')):
331343

332344
# see if we were passed in a message
333345
if self.form.has_key(':ok_message'):
334-
self.ok_message.append(self.form[':ok_message'].value)
346+
msg = mc.sub(clean_message, self.form[':ok_message'].value)
347+
self.ok_message.append(msg)
335348
if self.form.has_key(':error_message'):
336-
self.error_message.append(self.form[':error_message'].value)
349+
msg = mc.sub(clean_message, self.form[':error_message'].value)
350+
self.error_message.append(msg)
337351

338352
def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
339353
''' Serve the file from the content property of the designated item.

0 commit comments

Comments
 (0)