|
1 | | -# $Id: client.py,v 1.65.2.9 2003-06-19 23:02:32 richard Exp $ |
| 1 | +# $Id: client.py,v 1.65.2.10 2003-06-24 03:33:56 richard Exp $ |
2 | 2 |
|
3 | 3 | __doc__ = """ |
4 | 4 | WWW request handler (also used in the stand-alone server). |
@@ -47,10 +47,16 @@ def initialiseSecurity(security): |
47 | 47 | description="User may manipulate user Roles through the web") |
48 | 48 | security.addPermissionToRole('Admin', p) |
49 | 49 |
|
50 | | -def clean_message(match, ok={'a':1,'i':1,'b':1,'br':1}): |
| 50 | +# used to clean messages passed through CGI variables - HTML-escape any tag |
| 51 | +# that isn't <a href="">, <i>, <b> and <br> (including XHTML variants) so |
| 52 | +# that people can't pass through nasties like <script>, <iframe>, ... |
| 53 | +CLEAN_MESSAGE_RE = r'(<(/?(.*?)(\s*href="[^"]")?\s*/?)>)' |
| 54 | +def clean_message(message, mc=re.compile(CLEAN_MESSAGE_RE, re.I)): |
| 55 | + return mc.sub(clean_message_callback, message) |
| 56 | +def clean_message_callback(match, ok={'a':1,'i':1,'b':1,'br':1}): |
51 | 57 | ''' Strip all non <a>,<i>,<b> and <br> tags from a string |
52 | 58 | ''' |
53 | | - if ok.has_key(match.group(2)): |
| 59 | + if ok.has_key(match.group(3).lower()): |
54 | 60 | return match.group(1) |
55 | 61 | return '<%s>'%match.group(2) |
56 | 62 |
|
@@ -256,8 +262,7 @@ def determine_user(self): |
256 | 262 | # reopen the database as the correct user |
257 | 263 | self.opendb(self.user) |
258 | 264 |
|
259 | | - def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)'), |
260 | | - mc=re.compile(r'(</?(.*?)>)')): |
| 265 | + def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')): |
261 | 266 | ''' Determine the context of this page from the URL: |
262 | 267 |
|
263 | 268 | The URL path after the instance identifier is examined. The path |
@@ -339,10 +344,10 @@ def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)'), |
339 | 344 |
|
340 | 345 | # see if we were passed in a message |
341 | 346 | if self.form.has_key(':ok_message'): |
342 | | - msg = mc.sub(clean_message, self.form[':ok_message'].value) |
| 347 | + msg = clean_message(self.form[':ok_message'].value) |
343 | 348 | self.ok_message.append(msg) |
344 | 349 | if self.form.has_key(':error_message'): |
345 | | - msg = mc.sub(clean_message, self.form[':error_message'].value) |
| 350 | + msg = clean_message(self.form[':error_message'].value) |
346 | 351 | self.error_message.append(msg) |
347 | 352 |
|
348 | 353 | def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')): |
|
0 commit comments