Skip to content

Commit 4f68a17

Browse files
committed
Write documentation and example
1 parent c8983be commit 4f68a17

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from flask import Flask, request, make_response, Response
2+
3+
4+
@app.route("/true")
5+
def true():
6+
resp = make_response()
7+
resp.set_cookie("name", value="value", secure=True)
8+
return resp
9+
10+
11+
@app.route("/flask_make_response")
12+
def flask_make_response():
13+
resp = make_response("hello")
14+
resp.headers['Set-Cookie'] = "name=value; Secure;"
15+
return resp
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>Failing to set the 'secure' flag on a cookie can cause it to be sent in cleartext.
8+
This makes it easier for an attacker to intercept.</p>
9+
</overview>
10+
11+
<recommendation>
12+
<p>Always set <code>secure</code> to <code>True</code> or add "; Secure;" to the cookie's raw value.</p>
13+
</recommendation>
14+
15+
<example>
16+
<p>This example shows two ways of adding a cookie to a Flask response. The first way uses <code>set_cookie</code>'s
17+
secure flag and the second adds the secure flag in the cookie's raw value.</p>
18+
<sample src="InsecureCookie.py" />
19+
</example>
20+
21+
<references>
22+
<li>Detectify: <a href="https://support.detectify.com/support/solutions/articles/48001048982-cookie-lack-secure-flag">Cookie lack Secure flag</a>.</li>
23+
<li>PortSwigger: <a href="https://portswigger.net/kb/issues/00500200_tls-cookie-without-secure-flag-set">TLS cookie without secure flag set</a>.</li>
24+
</references>
25+
26+
</qhelp>

0 commit comments

Comments
 (0)