Skip to content

Commit b3258ce

Browse files
committed
Add CookieInjection sample and .qhelp
1 parent d7a7946 commit b3258ce

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
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 true():
6+
resp = make_response()
7+
resp.set_cookie(request.args["name"],
8+
value=request.args["name"])
9+
return resp
10+
11+
12+
@app.route("/2")
13+
def flask_make_response():
14+
resp = make_response("hello")
15+
resp.headers['Set-Cookie'] = f"{request.args['name']}={request.args['name']};"
16+
return resp
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>Constructing cookies from user input may allow an attacker to perform a Cookie Poisoning attack.
8+
It is possible, however, to perform other parameter-like attacks through cookie poisoning techniques,
9+
such as SQL Injection, Directory Traversal, or Stealth Commanding, etc. Additionally,
10+
cookie injection may relate to attempts to perform Access of Administrative Interface.
11+
</p>
12+
</overview>
13+
14+
<recommendation>
15+
<p>Do not use raw user input to construct cookies.</p>
16+
</recommendation>
17+
18+
<example>
19+
<p>This example shows two ways of adding a cookie to a Flask response. The first way uses <code>set_cookie</code>'s
20+
and the second sets a cookie's raw value through a header, both using user-supplied input.</p>
21+
<sample src="CookieInjection.py" />
22+
</example>
23+
24+
<references>
25+
<li>Imperva: <a href="https://docs.imperva.com/bundle/on-premises-knowledgebase-reference-guide/page/cookie_injection.htm">Cookie injection</a>.</li>
26+
</references>
27+
28+
</qhelp>

0 commit comments

Comments
 (0)