Skip to content

Commit b028d16

Browse files
committed
feat(python): Add Debugging queries
1 parent fab6524 commit b028d16

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @name Partial Path Query from Sink
3+
* @kind path-problem
4+
* @problem.severity warning
5+
* @security-severity 1.0
6+
* @sub-severity low
7+
* @precision low
8+
* @id py/debugging/partial-path-from-sink
9+
* @tags debugging
10+
*/
11+
12+
import python
13+
import ghsl
14+
import semmle.python.dataflow.new.DataFlow
15+
import semmle.python.dataflow.new.TaintTracking
16+
import semmle.python.Concepts
17+
import semmle.python.dataflow.new.RemoteFlowSources
18+
import semmle.python.dataflow.new.BarrierGuards
19+
import semmle.python.ApiGraphs
20+
21+
// Partial Graph
22+
module PartialFlowConfig implements DataFlow::ConfigSig {
23+
predicate isSource(DataFlow::Node source) { any() }
24+
25+
predicate isSink(DataFlow::Node sink) { sink instanceof AllSinks }
26+
}
27+
28+
int explorationLimit() { result = 10 }
29+
30+
private module PartialFlows = DataFlow::Global<PartialFlowConfig>;
31+
32+
private module PartialFlowsGraph = PartialFlows::FlowExplorationRev<explorationLimit/0>;
33+
34+
private import PartialFlowsGraph::PartialPathGraph
35+
36+
from PartialFlowsGraph::PartialPathNode source, PartialFlowsGraph::PartialPathNode sink
37+
where
38+
/// Only show sinks from a certain file
39+
// findByLocation(sink.getNode(), "File.java", _) and
40+
/// Only show sources that match our criteria
41+
// checkSource(source.getNode()) and
42+
/// Partical Path
43+
PartialFlowsGraph::partialFlow(source, sink, _)
44+
select sink.getNode(), source, sink, "Partial Graph $@.", source.getNode(), "user-provided value"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @name Partial Path Query from Source
3+
* @kind path-problem
4+
* @problem.severity warning
5+
* @security-severity 1.0
6+
* @sub-severity low
7+
* @precision low
8+
* @id py/debugging/partial-path-from-source
9+
* @tags debugging
10+
*/
11+
12+
import python
13+
import ghsl
14+
import semmle.python.dataflow.new.DataFlow
15+
import semmle.python.dataflow.new.TaintTracking
16+
import semmle.python.Concepts
17+
import semmle.python.dataflow.new.RemoteFlowSources
18+
import semmle.python.dataflow.new.BarrierGuards
19+
import semmle.python.ApiGraphs
20+
21+
// Partial Graph
22+
module PartialFlowConfig implements DataFlow::ConfigSig {
23+
predicate isSource(DataFlow::Node source) {
24+
source instanceof AllSources and
25+
// Make sure the source node is in the source code
26+
source.getScope().inSource()
27+
}
28+
29+
predicate isSink(DataFlow::Node sink) { none() }
30+
}
31+
32+
int explorationLimit() { result = 10 }
33+
34+
module PartialFlows = DataFlow::Global<PartialFlowConfig>;
35+
36+
module PartialFlowsGraph = PartialFlows::FlowExplorationFwd<explorationLimit/0>;
37+
38+
import PartialFlowsGraph::PartialPathGraph
39+
40+
from PartialFlowsGraph::PartialPathNode source, PartialFlowsGraph::PartialPathNode sink
41+
where
42+
PartialFlowsGraph::partialFlow(source, sink, _) and
43+
/// Filter by location
44+
filterByLocation(source.getNode(), "app.py", _)
45+
/// Filter by Function Parameters
46+
// and functionParameters(sink.getNode())
47+
select sink.getNode(), source, sink, "Partial Graph $@.", source.getNode(), "user-provided value"

python/src/debugging/Sinks.ql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name List of all known sinks
3+
* @kind problem
4+
* @problem.severity warning
5+
* @security-severity 1.0
6+
* @sub-severity low
7+
* @precision high
8+
* @id py/debugging/sinks
9+
* @tags debugging
10+
*/
11+
12+
import python
13+
import ghsl
14+
15+
from AllSinks sinks
16+
select sinks, "sink[" + sinks.sinkType() + "]"

python/src/debugging/Sources.ql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name List of all known sources (remote, local, etc.)
3+
* @kind problem
4+
* @problem.severity warning
5+
* @security-severity 1.0
6+
* @sub-severity low
7+
* @precision high
8+
* @id py/debugging/sources
9+
* @tags debugging
10+
*/
11+
12+
import python
13+
import ghsl
14+
15+
from AllSources sources, string threatModel
16+
where threatModel = sources.getThreatModel()
17+
// Local sources
18+
// sources.getThreatModel() = "local"
19+
select sources, "source[" + threatModel + "]"

0 commit comments

Comments
 (0)