Skip to content

Commit c5f30d9

Browse files
committed
Create an extendable AdditionalTaintStep class in customizations
1 parent 85b5ef3 commit c5f30d9

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

python/ql/src/experimental/semmle/python/security/dataflow/XmlEntityInjection.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module XmlEntityInjection {
2222
}
2323

2424
override predicate isAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
25-
ioAdditionalTaintStep(nodeFrom, nodeTo)
25+
any(AdditionalTaintStep s).step(nodeFrom, nodeTo)
2626
}
2727
}
2828

python/ql/src/experimental/semmle/python/security/dataflow/XmlEntityInjectionCustomizations.qll

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ module XmlEntityInjection {
3131
*/
3232
abstract class SanitizerGuard extends DataFlow::BarrierGuard { }
3333

34+
/**
35+
* A unit class for adding additional taint steps.
36+
*
37+
* Extend this class to add additional taint steps that should apply to `XmlEntityInjection`
38+
* taint configuration.
39+
*/
40+
class AdditionalTaintStep extends Unit {
41+
/**
42+
* Holds if the step from `nodeFrom` to `nodeTo` should be considered a taint
43+
* step for `XmlEntityInjection` configuration.
44+
*/
45+
abstract predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo);
46+
}
47+
3448
/**
3549
* A data flow sink for XML parsing libraries.
3650
*
@@ -85,11 +99,16 @@ module XmlEntityInjection {
8599
*/
86100
class StringConstCompareAsSanitizerGuard extends SanitizerGuard, StringConstCompare { }
87101

88-
predicate ioAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
89-
exists(DataFlow::CallCfgNode ioCalls |
90-
ioCalls = API::moduleImport("io").getMember(["StringIO", "BytesIO"]).getACall() and
91-
nodeFrom = ioCalls.getArg(0) and
92-
nodeTo = ioCalls
93-
)
102+
/**
103+
* A taint step for `io`'s `StringIO` and `BytesIO` methods.
104+
*/
105+
class IoAdditionalTaintStep extends AdditionalTaintStep {
106+
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
107+
exists(DataFlow::CallCfgNode ioCalls |
108+
ioCalls = API::moduleImport("io").getMember(["StringIO", "BytesIO"]).getACall() and
109+
nodeFrom = ioCalls.getArg(0) and
110+
nodeTo = ioCalls
111+
)
112+
}
94113
}
95114
}

0 commit comments

Comments
 (0)