Skip to content

Commit 0ca4f24

Browse files
committed
Merge tests and update .expected
1 parent a5009ef commit 0ca4f24

19 files changed

+288
-493
lines changed

python/ql/test/experimental/query-tests/Security/CWE-943/NoSQLInjection.expected

Lines changed: 136 additions & 136 deletions
Large diffs are not rendered by default.

python/ql/test/experimental/query-tests/Security/CWE-943/flask_mongoengine_get_db_bad.py renamed to python/ql/test/experimental/query-tests/Security/CWE-943/flask_mongoengine_bad.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ class Movie(db.Document):
1414
Movie(title='test').save()
1515

1616

17-
@app.route("/")
18-
def home_page():
17+
@app.route("/subclass_objects")
18+
def subclass_objects():
19+
unsafe_search = request.args['search']
20+
json_search = json.loads(unsafe_search)
21+
22+
return Movie.objects(__raw__=json_search)
23+
24+
@app.route("/get_db_find")
25+
def get_db_find():
1926
unsafe_search = request.args['search']
2027
json_search = json.loads(unsafe_search)
2128

2229
retrieved_db = db.get_db()
23-
data = retrieved_db["Movie"].find({'name': json_search})
30+
return retrieved_db["Movie"].find({'name': json_search})
2431

2532
# if __name__ == "__main__":
2633
# app.run(debug=True)

python/ql/test/experimental/query-tests/Security/CWE-943/flask_mongoengine_db_document_subclass_bad.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

python/ql/test/experimental/query-tests/Security/CWE-943/flask_mongoengine_db_document_subclass_good.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

python/ql/test/experimental/query-tests/Security/CWE-943/flask_mongoengine_get_db_good.py renamed to python/ql/test/experimental/query-tests/Security/CWE-943/flask_mongoengine_good.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ class Movie(db.Document):
1515
Movie(title='test').save()
1616

1717

18-
@app.route("/")
19-
def home_page():
18+
@app.route("/subclass_objects")
19+
def subclass_objects():
20+
unsafe_search = request.args['search']
21+
json_search = json.loads(unsafe_search)
22+
safe_search = sanitize(json_search)
23+
24+
return Movie.objects(__raw__=safe_search)
25+
26+
@app.route("/get_db_find")
27+
def get_db_find():
2028
unsafe_search = request.args['search']
2129
json_search = json.loads(unsafe_search)
2230
safe_search = sanitize(json_search)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from flask import Flask, request
2+
import mongoengine as me
3+
from mongoengine.connection import get_db, connect
4+
import json
5+
6+
app = Flask(__name__)
7+
8+
9+
class Movie(me.Document):
10+
title = me.StringField(required=True)
11+
12+
13+
Movie(title='test').save()
14+
15+
16+
@app.route("/connect_find")
17+
def connect_find():
18+
unsafe_search = request.args['search']
19+
json_search = json.loads(unsafe_search)
20+
21+
db = me.connect('mydb')
22+
return db.movie.find({'name': json_search})
23+
24+
@app.route("/connection_connect_find")
25+
def connection_connect_find():
26+
unsafe_search = request.args['search']
27+
json_search = json.loads(unsafe_search)
28+
29+
db = connect('mydb')
30+
return db.movie.find({'name': json_search})
31+
32+
@app.route("/get_db_find")
33+
def get_db_find():
34+
unsafe_search = request.args['search']
35+
json_search = json.loads(unsafe_search)
36+
37+
db = me.get_db()
38+
return db.movie.find({'name': json_search})
39+
40+
@app.route("/connection_get_db_find")
41+
def connection_get_db_find():
42+
unsafe_search = request.args['search']
43+
json_search = json.loads(unsafe_search)
44+
45+
db = get_db()
46+
return db.movie.find({'name': json_search})
47+
48+
@app.route("/subclass_objects")
49+
def subclass_objects():
50+
unsafe_search = request.args['search']
51+
json_search = json.loads(unsafe_search)
52+
53+
return Movie.objects(__raw__=json_search)
54+
55+
@app.route("/subscript_find")
56+
def subscript_find():
57+
unsafe_search = request.args['search']
58+
json_search = json.loads(unsafe_search)
59+
60+
db = me.connect('mydb')
61+
return db['movie'].find({'name': json_search})
62+
63+
# if __name__ == "__main__":
64+
# app.run(debug=True)

python/ql/test/experimental/query-tests/Security/CWE-943/mongoengine_connect_bad.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

python/ql/test/experimental/query-tests/Security/CWE-943/mongoengine_connect_good.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

python/ql/test/experimental/query-tests/Security/CWE-943/mongoengine_connect_via_connection_bad.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

python/ql/test/experimental/query-tests/Security/CWE-943/mongoengine_connect_via_connection_good.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)