Skip to content

Commit df5569f

Browse files
Add documentation
1 parent 32fbe52 commit df5569f

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>Cookies without the <code>Secure</code> flag set may be transmittd using HTTP instead of HTTPS, which leaves it vulnerable to being read by a third party.</p>
8+
<p>Cookies without the <code>HttpOnly</code> flag set are accessible to JavaScript running in the same origin. In case of a Cross-Site Scripting (XSS) vulnerability, the cookie can be stolen by a malicious script.</p>
9+
<p>Cookies with the <code>SameSite</code> attribute set to <code>'None'</code> will be sent with cross-origin requests, which can be controlled by third-party JavaScript code and allow for Cross-Site Request Forgery (CSRF) attacks.</p>
10+
</overview>
11+
12+
<recommendation>
13+
<p>Always set <code>secure</code> to <code>True</code> or add "; Secure;" to the cookie's raw value.</p>
14+
<p>Always set <code>httponly</code> to <code>True</code> or add "; HttpOnly;" to the cookie's raw value.</p>
15+
<p>Always set <code>samesite</code> to <code>Lax</code> or <code>Strict</code>, or add "; SameSite=Lax;", or
16+
"; Samesite=Strict;" to the cookie's raw header value.</p>
17+
</recommendation>
18+
19+
<example>
20+
<p>In the following examples, the cases marked GOOD show secure cookie attributes being set; whereas in the cases marked BAD they are not set.</p>
21+
<sample src="examples/InsecureCookie.py" />
22+
</example>
23+
24+
<references>
25+
<li>Detectify: <a href="https://support.detectify.com/support/solutions/articles/48001048982-cookie-lack-secure-flag">Cookie lack Secure flag</a>.</li>
26+
<li>PortSwigger: <a href="https://portswigger.net/kb/issues/00500200_tls-cookie-without-secure-flag-set">TLS cookie without secure flag set</a>.</li>
27+
</references>
28+
29+
</qhelp>

python/ql/src/Security/CWE-614/InsecureCookie.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* @description Insecure cookies may be sent in cleartext, which makes them vulnerable to
44
* interception.
55
* @kind problem
6-
* @problem.severity error
6+
* @problem.severity warning
77
* @security-severity 5.0
88
* @precision high
99
* @id py/insecure-cookie
1010
* @tags security
1111
* external/cwe/cwe-614
12+
* external/cwe/cwe-1004
13+
* external/cwe/cwe-1275
1214
*/
1315

1416
import python
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask, request, make_response, Response
2+
3+
4+
@app.route("/good1")
5+
def good1():
6+
resp = make_response()
7+
resp.set_cookie("name", value="value", secure=True, httponly=True, samesite='Strict') # GOOD: Attributes are securely set
8+
return resp
9+
10+
11+
@app.route("/good2")
12+
def good2():
13+
resp = make_response()
14+
resp.headers['Set-Cookie'] = "name=value; Secure; HttpOnly; SameSite=Strict" # GOOD: Attributes are securely set
15+
return resp
16+
17+
@app.route("/bad1")
18+
resp = make_response()
19+
resp.set_cookie("name", value="value", samesite='None') # BAD: the SameSite attribute is set to 'None'; and the 'Secure' and 'HttpOnly' attributes are set to False by default.
20+
return resp

0 commit comments

Comments
 (0)