Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05bb0ef

Browse files
committed
Python: Align xml.etree.ElementTree modeling
I didn't find a good way to actually share the stuff, so we kinda just have 2 things that look very similar :|
1 parent 70b3eec commit 05bb0ef

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,15 @@ private module StdlibPrivate {
31533153
.getMember("ElementTree")
31543154
.getMember(["fromstring", "fromstringlist", "XML"])
31553155
.getReturn()
3156+
or
3157+
result =
3158+
API::moduleImport("xml")
3159+
.getMember("etree")
3160+
.getMember("ElementTree")
3161+
.getMember("XMLParser")
3162+
.getReturn()
3163+
.getMember("close")
3164+
.getReturn()
31563165
}
31573166

31583167
/**
@@ -3255,6 +3264,7 @@ private module StdlibPrivate {
32553264
* - `xml.etree.ElementTree.XMLID`
32563265
* - `xml.etree.ElementTree.parse`
32573266
* - `xml.etree.ElementTree.iterparse`
3267+
* - `parse` method on an `xml.etree.ElementTree.ElementTree` instance
32583268
*
32593269
* See
32603270
* - https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.fromstring
@@ -3272,6 +3282,8 @@ private module StdlibPrivate {
32723282
.getMember("ElementTree")
32733283
.getMember(["fromstring", "fromstringlist", "XML", "XMLID", "parse", "iterparse"])
32743284
.getACall()
3285+
or
3286+
this = elementTreeInstance().getMember("parse").getACall()
32753287
}
32763288

32773289
override DataFlow::Node getAnInput() {
@@ -3321,6 +3333,8 @@ private module StdlibPrivate {
33213333
.getMember("ElementTree")
33223334
.getMember(["parse", "iterparse"])
33233335
.getACall()
3336+
or
3337+
this = elementTreeInstance().getMember("parse").getACall()
33243338
// I considered whether we should try to reduce FPs from people passing file-like
33253339
// objects, which will not be a file system access (and couldn't cause a
33263340
// path-injection).

python/ql/test/library-tests/frameworks/stdlib/XPathExecution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
root.findtext(match, default=None, namespaces=ns) # $ getXPath=match
1111

1212
tree = ET.ElementTree()
13-
tree.parse("index.xhtml")
13+
tree.parse("index.xhtml") # $ decodeFormat=XML decodeInput="index.xhtml" decodeOutput=tree.parse(..) xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup' getAPathArgument="index.xhtml"
1414

1515
tree.find(match, namespaces=ns) # $ getXPath=match
1616
tree.findall(match, namespaces=ns) # $ getXPath=match
@@ -19,4 +19,4 @@
1919
parser = ET.XMLParser()
2020
parser.feed("<foo>bar</foo>") # $ decodeFormat=XML decodeInput="<foo>bar</foo>" xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup'
2121
tree = parser.close() # $ decodeOutput=parser.close()
22-
tree.find(match, namespaces=ns) # $ MISSING: getXPath=match
22+
tree.find(match, namespaces=ns) # $ getXPath=match

python/ql/test/library-tests/frameworks/stdlib/xml_etree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
xml.etree.ElementTree.iterparse(source=StringIO(x)) # $ decodeFormat=XML decodeInput=StringIO(..) xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup' decodeOutput=xml.etree.ElementTree.iterparse(..) getAPathArgument=StringIO(..)
2424

2525
tree = xml.etree.ElementTree.ElementTree()
26-
tree.parse("file.xml") # $ MISSING: decodeFormat=XML decodeInput="file.xml" xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup' decodeOutput=tree.parse(..) getAPathArgument="file.xml"
27-
tree.parse(source="file.xml") # $ MISSING: decodeFormat=XML decodeInput="file.xml" xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup' decodeOutput=tree.parse(..) getAPathArgument="file.xml"
26+
tree.parse("file.xml") # $ decodeFormat=XML decodeInput="file.xml" xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup' decodeOutput=tree.parse(..) getAPathArgument="file.xml"
27+
tree.parse(source="file.xml") # $ decodeFormat=XML decodeInput="file.xml" xmlVuln='Billion Laughs' xmlVuln='Quadratic Blowup' decodeOutput=tree.parse(..) getAPathArgument="file.xml"
2828

2929

3030
# With parsers (no options available to disable/enable security features)

0 commit comments

Comments
 (0)