Skip to content

Commit c553e31

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add CallGraph module for displaying call graph paths
1 parent 87a8746 commit c553e31

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import semmle.code.java.frameworks.MyBatis
66
private import semmle.code.java.frameworks.Jdbc
77
private import semmle.code.java.dataflow.DataFlow
88
private import semmle.code.java.dataflow.ExternalFlow
9+
private import semmle.code.java.dispatch.VirtualDispatch
910

1011
/** A method that is not protected from CSRF by default. */
1112
abstract class CsrfUnprotectedMethod extends Method { }
@@ -71,3 +72,47 @@ private class SqlDatabaseUpdateMethod extends DatabaseUpdateMethod {
7172
)
7273
}
7374
}
75+
76+
module CallGraph {
77+
newtype TPathNode =
78+
TMethod(Method m) or
79+
TCall(Call c)
80+
81+
class PathNode extends TPathNode {
82+
Method asMethod() { this = TMethod(result) }
83+
84+
Call asCall() { this = TCall(result) }
85+
86+
string toString() {
87+
result = this.asMethod().toString()
88+
or
89+
result = this.asCall().toString()
90+
}
91+
92+
private PathNode getACallee() {
93+
[viableCallable(this.asCall()), this.asCall().getCallee()] = result.asMethod()
94+
}
95+
96+
PathNode getASuccessor() {
97+
this.asMethod() = result.asCall().getEnclosingCallable()
98+
or
99+
result = this.getACallee() and
100+
(
101+
exists(PathNode p |
102+
p = this.getACallee() and
103+
p.asMethod() instanceof DatabaseUpdateMethod
104+
)
105+
implies
106+
result.asMethod() instanceof DatabaseUpdateMethod
107+
)
108+
}
109+
110+
Location getLocation() {
111+
result = this.asMethod().getLocation()
112+
or
113+
result = this.asCall().getLocation()
114+
}
115+
}
116+
117+
query predicate edges(PathNode pred, PathNode succ) { pred.getASuccessor() = succ }
118+
}

0 commit comments

Comments
 (0)