Skip to content

Commit 6931d9a

Browse files
authored
Merge pull request github#5785 from edvraa/httponlyjs
Approved by esbena
2 parents 4831998 + 6fa2f1e commit 6931d9a

File tree

14 files changed

+774
-169
lines changed

14 files changed

+774
-169
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>Cookies without <code>HttpOnly</code> flag are accessible to JavaScript running in the same origin. In case of
7+
Cross-Site Scripting (XSS) vulnerability the cookie can be stolen by malicious script.</p>
8+
</overview>
9+
<recommendation>
10+
11+
<p>Protect sensitive cookies, such as those related to authentication, by setting <code>HttpOnly</code> to <code>true</code> to make
12+
them not accessible to JavaScript.</p>
13+
14+
</recommendation>
15+
16+
<references>
17+
18+
<li>Production Best Practices: Security:<a href="https://expressjs.com/en/advanced/best-practice-security.html#use-cookies-securely">Use cookies securely</a>.</li>
19+
<li>NodeJS security cheat sheet:<a href="https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html#set-cookie-flags-appropriately">Set cookie flags appropriately</a>.</li>
20+
<li>express-session:<a href="https://github.com/expressjs/session#cookiehttponly">cookie.httpOnly</a>.</li>
21+
<li>cookie-session:<a href="https://github.com/expressjs/cookie-session#cookie-options">Cookie Options</a>.</li>
22+
<li><a href="https://expressjs.com/en/api.html#res.cookie">express response.cookie</a>.</li>
23+
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a>.</li>
24+
</references>
25+
</qhelp>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name 'HttpOnly' attribute is not set to true
3+
* @description Omitting the 'HttpOnly' attribute for security sensitive cookie data allows
4+
* malicious JavaScript to steal it in case of XSS vulnerabilities. Always set
5+
* 'HttpOnly' to 'true' for authentication related cookies to make them
6+
* inaccessible from JavaScript.
7+
* @kind problem
8+
* @problem.severity warning
9+
* @precision high
10+
* @id js/cookie-httponly-not-set
11+
* @tags security
12+
* external/cwe/cwe-1004
13+
*/
14+
15+
import javascript
16+
import experimental.semmle.javascript.security.InsecureCookie::Cookie
17+
18+
from Cookie cookie
19+
where cookie.isAuthNotHttpOnly()
20+
select cookie, "Cookie attribute 'HttpOnly' is not set to true for this sensitive cookie."

javascript/ql/src/experimental/Security/CWE-614/InsecureCookie.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import javascript
14-
import InsecureCookie::Cookie
14+
import experimental.semmle.javascript.security.InsecureCookie::Cookie
1515

1616
from Cookie cookie
1717
where not cookie.isSecure()

javascript/ql/src/experimental/Security/CWE-614/InsecureCookie.qll

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)