Skip to content

Commit d8b37d0

Browse files
Review suggestions - update comments and description
1 parent 9cb593b commit d8b37d0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

java/ql/src/Security/CWE/CWE-1004/SensitiveCookieNotHttpOnly.ql

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
22
* @name Sensitive cookies without the HttpOnly response header set
3-
* @description Sensitive cookies without the 'HttpOnly' flag set leaves session cookies vulnerable to
3+
* @description A sensitive cookie without the 'HttpOnly' flag set may be vulnerable to
44
* an XSS attack.
55
* @kind path-problem
66
* @problem.severity warning
7-
* @precision medium
7+
* @precision high
8+
* @security-severity 5.0
89
* @id java/sensitive-cookie-not-httponly
910
* @tags security
1011
* external/cwe/cwe-1004
@@ -101,8 +102,9 @@ predicate removesCookie(MethodCall ma) {
101102
}
102103

103104
/**
104-
* A taint configuration tracking flow of a method that sets the `HttpOnly` flag,
105-
* or one that removes a cookie, to a `ServletResponse.addCookie` call.
105+
* A taint configuration tracking the flow of a cookie that has had the
106+
* `HttpOnly` flag set, or has been removed, to a `ServletResponse.addCookie`
107+
* call.
106108
*/
107109
module SetHttpOnlyOrRemovesCookieToAddCookieConfig implements DataFlow::ConfigSig {
108110
predicate isSource(DataFlow::Node source) {
@@ -120,8 +122,8 @@ module SetHttpOnlyOrRemovesCookieToAddCookieFlow =
120122
TaintTracking::Global<SetHttpOnlyOrRemovesCookieToAddCookieConfig>;
121123

122124
/**
123-
* A cookie that is added to an HTTP response and which doesn't have `httpOnly` set, used as a sink
124-
* in `MissingHttpOnlyConfiguration`.
125+
* A cookie that is added to an HTTP response and which doesn't have `HttpOnly` set, used as a sink
126+
* in `MissingHttpOnlyConfig`.
125127
*/
126128
class CookieResponseWithoutHttpOnlySink extends DataFlow::ExprNode {
127129
CookieResponseWithoutHttpOnlySink() {
@@ -157,9 +159,11 @@ predicate setsHttpOnlyInNewCookie(ClassInstanceExpr cie) {
157159

158160
/**
159161
* A taint configuration tracking flow from a sensitive cookie without the `HttpOnly` flag
160-
* set to its HTTP response.
162+
* set to an HTTP response.
163+
*
161164
* Tracks string literals containing sensitive names (`SensitiveCookieNameExpr`), to an `addCookie` call (as a `Cookie` object)
162165
* or an `addHeader` call (as a string) (`CookieResponseWithoutHttpOnlySink`).
166+
*
163167
* Passes through `Cookie` constructors and `toString` calls.
164168
*/
165169
module MissingHttpOnlyConfig implements DataFlow::ConfigSig {
@@ -169,7 +173,7 @@ module MissingHttpOnlyConfig implements DataFlow::ConfigSig {
169173

170174
predicate isBarrier(DataFlow::Node node) {
171175
// JAX-RS's `new NewCookie("session-access-key", accessKey, "/", null, null, 0, true, true)` and similar
172-
// Cookie constructors, but barriers to considering the flow of the sensitive name, as httponly flag is set.
176+
// Cookie constructors that set the `HttpOnly` flag are considered barriers to the flow of sensitive names.
173177
setsHttpOnlyInNewCookie(node.asExpr())
174178
}
175179

java/ql/test/query-tests/security/CWE-1004/SensitiveCookieNotHttpOnly.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void addCookie(String jwt_token, HttpServletRequest request, HttpServletR
1616
jwtCookie.setPath("/");
1717
jwtCookie.setMaxAge(3600*24*7);
1818
jwtCookie.setHttpOnly(true);
19-
response.addCookie(jwtCookie);
19+
response.addCookie(jwtCookie);
2020
}
2121

2222
// BAD - Tests adding a sensitive cookie without the `HttpOnly` flag set.
@@ -29,7 +29,7 @@ public void addCookie2(String jwt_token, String userId, HttpServletRequest reque
2929
jwtCookie.setMaxAge(3600*24*7);
3030
userIdCookie.setMaxAge(3600*24*7);
3131
response.addCookie(jwtCookie); // $Alert
32-
response.addCookie(userIdCookie);
32+
response.addCookie(userIdCookie);
3333
}
3434

3535
// GOOD - Tests set a sensitive cookie header with the `HttpOnly` flag set.

0 commit comments

Comments
 (0)