Skip to content

Commit 2857bf9

Browse files
committed
Convert trust boundary models to MaD
1 parent 03a9464 commit 2857bf9

File tree

5 files changed

+31
-55
lines changed

5 files changed

+31
-55
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/java-all
4+
extensible: sinkModel
5+
data:
6+
- ["org.apache.struts2.dispatcher", "SessionMap", False, "put", "", "", "Argument[0..1]", "trust-boundary", "manual"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/java-all
4+
extensible: sinkModel
5+
data:
6+
- ["org.apache.struts2.interceptor", "SessionAware", False, "setSession", "", "", "Argument[0]", "trust-boundary", "manual"]
7+
- ["org.apache.struts2.interceptor", "SessionAware", False, "withSession", "", "", "Argument[0]", "trust-boundary", "manual"]

java/ql/lib/ext/play.mvc.model.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ extensions:
1616
- ["play.mvc", "Http$RequestHeader", True, "queryString", "", "", "ReturnValue", "remote", "manual"]
1717
- ["play.mvc", "Http$RequestHeader", True, "remoteAddress", "", "", "ReturnValue", "remote", "manual"]
1818
- ["play.mvc", "Http$RequestHeader", True, "uri", "", "", "ReturnValue", "remote", "manual"]
19+
- addsTo:
20+
pack: codeql/java-all
21+
extensible: sinkModel
22+
data:
23+
- ["play.mvc", "Result", False, "addingToSession", "", "", "Argument[1..2]", "trust-boundary", "manual"]
1924
- addsTo:
2025
pack: codeql/java-all
2126
extensible: summaryModel

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@ private import semmle.code.java.dataflow.FlowSources
77
private import semmle.code.java.frameworks.Servlets
88

99
class TrustBoundaryViolationSource extends DataFlow::Node {
10-
TrustBoundaryViolationSource() {
11-
this instanceof RemoteFlowSource and this.asExpr().getType() instanceof HttpServletRequest
12-
}
10+
TrustBoundaryViolationSource() { this.asExpr().getType() instanceof HttpServletRequest }
1311
}
1412

1513
class TrustBoundaryViolationSink extends DataFlow::Node {
1614
TrustBoundaryViolationSink() { sinkNode(this, "trust-boundary") }
1715
}
16+
17+
module TrustBoundaryConfig implements DataFlow::ConfigSig {
18+
predicate isSource(DataFlow::Node source) { source instanceof TrustBoundaryViolationSource }
19+
20+
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
21+
n2.asExpr().(MethodAccess).getQualifier() = n1.asExpr()
22+
}
23+
24+
predicate isSink(DataFlow::Node sink) { sink instanceof TrustBoundaryViolationSink }
25+
}
26+
27+
module TrustBoundaryFlow = TaintTracking::Global<TrustBoundaryConfig>;

java/ql/src/Security/CWE/CWE-501/TrustBoundaryViolation.ql

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,6 @@ import semmle.code.java.dataflow.DataFlow
1414
import semmle.code.java.dataflow.FlowSources
1515
import semmle.code.java.dataflow.TaintTracking
1616
import semmle.code.java.security.TrustBoundaryViolationQuery
17-
18-
/**
19-
* The `setAttribute` method of the `HttpSession` interface.
20-
*/
21-
abstract class SessionSetAttributeMethod extends Method {
22-
abstract int getArgumentIndex();
23-
}
24-
25-
private class PlayMvcResultAddingToSessionMethod extends SessionSetAttributeMethod {
26-
PlayMvcResultAddingToSessionMethod() {
27-
this.getDeclaringType().hasQualifiedName("play.mvc", "Result") and
28-
this.hasName("addingToSession")
29-
}
30-
31-
override int getArgumentIndex() { result = [1, 2] }
32-
}
33-
34-
private class Struts2SessionMapPutMethod extends SessionSetAttributeMethod {
35-
Struts2SessionMapPutMethod() {
36-
this.getDeclaringType().hasQualifiedName("org.apache.struts2.dispatcher", "SessionMap") and
37-
this.hasName("put")
38-
}
39-
40-
override int getArgumentIndex() { result = 1 }
41-
}
42-
43-
private class Struts2SessionSetMethod extends SessionSetAttributeMethod {
44-
Struts2SessionSetMethod() {
45-
this.getDeclaringType().hasQualifiedName("org.apache.struts2.interceptor", "SessionAware") and
46-
this.hasName(["setSession", "withSession"])
47-
}
48-
49-
override int getArgumentIndex() { result = 0 }
50-
}
51-
52-
module TrustBoundaryConfig implements DataFlow::ConfigSig {
53-
predicate isSource(DataFlow::Node source) {
54-
source instanceof RemoteFlowSource and
55-
source.asExpr().(MethodAccess).getQualifier().getType() instanceof HttpServletRequest
56-
}
57-
58-
predicate isSink(DataFlow::Node sink) {
59-
exists(MethodAccess ma, SessionSetAttributeMethod m | m = ma.getMethod() |
60-
sink.asExpr() = ma.getArgument(m.getArgumentIndex())
61-
)
62-
or
63-
sink instanceof TrustBoundaryViolationSink
64-
}
65-
}
66-
67-
module TrustBoundaryFlow = TaintTracking::Global<TrustBoundaryConfig>;
68-
6917
import TrustBoundaryFlow::PathGraph
7018

7119
from TrustBoundaryFlow::PathNode source, TrustBoundaryFlow::PathNode sink

0 commit comments

Comments
 (0)