Skip to content

Commit 3fb579e

Browse files
committed
Python: add test for type tracking
1 parent 37a4f35 commit 3fb579e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

python/ql/test/query-tests/Security/CWE-943-NoSqlInjection/pymongo_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,24 @@ def bad3():
4343
cursor = collection.find_one({"$where": f"this._id == '${event_id}'"}) #$ result=BAD
4444

4545

46+
@app.route("/bad4")
47+
def bad4():
48+
client = MongoClient("localhost", 27017, maxPoolSize=50)
49+
db = client.get_database(name="localhost")
50+
collection = db.get_collection("collection")
51+
52+
decoded = json.loads(request.args['event_id'])
53+
54+
search = {
55+
"body": decoded,
56+
"args": [ "$event_id" ],
57+
"lang": "js"
58+
}
59+
collection.find_one({'$expr': {'$function': search}}) # $ result=BAD
60+
61+
collection.find_one({'$expr': {'$function': decoded}}) # $ result=BAD
62+
collection.find_one({'$expr': decoded}) # $ result=BAD
63+
collection.find_one(decoded) # $ result=BAD
64+
4665
if __name__ == "__main__":
4766
app.run(debug=True)

0 commit comments

Comments
 (0)