Skip to content

Commit 2a7b593

Browse files
committed
Python: Fix QL alerts
1 parent eb1be08 commit 2a7b593

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

python/ql/lib/semmle/python/frameworks/BSon.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import semmle.python.dataflow.new.DataFlow
77
private import semmle.python.Concepts
88
private import semmle.python.ApiGraphs
99

10-
module BSon {
10+
private module BSon {
1111
/**
1212
* ObjectId returns a string representing an id.
1313
* If at any time ObjectId can't parse it's input (like when a tainted dict in passed in),

python/ql/lib/semmle/python/frameworks/PyMongo.qll

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private module PyMongo {
144144
private class MongoMapReduceQuery extends API::CallNode, NoSqlExecution::Range {
145145
MongoMapReduceQuery() { this = mongoCollection().getMember("map_reduce").getACall() }
146146

147-
override DataFlow::Node getQuery() { result in [this.getArgByName("query")] }
147+
override DataFlow::Node getQuery() { result = this.getArgByName("query") }
148148

149149
override predicate interpretsDict() { any() }
150150

@@ -178,19 +178,20 @@ private module PyMongo {
178178
* See https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function
179179
*/
180180
private class FunctionQueryOperator extends DataFlow::Node, Decoding::Range {
181-
API::Node dictionary;
182181
DataFlow::Node query;
183182

184183
FunctionQueryOperator() {
185-
dictionary =
186-
mongoCollection()
187-
.getMember(mongoCollectionMethodName())
188-
.getACall()
189-
.getParameter(0)
190-
.getASubscript*()
191-
.getSubscript("$function") and
192-
query = dictionary.getSubscript("body").asSink() and
193-
this = dictionary.asSink()
184+
exists(API::Node dictionary |
185+
dictionary =
186+
mongoCollection()
187+
.getMember(mongoCollectionMethodName())
188+
.getACall()
189+
.getParameter(0)
190+
.getASubscript*()
191+
.getSubscript("$function") and
192+
query = dictionary.getSubscript("body").asSink() and
193+
this = dictionary.asSink()
194+
)
194195
}
195196

196197
override DataFlow::Node getAnInput() { result = query }
@@ -208,19 +209,20 @@ private module PyMongo {
208209
* See https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator
209210
*/
210211
private class AccumulatorQueryOperator extends DataFlow::Node, Decoding::Range {
211-
API::Node dictionary;
212212
DataFlow::Node query;
213213

214214
AccumulatorQueryOperator() {
215-
dictionary =
216-
mongoCollection()
217-
.getMember("aggregate")
218-
.getACall()
219-
.getParameter(0)
220-
.getASubscript*()
221-
.getSubscript("$accumulator") and
222-
query = dictionary.getSubscript(["init", "accumulate", "merge", "finalize"]).asSink() and
223-
this = dictionary.asSink()
215+
exists(API::Node dictionary |
216+
dictionary =
217+
mongoCollection()
218+
.getMember("aggregate")
219+
.getACall()
220+
.getParameter(0)
221+
.getASubscript*()
222+
.getSubscript("$accumulator") and
223+
query = dictionary.getSubscript(["init", "accumulate", "merge", "finalize"]).asSink() and
224+
this = dictionary.asSink()
225+
)
224226
}
225227

226228
override DataFlow::Node getAnInput() { result = query }

0 commit comments

Comments
 (0)