Index: test/test_cgi.py =================================================================== --- test/test_cgi.py (revision 88880) +++ test/test_cgi.py (working copy) @@ -48,17 +48,23 @@ self.assertEqual(cm('x'), 'x') self.assertEqual(cm('x'), 'x') self.assertEqual(cm('x'), 'x') + self.assertEqual(cm('x'), 'x') + self.assertEqual(cm('x'), 'x') self.assertEqual(cm('x'), 'x') self.assertEqual(cm('x'), 'x') self.assertEqual(cm('x'), 'x') self.assertEqual(cm('x'), 'x') + self.assertEqual(cm('X'), 'X') + self.assertEqual(cm('X'), 'X') self.assertEqual(cm('x'), 'x') def testCleanMessageBAD(self): self.assertEqual(cm(''), '<script>x</script>') + self.assertEqual(cm('<>>alert(42);5<>'), + '<<script >>alert(42);5<</script >>') self.assertEqual(cm('x'), '<iframe>x</iframe>') Index: roundup/cgi/client.py =================================================================== --- roundup/cgi/client.py (revision 88880) +++ roundup/cgi/client.py (working copy) @@ -38,18 +38,15 @@ description="User may manipulate user Roles through the web") security.addPermissionToRole('Admin', p) -# used to clean messages passed through CGI variables - HTML-escape any tag -# that isn't , , and (including XHTML variants) so -# that people can't pass through nasties like >, , ... -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 ,, and tags from a string - """ - if match.group(3).lower() in ok: - return match.group(1) - return '<%s>'%match.group(2) +# used to clean messages passed through CGI variables - HTML-escape everything +# and then restore the allowed tags , , , , , +# so that people can't pass through nasties like >, , ... +# See also issue #2550724 +ALLOWED_TAGS_RE = re.compile(r'<(/?(?:em|strong|i|b)(?=>)|' + r'a\s+href="[^"]"(?=>)|/a|br\s*/?)>', re.I) +def clean_message(message): + cleaned = cgi.escape(message) + return ALLOWED_TAGS_RE.sub(r'<1円>', cleaned) error_message = ''""" An error has occurred AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル