Skip to content

Commit 7fb8e0e

Browse files
committed
Python: Add basic shared taint tracking test
1 parent 0baac8f commit 7fb8e0e

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.py:3:11:3:16 | ControlFlowNode for SOURCE | test.py:4:6:4:12 | ControlFlowNode for tainted |
2+
| test.py:7:20:7:25 | ControlFlowNode for SOURCE | test.py:8:10:8:21 | ControlFlowNode for also_tainted |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import python
2+
import experimental.dataflow.TaintTracking
3+
import experimental.dataflow.DataFlow
4+
5+
class TestTaintTrackingConfiguration extends TaintTracking::Configuration {
6+
TestTaintTrackingConfiguration() { this = "TestTaintTrackingConfiguration" }
7+
8+
override predicate isSource(DataFlow::Node source) {
9+
source.(DataFlow::CfgNode).getNode().(NameNode).getId() = "SOURCE"
10+
}
11+
12+
override predicate isSink(DataFlow::Node sink) {
13+
exists(CallNode call |
14+
call.getFunction().(NameNode).getId() = "SINK" and
15+
sink.(DataFlow::CfgNode).getNode() = call.getAnArg()
16+
)
17+
}
18+
}
19+
20+
from TestTaintTrackingConfiguration config, DataFlow::Node source, DataFlow::Node sink
21+
where config.hasFlow(source, sink)
22+
select source, sink
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.py:0:0:0:0 | SSA variable $ | test.py:0:0:0:0 | Exit node for Module test |
2+
| test.py:7:5:7:16 | SSA variable also_tainted | test.py:8:5:8:22 | SSA variable also_tainted |
3+
| test.py:7:5:7:16 | SSA variable also_tainted | test.py:8:10:8:21 | ControlFlowNode for also_tainted |
4+
| test.py:7:20:7:25 | ControlFlowNode for SOURCE | test.py:7:5:7:16 | SSA variable also_tainted |
5+
| test.py:8:5:8:22 | SSA variable also_tainted | test.py:6:1:6:11 | Exit node for Function func |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import python
2+
import experimental.dataflow.TaintTracking
3+
import experimental.dataflow.DataFlow
4+
5+
from DataFlow::Node nodeFrom, DataFlow::Node nodeTo
6+
where TaintTracking::localTaintStep(nodeFrom, nodeTo)
7+
select nodeFrom, nodeTo
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Module level taint is different from inside functions, since shared dataflow library
2+
# relies on `getEnclosingCallable`
3+
tainted = SOURCE
4+
SINK(tainted)
5+
6+
def func():
7+
also_tainted = SOURCE
8+
SINK(also_tainted)

0 commit comments

Comments
 (0)