Skip to content

Commit f2f0873

Browse files
committed
Python: Use new API::CallNode for XML constant check
This also means that the detection of the values passed to these keyword arguments will no longer just be from a local scope, but can also be across function boundaries.
1 parent c784f15 commit f2f0873

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private module Lxml {
129129
*
130130
* See https://lxml.de/apidoc/lxml.etree.html?highlight=xmlparser#lxml.etree.XMLParser
131131
*/
132-
private class LxmlParser extends InstanceSource, DataFlow::CallCfgNode {
132+
private class LxmlParser extends InstanceSource, API::CallNode {
133133
LxmlParser() {
134134
this = API::moduleImport("lxml").getMember("etree").getMember("XMLParser").getACall()
135135
}
@@ -141,16 +141,17 @@ private module Lxml {
141141
// resolve_entities has default True
142142
not exists(this.getArgByName("resolve_entities"))
143143
or
144-
this.getArgByName("resolve_entities").getALocalSource().asExpr() = any(True t)
144+
this.getKeywordParameter("resolve_entities").getAValueReachingRhs().asExpr() = any(True t)
145145
)
146146
or
147147
(kind.isBillionLaughs() or kind.isQuadraticBlowup()) and
148-
this.getArgByName("huge_tree").getALocalSource().asExpr() = any(True t) and
149-
not this.getArgByName("resolve_entities").getALocalSource().asExpr() = any(False t)
148+
this.getKeywordParameter("huge_tree").getAValueReachingRhs().asExpr() = any(True t) and
149+
not this.getKeywordParameter("resolve_entities").getAValueReachingRhs().asExpr() =
150+
any(False t)
150151
or
151152
kind.isDtdRetrieval() and
152-
this.getArgByName("load_dtd").getALocalSource().asExpr() = any(True t) and
153-
this.getArgByName("no_network").getALocalSource().asExpr() = any(False t)
153+
this.getKeywordParameter("load_dtd").getAValueReachingRhs().asExpr() = any(True t) and
154+
this.getKeywordParameter("no_network").getAValueReachingRhs().asExpr() = any(False t)
154155
}
155156
}
156157

@@ -305,7 +306,7 @@ private module Lxml {
305306
* See
306307
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.iterparse
307308
*/
308-
private class LxmlIterparseCall extends DataFlow::CallCfgNode, XML::XmlParsing::Range,
309+
private class LxmlIterparseCall extends API::CallNode, XML::XmlParsing::Range,
309310
FileSystemAccess::Range {
310311
LxmlIterparseCall() {
311312
this = API::moduleImport("lxml").getMember("etree").getMember("iterparse").getACall()
@@ -318,11 +319,11 @@ private module Lxml {
318319
kind.isXxe()
319320
or
320321
(kind.isBillionLaughs() or kind.isQuadraticBlowup()) and
321-
this.getArgByName("huge_tree").getALocalSource().asExpr() = any(True t)
322+
this.getKeywordParameter("huge_tree").getAValueReachingRhs().asExpr() = any(True t)
322323
or
323324
kind.isDtdRetrieval() and
324-
this.getArgByName("load_dtd").getALocalSource().asExpr() = any(True t) and
325-
this.getArgByName("no_network").getALocalSource().asExpr() = any(False t)
325+
this.getKeywordParameter("load_dtd").getAValueReachingRhs().asExpr() = any(True t) and
326+
this.getKeywordParameter("no_network").getAValueReachingRhs().asExpr() = any(False t)
326327
}
327328

328329
override predicate mayExecuteInput() { none() }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private module Xmltodict {
2020
/**
2121
* A call to `xmltodict.parse`.
2222
*/
23-
private class XMLtoDictParsing extends DataFlow::CallCfgNode, XML::XmlParsing::Range {
23+
private class XMLtoDictParsing extends API::CallNode, XML::XmlParsing::Range {
2424
XMLtoDictParsing() { this = API::moduleImport("xmltodict").getMember("parse").getACall() }
2525

2626
override DataFlow::Node getAnInput() {
@@ -29,7 +29,7 @@ private module Xmltodict {
2929

3030
override predicate vulnerableTo(XML::XmlParsingVulnerabilityKind kind) {
3131
(kind.isBillionLaughs() or kind.isQuadraticBlowup()) and
32-
this.getArgByName("disable_entities").getALocalSource().asExpr() = any(False f)
32+
this.getKeywordParameter("disable_entities").getAValueReachingRhs().asExpr() = any(False f)
3333
}
3434

3535
override predicate mayExecuteInput() { none() }

0 commit comments

Comments
 (0)