Skip to content

Commit 5611bda

Browse files
committed
Python: add test for $accumulator
1 parent 4614b1a commit 5611bda

File tree

1 file changed

+20
-0
lines changed
  • python/ql/test/query-tests/Security/CWE-943-NoSqlInjection/PoC

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ def by_function_arg():
7171
post = posts.find_one({'$expr': {'$function': search}}) # $ result=OK
7272
return show_post(post, author)
7373

74+
@app.route('/byGroup', methods=['GET'])
75+
def by_group():
76+
author = request.args['author']
77+
accumulator = {
78+
"init": 'function() { return "Not found" }',
79+
"accumulate": 'function(state, author) { return (author === "'+author+'") ? author : state }',
80+
"accumulateArgs": ["$author"],
81+
"merge": 'function(state1, state2) { return (state1 === "Not found") ? state2 : state1 }'
82+
}
83+
group = {
84+
"_id": "null",
85+
"author": { "$accumulator": accumulator }
86+
}
87+
# Use `" | "a" === "a` as author
88+
# making the query `this.author === "" | "a" === "a"`
89+
# Found by http://127.0.0.1:5000/byGroup?author=%22%20|%20%22a%22%20===%20%22a
90+
post = posts.aggregate([{ "$group": group }]).next() # $ MISSING: result=BAD
91+
app.logger.error("post", post)
92+
return show_post(post, author)
93+
7494
@app.route('/', methods=['GET'])
7595
def show_routes():
7696
links = []

0 commit comments

Comments
 (0)