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 11flask
2- pymongo
2+ pymongo == 3.9
Original file line number Diff line number Diff line change @@ -90,6 +90,21 @@ def by_group():
9090 post = posts .aggregate ([{ "$group" : group }]).next () # $ result=BAD
9191 return show_post (post , author )
9292
93+ # works with pymongo 3.9, `map_reduce` is removed in pymongo 4.0
94+ @app .route ('/byMapReduce' , methods = ['GET' ])
95+ def by_map_reduce ():
96+ author = request .args ['author' ]
97+ mapper = 'function() { emit(this.author, this.author === "' + author + '") }'
98+ reducer = "function(key, values) { return values.some( x => x ) }"
99+ results = posts .map_reduce (mapper , reducer , "results" )
100+ # Use `" | "a" === "a` as author
101+ # making the query `this.author === "" | "a" === "a"`
102+ # Found by http://127.0.0.1:5000/byMapReduce?author=%22%20|%20%22a%22%20===%20%22a
103+ post = results .find_one ({'value' : True }) # $ MISSING: result=BAD
104+ if (post ):
105+ post ["author" ] = post ["_id" ]
106+ return show_post (post , author )
107+
93108@app .route ('/' , methods = ['GET' ])
94109def show_routes ():
95110 links = []
You can’t perform that action at this time.
0 commit comments