Skip to content

Commit 2c41270

Browse files
committed
Python: Move experimental CsvInjection to new dataflow API
1 parent ace1e23 commit 2c41270

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

python/ql/src/experimental/Security/CWE-1236/CsvInjection.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
*/
1212

1313
import python
14-
import DataFlow::PathGraph
14+
import CsvInjectionFlow::PathGraph
1515
import semmle.python.dataflow.new.DataFlow
1616
import experimental.semmle.python.security.injection.CsvInjection
1717

18-
from CsvInjectionFlowConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
19-
where config.hasFlowPath(source, sink)
18+
from CsvInjectionFlow::PathNode source, CsvInjectionFlow::PathNode sink
19+
where CsvInjectionFlow::flowPath(source, sink)
2020
select sink.getNode(), source, sink, "Csv injection might include code from $@.", source.getNode(),
2121
"this user input"

python/ql/src/experimental/semmle/python/security/injection/CsvInjection.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import semmle.python.dataflow.new.RemoteFlowSources
88
/**
99
* A taint-tracking configuration for tracking untrusted user input used in file read.
1010
*/
11-
class CsvInjectionFlowConfig extends TaintTracking::Configuration {
12-
CsvInjectionFlowConfig() { this = "CsvInjectionFlowConfig" }
11+
private module CsvInjectionConfig implements DataFlow::ConfigSig {
12+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
1313

14-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
14+
predicate isSink(DataFlow::Node sink) { sink = any(CsvWriter cw).getAnInput() }
1515

16-
override predicate isSink(DataFlow::Node sink) { sink = any(CsvWriter cw).getAnInput() }
17-
18-
override predicate isSanitizer(DataFlow::Node node) {
16+
predicate isBarrier(DataFlow::Node node) {
1917
node = DataFlow::BarrierGuard<startsWithCheck/3>::getABarrierNode() or
2018
node instanceof StringConstCompareBarrier
2119
}
@@ -29,3 +27,6 @@ private predicate startsWithCheck(DataFlow::GuardNode g, ControlFlowNode node, b
2927
branch = true
3028
)
3129
}
30+
31+
/** Global taint-tracking for detecting "CSV injection" vulnerabilities. */
32+
module CsvInjectionFlow = TaintTracking::Global<CsvInjectionConfig>;

0 commit comments

Comments
 (0)