Skip to content

Commit 3f4c2ba

Browse files
committed
Python: Support debugging inline taint tests
The module `Conf` is created so that it can be imported without importing the query predicates from the same file.
1 parent 624b794 commit 3f4c2ba

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

python/ql/test/experimental/meta/InlineTaintTest.qll

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,34 @@ DataFlow::Node shouldNotBeTainted() {
3030
)
3131
}
3232

33-
class TestTaintTrackingConfiguration extends TaintTracking::Configuration {
34-
TestTaintTrackingConfiguration() { this = "TestTaintTrackingConfiguration" }
33+
module Conf {
34+
class TestTaintTrackingConfiguration extends TaintTracking::Configuration {
35+
TestTaintTrackingConfiguration() { this = "TestTaintTrackingConfiguration" }
3536

36-
override predicate isSource(DataFlow::Node source) {
37-
source.asCfgNode().(NameNode).getId() in [
38-
"TAINTED_STRING", "TAINTED_BYTES", "TAINTED_LIST", "TAINTED_DICT"
39-
]
40-
or
41-
// User defined sources
42-
exists(CallNode call |
43-
call.getFunction().(NameNode).getId() = "taint" and
44-
source.(DataFlow::CfgNode).getNode() = call.getAnArg()
45-
)
46-
or
47-
source instanceof RemoteFlowSource
48-
}
37+
override predicate isSource(DataFlow::Node source) {
38+
source.asCfgNode().(NameNode).getId() in [
39+
"TAINTED_STRING", "TAINTED_BYTES", "TAINTED_LIST", "TAINTED_DICT"
40+
]
41+
or
42+
// User defined sources
43+
exists(CallNode call |
44+
call.getFunction().(NameNode).getId() = "taint" and
45+
source.(DataFlow::CfgNode).getNode() = call.getAnArg()
46+
)
47+
or
48+
source instanceof RemoteFlowSource
49+
}
4950

50-
override predicate isSink(DataFlow::Node sink) {
51-
sink = shouldBeTainted()
52-
or
53-
sink = shouldNotBeTainted()
51+
override predicate isSink(DataFlow::Node sink) {
52+
sink = shouldBeTainted()
53+
or
54+
sink = shouldNotBeTainted()
55+
}
5456
}
5557
}
5658

59+
import Conf
60+
5761
class InlineTaintTest extends InlineExpectationsTest {
5862
InlineTaintTest() { this = "InlineTaintTest" }
5963

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
edges
2+
nodes
3+
subpaths
4+
#select
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
// This query is for debugging InlineTaintTestFailures.
6+
// The intended usage is
7+
// 1. load the database of the failing test
8+
// 2. run this query to see actual paths
9+
// 3. if necessary, look at partial paths by (un)commenting appropriate lines
10+
import python
11+
import semmle.python.dataflow.new.DataFlow
12+
import experimental.meta.InlineTaintTest::Conf
13+
// import DataFlow::PartialPathGraph
14+
import DataFlow::PathGraph
15+
16+
class Conf extends TestTaintTrackingConfiguration {
17+
override int explorationLimit() { result = 5 }
18+
}
19+
20+
// from Conf config, DataFlow::PartialPathNode source, DataFlow::PartialPathNode sink
21+
// where config.hasPartialFlow(source, sink, _)
22+
from Conf config, DataFlow::PathNode source, DataFlow::PathNode sink
23+
where config.hasFlowPath(source, sink)
24+
select sink.getNode(), source, sink, "This node receives taint from $@.", source.getNode(),
25+
"this source"

0 commit comments

Comments
 (0)