コード例 #1
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_remove_script_elem(self):
     markup = Markup('<script>alert("Foo")</script>')
     self.assertEquals('', markup.sanitize())
     markup = Markup('<SCRIPT SRC="http://example.com/"></SCRIPT>')
     self.assertEquals('', markup.sanitize())
     markup = Markup('<SCR\0IPT>alert("foo")</SCR\0IPT>')
     self.assertRaises(HTMLParseError, markup.sanitize)
     markup = Markup('<SCRIPT&XYZ SRC="http://example.com/"></SCRIPT>')
     self.assertRaises(HTMLParseError, markup.sanitize)
コード例 #2
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_remove_script_elem(self):
     markup = Markup('<script>alert("Foo")</script>')
     self.assertEquals('', markup.sanitize())
     markup = Markup('<SCRIPT SRC="http://example.com/"></SCRIPT>')
     self.assertEquals('', markup.sanitize())
     markup = Markup('<SCR\0IPT>alert("foo")</SCR\0IPT>')
     self.assertRaises(HTMLParseError, markup.sanitize)
     markup = Markup('<SCRIPT&XYZ SRC="http://example.com/"></SCRIPT>')
     self.assertRaises(HTMLParseError, markup.sanitize)
コード例 #3
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_remove_style_scripts(self):
     # Inline style with url() using javascript: scheme
     markup = Markup('<DIV STYLE=\'background: url(javascript:alert("foo"))\'>')
     self.assertEquals('<div>', markup.sanitize())
     # Inline style with url() using javascript: scheme, using control char
     markup = Markup('<DIV STYLE=\'background: url(&#1;javascript:alert("foo"))\'>')
     self.assertEquals('<div>', markup.sanitize())
     # Inline style with url() using javascript: scheme, in quotes
     markup = Markup('<DIV STYLE=\'background: url("javascript:alert(foo)")\'>')
     self.assertEquals('<div>', markup.sanitize())
     # IE expressions in CSS not allowed
     markup = Markup('<DIV STYLE=\'width: expression(alert("foo"));\'>')
     self.assertEquals('<div>', markup.sanitize())
     markup = Markup('<DIV STYLE=\'background: url(javascript:alert("foo"));'
                                  'color: #fff\'>')
     self.assertEquals('<div style="color: #fff">', markup.sanitize())
