Skip to content

Commit 34bb5ac

Browse files
author
Sakshis
committed
cookie-httponly-false-java
1 parent a008769 commit 34bb5ac

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
id: cookie-httponly-false-java
2+
language: java
3+
message: >-
4+
A cookie was detected without setting the 'HttpOnly' flag. The
5+
'HttpOnly' flag for cookies instructs the browser to forbid client-side
6+
scripts from reading the cookie. Set the 'HttpOnly' flag by calling
7+
'cookie.setHttpOnly(true);'
8+
note: >-
9+
[CWE-1004] Sensitive Cookie Without 'HttpOnly' Flag.
10+
[REFERENCES]
11+
- https://capec.mitre.org/data/definitions/463.html
12+
rule:
13+
pattern: $COOKIE.setHttpOnly(false);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
id: cookie-httponly-false-java
2+
snapshots:
3+
? |2
4+
5+
@RequestMapping(value = "/cookie4", method = "GET")
6+
public void explicitDisable(@RequestParam String value, HttpServletResponse response) {
7+
Cookie cookie = new Cookie("cookie", value);
8+
cookie.setSecure(false);
9+
cookie.setHttpOnly(false);
10+
response.addCookie(cookie);
11+
}
12+
: labels:
13+
- source: cookie.setHttpOnly(false);
14+
style: primary
15+
start: 223
16+
end: 249
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
id: cookie-httponly-false-java
2+
valid:
3+
- |
4+
@RequestMapping(value = "/cookie3", method = "GET")
5+
public void setSecureHttponlyCookie(@RequestParam String value, HttpServletResponse response) {
6+
Cookie cookie = new Cookie("cookie", value);
7+
cookie.setSecure(true);
8+
cookie.setHttpOnly(true);
9+
response.addCookie(cookie);
10+
}
11+
invalid:
12+
- |
13+
14+
@RequestMapping(value = "/cookie4", method = "GET")
15+
public void explicitDisable(@RequestParam String value, HttpServletResponse response) {
16+
Cookie cookie = new Cookie("cookie", value);
17+
cookie.setSecure(false);
18+
cookie.setHttpOnly(false);
19+
response.addCookie(cookie);
20+
}

0 commit comments

Comments
 (0)