Skip to content

Commit b39d508

Browse files
committed
Add InsecureCookieQuery
1 parent be24b29 commit b39d508

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

java/ql/lib/change-notes/2023-03-30-add-libraries-for-query-configurations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ category: minorAnalysis
55
* Added the `XPathInjectionQuery.qll` library to provide the `XPathInjectionFlow` taint-tracking module to reason about XPath injection vulnerabilities.
66
* Added the `SqlConcatenatedQuery.qll` library to provide the `UncontrolledStringBuilderSourceFlow` taint-tracking module to reason about SQL injection vulnerabilities caused by concatenating untrusted strings.
77
* Added the `XssLocalQuery.qll` library to provide the `XssLocalFlow` taint-tracking module to reason about XSS vulnerabilities caused by local data flow.
8-
* Added the `ExternallyControlledFormatStringLocalQuery.qll` library to provide the `ExternallyControlledFormatStringLocalFlow` taint-tracking module to reason about format string vulnerabilities caused by local data flow.
8+
* Added the `ExternallyControlledFormatStringLocalQuery.qll` library to provide the `ExternallyControlledFormatStringLocalFlow` taint-tracking module to reason about format string vulnerabilities caused by local data flow.
9+
* Added the `InsecureCookieQuery.qll` library to provide the `SecureCookieFlow` taint-tracking module to reason about insecure cookie vulnerabilities.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/** Provides a dataflow configuration to reason about the failure to use secure cookies. */
2+
3+
import java
4+
import semmle.code.java.dataflow.DataFlow
5+
private import semmle.code.java.frameworks.Servlets
6+
7+
private predicate isSafeSecureCookieSetting(Expr e) {
8+
e.(CompileTimeConstantExpr).getBooleanValue() = true
9+
or
10+
exists(Method isSecure |
11+
isSecure.hasName("isSecure") and
12+
isSecure.getDeclaringType().getASourceSupertype*() instanceof ServletRequest
13+
|
14+
e.(MethodAccess).getMethod() = isSecure
15+
)
16+
}
17+
18+
/** A dataflow configuration to reason about the failure to use secure cookies. */
19+
module SecureCookieConfig implements DataFlow::ConfigSig {
20+
predicate isSource(DataFlow::Node source) {
21+
exists(MethodAccess ma, Method m | ma.getMethod() = m |
22+
m.getDeclaringType() instanceof TypeCookie and
23+
m.getName() = "setSecure" and
24+
source.asExpr() = ma.getQualifier() and
25+
forex(DataFlow::Node argSource |
26+
DataFlow::localFlow(argSource, DataFlow::exprNode(ma.getArgument(0))) and
27+
not DataFlow::localFlowStep(_, argSource)
28+
|
29+
isSafeSecureCookieSetting(argSource.asExpr())
30+
)
31+
)
32+
}
33+
34+
predicate isSink(DataFlow::Node sink) {
35+
sink.asExpr() =
36+
any(MethodAccess add | add.getMethod() instanceof ResponseAddCookieMethod).getArgument(0)
37+
}
38+
}
39+
40+
/** Data flow to reason about the failure to use secure cookies. */
41+
module SecureCookieFlow = DataFlow::Global<SecureCookieConfig>;

java/ql/src/Security/CWE/CWE-614/InsecureCookie.ql

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,7 @@
1313

1414
import java
1515
import semmle.code.java.frameworks.Servlets
16-
import semmle.code.java.dataflow.DataFlow
17-
18-
predicate isSafeSecureCookieSetting(Expr e) {
19-
e.(CompileTimeConstantExpr).getBooleanValue() = true
20-
or
21-
exists(Method isSecure |
22-
isSecure.getName() = "isSecure" and
23-
isSecure.getDeclaringType().getASourceSupertype*() instanceof ServletRequest
24-
|
25-
e.(MethodAccess).getMethod() = isSecure
26-
)
27-
}
28-
29-
module SecureCookieConfig implements DataFlow::ConfigSig {
30-
predicate isSource(DataFlow::Node source) {
31-
exists(MethodAccess ma, Method m | ma.getMethod() = m |
32-
m.getDeclaringType() instanceof TypeCookie and
33-
m.getName() = "setSecure" and
34-
source.asExpr() = ma.getQualifier() and
35-
forex(DataFlow::Node argSource |
36-
DataFlow::localFlow(argSource, DataFlow::exprNode(ma.getArgument(0))) and
37-
not DataFlow::localFlowStep(_, argSource)
38-
|
39-
isSafeSecureCookieSetting(argSource.asExpr())
40-
)
41-
)
42-
}
43-
44-
predicate isSink(DataFlow::Node sink) {
45-
sink.asExpr() =
46-
any(MethodAccess add | add.getMethod() instanceof ResponseAddCookieMethod).getArgument(0)
47-
}
48-
}
49-
50-
module SecureCookieFlow = DataFlow::Global<SecureCookieConfig>;
16+
import semmle.code.java.security.InsecureCookieQuery
5117

5218
from MethodAccess add
5319
where

0 commit comments

Comments
 (0)