File tree Expand file tree Collapse file tree 3 files changed +36
-64
lines changed
python/ql/test/experimental
library-tests/frameworks/XML
query-tests/Security/CWE-611 Expand file tree Collapse file tree 3 files changed +36
-64
lines changed Original file line number Diff line number Diff line change 1+ from io import StringIO
2+ import xml .etree .ElementTree
3+
4+ x = "some xml"
5+
6+ # Parsing in different ways
7+ xml .etree .ElementTree .fromstring (x ) # $ input=x vuln='Billion Laughs' vuln='Quadratic Blowup'
8+ xml .etree .ElementTree .fromstringlist (x ) # $ input=x vuln='Billion Laughs' vuln='Quadratic Blowup'
9+ xml .etree .ElementTree .XML (x ) # $ input=x vuln='Billion Laughs' vuln='Quadratic Blowup'
10+ xml .etree .ElementTree .parse (StringIO (x )) # $ input=StringIO(..) vuln='Billion Laughs' vuln='Quadratic Blowup'
11+
12+ # With parsers (no options available to disable/enable security features)
13+ parser = xml .etree .ElementTree .XMLParser ()
14+ xml .etree .ElementTree .fromstring (x , parser = parser ) # $ input=x vuln='Billion Laughs' vuln='Quadratic Blowup'
15+
16+ # note: it's technically possible to use the thing wrapper func `fromstring` with an
17+ # `lxml` parser, and thereby change what vulnerabilities you are exposed to.. but it
18+ # seems very unlikely that anyone would do this, so we have intentionally not added any
19+ # tests for this.
Original file line number Diff line number Diff line change @@ -250,6 +250,23 @@ def test_ok_xml():
250250 assert root .tag == "test"
251251 assert root .text == "hello world"
252252
253+ @staticmethod
254+ def test_ok_xml_sax_parser ():
255+ # you _can_ pass a SAX parser to xml.etree... but it doesn't give you the output :|
256+ parser = xml .sax .make_parser ()
257+ root = xml .etree .ElementTree .fromstring (ok_xml , parser = parser )
258+ assert root == None
259+
260+ @staticmethod
261+ def test_ok_xml_lxml_parser ():
262+ # this is technically possible, since parsers follow the same API, and the
263+ # `fromstring` function is just a thin wrapper... seems very unlikely that
264+ # anyone would do this though :|
265+ parser = lxml .etree .XMLParser ()
266+ root = xml .etree .ElementTree .fromstring (ok_xml , parser = parser )
267+ assert root .tag == "test"
268+ assert root .text == "hello world"
269+
253270 @staticmethod
254271 def test_xxe_not_possible ():
255272 parser = xml .etree .ElementTree .XMLParser ()
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments