-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathUtils.qll
More file actions
89 lines (80 loc) · 2.16 KB
/
Utils.qll
File metadata and controls
89 lines (80 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
private import python
private import semmle.python.ApiGraphs
private import semmle.python.Concepts
private import semmle.python.dataflow.new.DataFlow
private import ghsl.LocalSources
private import ghsl.Sinks
/**
* Find Node at Location
*/
predicate filterByLocation(DataFlow::Node node, string relative_path, int linenumber) {
node.getLocation().getFile().getRelativePath() = relative_path and
node.getLocation().getStartLine() = linenumber
}
/**
* Check if the source node is a method parameter
*/
predicate functionParameters(DataFlow::Node node) {
(
// // Function Call Parameters
node instanceof DataFlow::ParameterNode
or
// Function Call Arguments
node instanceof DataFlow::ArgumentNode
) and
node instanceof AllSinks and
node.getScope().inSource()
}
/**
* List of all the souces
*/
class AllSources extends DataFlow::Node {
private string threatmodel;
AllSources() {
exists(ThreatModelSource tms |
threatmodel = tms.getThreatModel() and
this = tms
)
or
this instanceof LocalSources::Range and
threatmodel = "local"
}
/**
* Gets the source threat model.
*/
string getThreatModel() { result = threatmodel }
}
/**
* Local sources
*/
class LocalSources = LocalSources::Range;
// List of all the format strings
// - python/ql/lib/semmle/python/dataflow/new/internal/TaintTrackingPrivate.qll
class DynamicStrings extends DataFlow::Node {
DynamicStrings() {
(
// s = f"WHERE name = '{input}'"
exists(Fstring fmtstr | this.asExpr() = fmtstr)
or
// "SELECT * FROM users WHERE username = '{}'".format(username)
exists(CallNode format, string methods, ControlFlowNode object |
object = format.getFunction().(AttrNode).getObject(methods)
|
methods = "format" and
this.asExpr() = format.getNode()
)
or
exists(BinaryExpr expr |
(
// q = "WHERE name = %s" % username
expr.getOp() instanceof Mod
or
// q = "WHERE name = " + username
expr.getOp() instanceof Add
) and
expr.getLeft().getParent() = this.asExpr()
)
) and
this.getScope().inSource()
}
}