File tree Expand file tree Collapse file tree
python/ql/test/query-tests/Security/CWE-943-NoSqlInjection/PoC Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ])
7595def show_routes ():
7696 links = []
You can’t perform that action at this time.
0 commit comments