Skip to content

Commit 11ffcc4

Browse files
authored
Merge pull request github#2912 from Mithrilwoodrat/master
Add check for disabled HTTPOnly setting in Tomcat
2 parents b745809 + a7960c3 commit 11ffcc4

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE qhelp SYSTEM "qhelp.dtd">
2+
<qhelp>
3+
4+
<overview>
5+
<p>When you add an application to a Tomcat server, it will generate a new <code>JSESSIONID</code> when you call <code>request.getSession()</code>
6+
or if you invoke a JSP from a servlet. If cookies are generated without the <code>HttpOnly</code> flag,
7+
an attacker can use a cross-site scripting (XSS) attack to get another user's session ID.
8+
</p>
9+
</overview>
10+
11+
<recommendation>
12+
<p>Tomcat version 7+ automatically sets an <code>HttpOnly</code> flag on all session cookies to
13+
prevent client side scripts from accessing the session ID.
14+
In most situations, you should not override this behavior.</p>
15+
</recommendation>
16+
17+
<example>
18+
<p>The following example shows a Tomcat configuration with <code>useHttpOnly</code> disabled. Usually you should not set this.</p>
19+
20+
<sample src="insecure-web.xml" />
21+
</example>
22+
23+
<references>
24+
<li>
25+
CWE:
26+
<a href="https://cwe.mitre.org/data/definitions/1004.html">Sensitive Cookie Without 'HttpOnly' Flag</a>.
27+
</li>
28+
<li>
29+
OWASP:
30+
<a href="https://www.owasp.org/index.php/HttpOnly">
31+
HttpOnly
32+
</a>.
33+
</li>
34+
</references>
35+
</qhelp>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @name Tomcat config disables 'HttpOnly' flag (XSS risk)
3+
* @description Disabling 'HttpOnly' leaves session cookies vulnerable to an XSS attack.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision medium
7+
* @id java/tomcat-disabled-httponly
8+
* @tags security
9+
* external/cwe/cwe-1004
10+
*/
11+
12+
import java
13+
import semmle.code.xml.WebXML
14+
15+
private class HttpOnlyConfig extends WebContextParameter {
16+
HttpOnlyConfig() { this.getParamName().getValue() = "useHttpOnly" }
17+
18+
string getParamValueElementValue() { result = getParamValue().getValue() }
19+
20+
predicate isHTTPOnlySet() { getParamValueElementValue().toLowerCase() = "false" }
21+
}
22+
23+
from HttpOnlyConfig config
24+
where config.isHTTPOnlySet()
25+
select config,
26+
"httpOnly should be enabled in tomcat config file to help mitigate cross-site scripting (XSS) attacks"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
3+
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
4+
<display-name>Sample Tomcat Web Application</display-name>
5+
<context-param>
6+
<param-name>useHttpOnly</param-name>
7+
<param-value>false</param-value>
8+
</context-param>
9+
</web-app>

0 commit comments

Comments
 (0)