A cookie's Secure or HttpOnly flag is switched off or never switched on
What it finds
cookie.setSecure(false) lets the browser send the cookie over plain HTTP, where anyone on the network can read it (CWE-614), and cookie.setHttpOnly(false) lets scripts of the page read it, which a cross-site scripting flaw then exploits (CWE-1004). Both flags are on for session and other sensitive cookies.
Reported are setSecure(false) and setHttpOnly(false) on a cookie, and a servlet or java.net.HttpCookie created in a method that never calls setSecure or setHttpOnly on it and does not hand it to code other than addCookie, which might. Cookies named after an anti-forgery token are meant to be read by scripts and need no HttpOnly.
From the rule's source, cookie_protection_off.rs.
import javax.servlet.http.Cookie; class Session { Cookie make(String id) { Cookie cookie = new Cookie("session", id); cookie.setSecure(false);tx0 reports: the Secure flag of this cookie is switched off cookie.setHttpOnly(false);tx0 reports: the HttpOnly flag of this cookie is switched off cookie.setSecure(true); return cookie; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:cookie-protection-off" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:cookie-protection-off] reason="..."tx0 explain tx0/java:cookie-protection-off shows the same in the terminal. Found a false positive? Report it.