Skip to content

Commit 8f4ee8a

Browse files
committed
feat: add utility predicates and classes for Java library
1 parent 99346cf commit 8f4ee8a

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

java/lib/ghsl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ghsl.LocalSources
2+
// Export utils
3+
import ghsl.Utils

java/lib/ghsl/Utils.qll

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* A collection of utility predicates and classes for the Java library.
3+
*/
4+
5+
private import semmle.code.java.dataflow.DataFlow
6+
private import semmle.code.java.dataflow.ExternalFlow
7+
private import semmle.code.java.dataflow.FlowSources
8+
// Sinks
9+
private import semmle.code.java.security.QueryInjection
10+
private import semmle.code.java.security.CommandLineQuery
11+
private import semmle.code.java.security.LdapInjection
12+
private import semmle.code.java.security.LogInjection
13+
private import semmle.code.java.security.OgnlInjection
14+
private import semmle.code.java.security.RequestForgery
15+
private import semmle.code.java.security.TemplateInjection
16+
17+
/**
18+
* Filter nodes by its location (relative path or base name).
19+
*/
20+
bindingset[relative_path]
21+
predicate findByLocation(DataFlow::Node node, string relative_path, int linenumber) {
22+
node.getLocation().getFile().getRelativePath().matches(relative_path) and
23+
node.getLocation().getStartLine() = linenumber
24+
}
25+
26+
/**
27+
* This will only show sinks that are callable (method calls)
28+
*/
29+
predicate isCallable(DataFlow::Node sink) { sink.asExpr() instanceof MethodCall }
30+
31+
/**
32+
* Check if the source node is a method parameter.
33+
*/
34+
predicate checkSource(DataFlow::Node source) {
35+
// TODO: fix this
36+
source.asParameter() instanceof Parameter
37+
or
38+
source.asExpr() instanceof MethodCall
39+
}
40+
41+
/**
42+
* Local sources
43+
*/
44+
class LocalSources = LocalUserInput;
45+
46+
/**
47+
* List of all the souces
48+
*/
49+
class AllSources extends DataFlow::Node {
50+
private string threadmodel;
51+
52+
AllSources() {
53+
this instanceof LocalUserInput and
54+
threadmodel = "local"
55+
or
56+
this instanceof RemoteFlowSource and
57+
threadmodel = "remote"
58+
or
59+
this instanceof ActiveThreatModelSource
60+
and
61+
threadmodel = this.(SourceNode).getThreatModel()
62+
}
63+
64+
/**
65+
* Gets the source threat model.
66+
*/
67+
string getThreatModel() {
68+
result = threadmodel
69+
}
70+
}
71+
72+
/**
73+
* List of all the sinks that we want to check.
74+
*/
75+
class AllSinks extends DataFlow::Node {
76+
private string sink;
77+
78+
AllSinks() {
79+
this instanceof QueryInjectionSink
80+
and
81+
sink = "QueryInjectionSink"
82+
or
83+
this instanceof CommandInjectionSink
84+
and
85+
sink = "CommandInjectionSink"
86+
or
87+
this instanceof LdapInjectionSink
88+
and
89+
sink = "LdapInjectionSink"
90+
or
91+
this instanceof LogInjectionSink
92+
and
93+
sink = "LogInjectionSink"
94+
or
95+
this instanceof OgnlInjectionSink
96+
and
97+
sink = "OgnlInjectionSink"
98+
or
99+
this instanceof RequestForgerySink
100+
and
101+
sink = "RequestForgerySink"
102+
or
103+
this instanceof TemplateInjectionSink
104+
and
105+
sink = "TemplateInjectionSink"
106+
or
107+
// All MaD sinks
108+
sinkNode(this, _)
109+
and
110+
sink = "MaD"
111+
}
112+
113+
/**
114+
* Gets the sink sink type.
115+
*/
116+
string sinkType() {
117+
result = sink
118+
}
119+
}

java/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ name: githubsecuritylab/codeql-java-libs
33
version: 0.2.1
44
dependencies:
55
codeql/java-all: '*'
6+
githubsecuritylab/codeql-java-extensions: '0.2.1'

0 commit comments

Comments
 (0)