File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
java/ql/src/experimental/Security/CWE/CWE-1004 Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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"
Original file line number Diff line number Diff line change
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 >
You can’t perform that action at this time.
0 commit comments