|
1 | | -# $Id: client.py,v 1.119 2003-06-10 22:55:30 richard Exp $ |
| 1 | +# $Id: client.py,v 1.120 2003-06-24 03:30:30 richard Exp $ |
2 | 2 |
|
3 | 3 | __doc__ = """ |
4 | 4 | WWW request handler (also used in the stand-alone server). |
@@ -68,10 +68,16 @@ def initialiseSecurity(security): |
68 | 68 | description="User may manipulate user Roles through the web") |
69 | 69 | security.addPermissionToRole('Admin', p) |
70 | 70 |
|
71 | | -def clean_message(match, ok={'a':1,'i':1,'b':1,'br':1}): |
| 71 | +# used to clean messages passed through CGI variables - HTML-escape any tag |
| 72 | +# that isn't <a href="">, <i>, <b> and <br> (including XHTML variants) so |
| 73 | +# that people can't pass through nasties like <script>, <iframe>, ... |
| 74 | +CLEAN_MESSAGE_RE = r'(<(/?(.*?)(\s*href="[^"]")?\s*/?)>)' |
| 75 | +def clean_message(message, mc=re.compile(CLEAN_MESSAGE_RE, re.I)): |
| 76 | + return mc.sub(clean_message_callback, message) |
| 77 | +def clean_message_callback(match, ok={'a':1,'i':1,'b':1,'br':1}): |
72 | 78 | ''' Strip all non <a>,<i>,<b> and <br> tags from a string |
73 | 79 | ''' |
74 | | - if ok.has_key(match.group(2)): |
| 80 | + if ok.has_key(match.group(3).lower()): |
75 | 81 | return match.group(1) |
76 | 82 | return '<%s>'%match.group(2) |
77 | 83 |
|
@@ -348,8 +354,7 @@ def determine_user(self): |
348 | 354 | # reopen the database as the correct user |
349 | 355 | self.opendb(self.user) |
350 | 356 |
|
351 | | - def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)'), |
352 | | - mc=re.compile(r'(</?(.*?)>)')): |
| 357 | + def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')): |
353 | 358 | ''' Determine the context of this page from the URL: |
354 | 359 |
|
355 | 360 | The URL path after the instance identifier is examined. The path |
@@ -397,10 +402,10 @@ def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)'), |
397 | 402 | template_override = self.form[key].value |
398 | 403 | elif self.FV_OK_MESSAGE.match(key): |
399 | 404 | ok_message = self.form[key].value |
400 | | - ok_message = mc.sub(clean_message, ok_message) |
| 405 | + ok_message = clean_message(ok_message) |
401 | 406 | elif self.FV_ERROR_MESSAGE.match(key): |
402 | 407 | error_message = self.form[key].value |
403 | | - error_message = mc.sub(clean_message, error_message) |
| 408 | + error_message = clean_message(error_message) |
404 | 409 |
|
405 | 410 | # determine the classname and possibly nodeid |
406 | 411 | path = self.path.split('/') |
|
0 commit comments