Skip to content

Commit d7f26df

Browse files
committed
Update stub classes and qldoc
1 parent 04b0682 commit d7f26df

File tree

4 files changed

+22
-66
lines changed

4 files changed

+22
-66
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class CookieClass extends RefType {
8282
}
8383
}
8484

85-
/** Holds if the `expr` is `true` or a variable that is ever assigned `true`. */
86-
// This could be a very large result set if computed out of context
85+
/** Holds if `expr` is any boolean-typed expression other than literal `false`. */
86+
// Inlined because this could be a very large result set if computed out of context
8787
pragma[inline]
8888
predicate mayBeBooleanTrue(Expr expr) {
8989
expr.getType() instanceof BooleanType and
@@ -123,11 +123,11 @@ predicate isTestMethod(MethodAccess ma) {
123123
}
124124

125125
/**
126-
* A taint configuration tracking flow of a method or a wrapper method that sets the `HttpOnly`
127-
* flag, or one that removes a cookie, to a `ServletResponse.addCookie` call.
126+
* A taint configuration tracking flow of a method that sets the `HttpOnly` flag,
127+
* or one that removes a cookie, to a `ServletResponse.addCookie` call.
128128
*/
129-
class SetHttpOnlyInCookieConfiguration extends TaintTracking2::Configuration {
130-
SetHttpOnlyInCookieConfiguration() { this = "SetHttpOnlyInCookieConfiguration" }
129+
class SetHttpOnlyOrRemovesCookieConfiguration extends TaintTracking2::Configuration {
130+
SetHttpOnlyOrRemovesCookieConfiguration() { this = "SetHttpOnlyOrRemovesCookieConfiguration" }
131131

132132
override predicate isSource(DataFlow::Node source) {
133133
source.asExpr() =
@@ -150,7 +150,7 @@ class CookieResponseSink extends DataFlow::ExprNode {
150150
(
151151
ma.getMethod() instanceof ResponseAddCookieMethod and
152152
this.getExpr() = ma.getArgument(0) and
153-
not exists(SetHttpOnlyInCookieConfiguration cc | cc.hasFlowTo(this))
153+
not exists(SetHttpOnlyOrRemovesCookieConfiguration cc | cc.hasFlowTo(this))
154154
or
155155
ma instanceof SetCookieMethodAccess and
156156
this.getExpr() = ma.getArgument(1) and

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void addCookie14(HttpServletRequest request, HttpServletResponse response
137137
response.addCookie(createCookie("refresh_token", refreshToken, true));
138138
}
139139

140-
// BAD - Tests set a sensitive cookie header with the `HttpOnly` flag not set through a boolean variable using a wrapper method.
140+
// GOOD - Tests set a sensitive cookie header with the `HttpOnly` flag not set through a boolean variable using a wrapper method.
141141
public void addCookie15(HttpServletRequest request, HttpServletResponse response, String refreshToken) {
142142
response.addCookie(createCookie("refresh_token", refreshToken, false));
143143
}

java/ql/test/stubs/jsr311-api-1.1.1/javax/ws/rs/core/Cookie.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static Cookie valueOf(final String value) {
125125
* @return the cookie name.
126126
*/
127127
public String getName() {
128-
return name;
128+
return null;
129129
}
130130

131131
/**
@@ -134,7 +134,7 @@ public String getName() {
134134
* @return the cookie value.
135135
*/
136136
public String getValue() {
137-
return value;
137+
return null;
138138
}
139139

140140
/**
@@ -143,7 +143,7 @@ public String getValue() {
143143
* @return the cookie version.
144144
*/
145145
public int getVersion() {
146-
return version;
146+
return -1;
147147
}
148148

149149
/**
@@ -152,7 +152,7 @@ public int getVersion() {
152152
* @return the cookie domain.
153153
*/
154154
public String getDomain() {
155-
return domain;
155+
return null;
156156
}
157157

158158
/**
@@ -161,6 +161,6 @@ public String getDomain() {
161161
* @return the cookie path.
162162
*/
163163
public String getPath() {
164-
return path;
164+
return null;
165165
}
166166
}

java/ql/test/stubs/servlet-api-2.4/javax/servlet/http/Cookie.java

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,95 +24,51 @@
2424
package javax.servlet.http;
2525

2626
public class Cookie implements Cloneable {
27-
private String name; // NAME= ... "$Name" style is reserved
28-
private String value; // value of NAME
29-
private String comment; // ;Comment=VALUE ... describes cookie's use
30-
private String domain; // ;Domain=VALUE ... domain that sees cookie
31-
private int maxAge = -1; // ;Max-Age=VALUE ... cookies auto-expire
32-
private String path; // ;Path=VALUE ... URLs that see the cookie
33-
private boolean secure; // ;Secure ... e.g. use SSL
34-
private int version = 0; // ;Version=1 ... means RFC 2109++ style
35-
private boolean isHttpOnly = false;
3627

3728
public Cookie(String name, String value) {
38-
this.name = name;
39-
this.value = value;
4029
}
4130
public void setComment(String purpose) {
42-
comment = purpose;
4331
}
4432
public String getComment() {
45-
return comment;
33+
return null;
4634
}
4735
public void setDomain(String pattern) {
48-
domain = pattern.toLowerCase(); // IE allegedly needs this
4936
}
5037
public String getDomain() {
51-
return domain;
38+
return null;
5239
}
5340
public void setMaxAge(int expiry) {
54-
maxAge = expiry;
5541
}
5642
public int getMaxAge() {
57-
return maxAge;
43+
return -1;
5844
}
5945
public void setPath(String uri) {
60-
path = uri;
6146
}
6247
public String getPath() {
63-
return path;
48+
return null;
6449
}
6550
public void setSecure(boolean flag) {
66-
secure = flag;
6751
}
6852
public boolean getSecure() {
69-
return secure;
53+
return false;
7054
}
7155
public String getName() {
72-
return name;
56+
return null;
7357
}
7458
public void setValue(String newValue) {
75-
value = newValue;
7659
}
7760
public String getValue() {
78-
return value;
61+
return null;
7962
}
8063
public int getVersion() {
81-
return version;
64+
return -1;
8265
}
8366
public void setVersion(int v) {
8467
}
85-
86-
/**
87-
* Marks or unmarks this Cookie as <i>HttpOnly</i>.
88-
*
89-
* <p>If <tt>isHttpOnly</tt> is set to <tt>true</tt>, this cookie is
90-
* marked as <i>HttpOnly</i>, by adding the <tt>HttpOnly</tt> attribute
91-
* to it.
92-
*
93-
* <p><i>HttpOnly</i> cookies are not supposed to be exposed to
94-
* client-side scripting code, and may therefore help mitigate certain
95-
* kinds of cross-site scripting attacks.
96-
*
97-
* @param isHttpOnly true if this cookie is to be marked as
98-
* <i>HttpOnly</i>, false otherwise
99-
*
100-
* @since Servlet 3.0
101-
*/
10268
public void setHttpOnly(boolean isHttpOnly) {
103-
this.isHttpOnly = isHttpOnly;
10469
}
105-
106-
/**
107-
* Checks whether this Cookie has been marked as <i>HttpOnly</i>.
108-
*
109-
* @return true if this Cookie has been marked as <i>HttpOnly</i>,
110-
* false otherwise
111-
*
112-
* @since Servlet 3.0
113-
*/
11470
public boolean isHttpOnly() {
115-
return isHttpOnly;
71+
return false;
11672
}
11773

11874
/**

0 commit comments

Comments
 (0)