コード例 #4
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_remove_src_javascript(self):
     markup = Markup('<img src=\'javascript:alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Case-insensitive protocol matching
     markup = Markup('<IMG SRC=\'JaVaScRiPt:alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Grave accents (not parsed)
     markup = Markup('<IMG SRC=`javascript:alert("RSnake says, \'foo\'")`>')
     self.assertRaises(HTMLParseError, markup.sanitize)
     # Protocol encoded using UTF-8 numeric entities
     markup = Markup(
         '<IMG SRC=\'&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;'
         '&#112;&#116;&#58;alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Protocol encoded using UTF-8 numeric entities without a semicolon
     # (which is allowed because the max number of digits is used)
     markup = Markup(
         '<IMG SRC=\'&#0000106&#0000097&#0000118&#0000097'
         '&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116'
         '&#0000058alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Protocol encoded using UTF-8 numeric hex entities without a semicolon
     # (which is allowed because the max number of digits is used)
     markup = Markup('<IMG SRC=\'&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69'
                     '&#x70&#x74&#x3A;alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Embedded tab character in protocol
     markup = Markup('<IMG SRC=\'jav\tascript:alert("foo");\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Embedded tab character in protocol, but encoded this time
     markup = Markup('<IMG SRC=\'jav&#x09;ascript:alert("foo");\'>')
     self.assertEquals('<img />', markup.sanitize())
コード例 #5
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_remove_src_javascript(self):
     markup = Markup('<img src=\'javascript:alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Case-insensitive protocol matching
     markup = Markup('<IMG SRC=\'JaVaScRiPt:alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Grave accents (not parsed)
     markup = Markup('<IMG SRC=`javascript:alert("RSnake says, \'foo\'")`>')
     self.assertRaises(HTMLParseError, markup.sanitize)
     # Protocol encoded using UTF-8 numeric entities
     markup = Markup('<IMG SRC=\'&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;'
                     '&#112;&#116;&#58;alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Protocol encoded using UTF-8 numeric entities without a semicolon
     # (which is allowed because the max number of digits is used)
     markup = Markup('<IMG SRC=\'&#0000106&#0000097&#0000118&#0000097'
                     '&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116'
                     '&#0000058alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Protocol encoded using UTF-8 numeric hex entities without a semicolon
     # (which is allowed because the max number of digits is used)
     markup = Markup('<IMG SRC=\'&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69'
                     '&#x70&#x74&#x3A;alert("foo")\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Embedded tab character in protocol
     markup = Markup('<IMG SRC=\'jav\tascript:alert("foo");\'>')
     self.assertEquals('<img />', markup.sanitize())
     # Embedded tab character in protocol, but encoded this time
     markup = Markup('<IMG SRC=\'jav&#x09;ascript:alert("foo");\'>')
     self.assertEquals('<img />', markup.sanitize())
コード例 #6
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_remove_style_scripts(self):
     # Inline style with url() using javascript: scheme
     markup = Markup(
         '<DIV STYLE=\'background: url(javascript:alert("foo"))\'>')
     self.assertEquals('<div>', markup.sanitize())
     # Inline style with url() using javascript: scheme, using control char
     markup = Markup(
         '<DIV STYLE=\'background: url(&#1;javascript:alert("foo"))\'>')
     self.assertEquals('<div>', markup.sanitize())
     # Inline style with url() using javascript: scheme, in quotes
     markup = Markup(
         '<DIV STYLE=\'background: url("javascript:alert(foo)")\'>')
     self.assertEquals('<div>', markup.sanitize())
     # IE expressions in CSS not allowed
     markup = Markup('<DIV STYLE=\'width: expression(alert("foo"));\'>')
     self.assertEquals('<div>', markup.sanitize())
     markup = Markup(
         '<DIV STYLE=\'background: url(javascript:alert("foo"));'
         'color: #fff\'>')
     self.assertEquals('<div style="color: #fff">', markup.sanitize())
コード例 #7
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_unchanged(self):
     markup = Markup('<a href="#">fo<br />o</a>')
     self.assertEquals('<a href="#">fo<br />o</a>', markup.sanitize())
コード例 #8
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_remove_onclick_attr(self):
     markup = Markup('<div onclick=\'alert("foo")\' />')
     self.assertEquals('<div></div>', markup.sanitize())
コード例 #9
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_invalid_entity(self):
     markup = Markup('&junk;')
     self.assertEquals('&amp;junk;', markup.sanitize())
コード例 #10
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_escape_attr(self):
     markup = Markup('<div title="&lt;foo&gt;"></div>')
     self.assertEquals('<div title="&lt;foo&gt;"></div>', markup.sanitize())
コード例 #11
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_entityref_text(self):
     markup = Markup('<a href="#">fo&ouml;</a>')
     self.assertEquals(u'<a href="#">foö</a>', markup.sanitize())
コード例 #12
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_escape_text(self):
     markup = Markup('<a href="#">fo&amp;</a>')
     self.assertEquals('<a href="#">fo&amp;</a>', markup.sanitize())
     markup = Markup('<a href="#">&lt;foo&gt;</a>')
     self.assertEquals('<a href="#">&lt;foo&gt;</a>', markup.sanitize())
コード例 #13
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_unchanged(self):
     markup = Markup('<a href="#">fo<br />o</a>')
     self.assertEquals('<a href="#">fo<br />o</a>', markup.sanitize())
コード例 #14
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_remove_onclick_attr(self):
     markup = Markup('<div onclick=\'alert("foo")\' />')
     self.assertEquals('<div></div>', markup.sanitize())
コード例 #15
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_escape_text(self):
     markup = Markup('<a href="#">fo&amp;</a>')
     self.assertEquals('<a href="#">fo&amp;</a>', markup.sanitize())
     markup = Markup('<a href="#">&lt;foo&gt;</a>')
     self.assertEquals('<a href="#">&lt;foo&gt;</a>', markup.sanitize())
コード例 #16
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_escape_attr(self):
     markup = Markup('<div title="&lt;foo&gt;"></div>')
     self.assertEquals('<div title="&lt;foo&gt;"></div>', markup.sanitize())
コード例 #17
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_entityref_text(self):
     markup = Markup('<a href="#">fo&ouml;</a>')
     self.assertEquals(u'<a href="#">foö</a>', markup.sanitize())
コード例 #18
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_invalid_entity(self):
     markup = Markup('&junk;')
     self.assertEquals('&amp;junk;', markup.sanitize())
コード例 #19
0
ファイル: html.py プロジェクト: pombredanne/trachacks
 def test_sanitize_close_empty_tag(self):
     markup = Markup('<a href="#">fo<br>o</a>')
     self.assertEquals('<a href="#">fo<br />o</a>', markup.sanitize())
コード例 #20
0
ファイル: html.py プロジェクト: cyphactor/lifecyclemanager
 def test_sanitize_close_empty_tag(self):
     markup = Markup('<a href="#">fo<br>o</a>')
     self.assertEquals('<a href="#">fo<br />o</a>', markup.sanitize())