Skip to content

Commit e885f1f

Browse files
Add documentation
1 parent 983bdb9 commit e885f1f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>Constructing cookies from user input can allow an attacker to control a user's cookie. Additionally, if the cookie is set using a raw header, cookie attributes such as the <code>Secure</code> flag may be controlled by an attacker.
8+
</p>
9+
</overview>
10+
11+
<recommendation>
12+
<p>Do not use raw user input to construct cookies.</p>
13+
</recommendation>
14+
15+
<example>
16+
<p>In the following cases, a cookie is constructed for a Flask response using user input. The first uses <code>set_cookie</code>,
17+
and the second sets a cookie's raw value through the <code>set-cookie</code> header.</p>
18+
<sample src="examples/CookieInjection.py" />
19+
</example>
20+
21+
<references>
22+
</references>
23+
24+
</qhelp>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* @name Construction of a cookie using user-supplied input.
33
* @description Constructing cookies from user input may allow an attacker to perform a Cookie Poisoning attack.
44
* @kind path-problem
5-
* @problem.severity error
5+
* @problem.severity warning
66
* @precision high
7+
* @security-severity 5.0
78
* @id py/cookie-injection
89
* @tags security
910
* external/cwe/cwe-614
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from flask import request, make_response
2+
3+
4+
@app.route("/1")
5+
def set_cookie():
6+
resp = make_response()
7+
resp.set_cookie(request.args["name"], # BAD: User input is used to set the cookie's name and value
8+
value=request.args["name"])
9+
return resp
10+
11+
12+
@app.route("/2")
13+
def set_cookie_header():
14+
resp = make_response()
15+
resp.headers['Set-Cookie'] = f"{request.args['name']}={request.args['name']};" # BAD: User input is used to set the raw cookie header.
16+
return resp

0 commit comments

Comments
 (0)