Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edfcf39

Browse files
committed
Python: Add flask tests from internal repo
1 parent ec79bfa commit edfcf39

10 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| / | Function hello |
2+
| /dangerous | Function dangerous |
3+
| /dangerous-with-cfg-split | Function dangerous2 |
4+
| /the/ | Function get |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import python
2+
3+
import semmle.python.web.flask.General
4+
5+
from ControlFlowNode regex, Function func
6+
7+
where flask_routing(regex, func)
8+
9+
select regex.getNode().(StrConst).getText(), func.toString()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:8 | Str | externally controlled string |
2+
| test.py:29 | Attribute() | externally controlled string |
3+
| test.py:35 | Subscript | externally controlled string |
4+
| test.py:36 | None | externally controlled string |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.security.strings.Untrusted
7+
8+
from TaintSink sink, TaintKind kind
9+
where sink.sinks(kind)
10+
select sink.getLocation().toString(), sink.(ControlFlowNode).getNode().toString(), kind
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:22 | Attribute() | flask/MyView.as.view |
2+
| test.py:29 | Attribute | {externally controlled string} |
3+
| test.py:33 | Attribute | {externally controlled string} |
4+
| test.py:35 | Attribute | {externally controlled string} |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.security.strings.Untrusted
7+
8+
9+
from TaintSource src, TaintKind kind
10+
where src.isSourceOf(kind)
11+
select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| test.py:22 | Attribute() | flask/MyView.as.view |
2+
| test.py:25 | the_view | flask/MyView.as.view |
3+
| test.py:29 | Attribute | {externally controlled string} |
4+
| test.py:29 | Attribute() | externally controlled string |
5+
| test.py:33 | Attribute | {externally controlled string} |
6+
| test.py:33 | Subscript | externally controlled string |
7+
| test.py:35 | Attribute | {externally controlled string} |
8+
| test.py:35 | Subscript | externally controlled string |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import python
3+
4+
5+
import semmle.python.web.HttpRequest
6+
import semmle.python.web.HttpResponse
7+
import semmle.python.security.strings.Untrusted
8+
9+
10+
from TaintedNode node
11+
where node.getLocation().getFile().getName().matches("%test.py")
12+
select node.getLocation().toString(), node.getAstNode().toString(), node.getTaintKind()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: --max-import-depth=3 --lang=3 -p ../../../query-tests/Security/lib/
2+
optimize: true
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import flask
2+
3+
from flask import Flask, request
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def hello():
8+
return "Hello World!"
9+
10+
from flask.views import MethodView
11+
12+
class MyView(MethodView):
13+
14+
def get(self, user_id):
15+
if user_id is None:
16+
# return a list of users
17+
pass
18+
else:
19+
# expose a single user
20+
pass
21+
22+
the_view = MyView.as_view('my_view')
23+
24+
app.add_url_rule('/the/', defaults={'user_id': None},
25+
view_func=the_view, methods=['GET',])
26+
27+
@app.route("/dangerous")
28+
def dangerous():
29+
return request.args.get('payload')
30+
31+
@app.route("/dangerous-with-cfg-split")
32+
def dangerous2():
33+
x = request.form['param0']
34+
if request.method == "POST":
35+
return request.form['param1']
36+
return None

0 commit comments

Comments
 (0)