Skip to content

Commit 16fa066

Browse files
committed
JS: Fix false negative in Mongo model
1 parent 3dd5d4d commit 16fa066

File tree

1 file changed

+6
-4
lines changed
  • javascript/ql/lib/semmle/javascript/frameworks

1 file changed

+6
-4
lines changed

javascript/ql/lib/semmle/javascript/frameworks/NoSQL.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ private module MongoDB {
2929
private API::Node getAMongoClient() {
3030
result = API::moduleImport("mongodb").getMember("MongoClient")
3131
or
32-
result = getAMongoDbCallback().getParameter(1) and
33-
not result.getAnImmediateUse().(DataFlow::ParameterNode).getName() = "db" // mongodb v2 provides a `Db` here
32+
// The callback parameter is either a MongoClient or Db depending on the mongodb package version,
33+
// but we just model it as both.
34+
result = getAMongoDbCallback().getParameter(1)
3435
}
3536

3637
/** Gets an API-graph node that refers to a `connect` callback. */
@@ -44,8 +45,9 @@ private module MongoDB {
4445
private API::Node getAMongoDb() {
4546
result = getAMongoClient().getMember("db").getReturn()
4647
or
47-
result = getAMongoDbCallback().getParameter(1) and
48-
not result.getAnImmediateUse().(DataFlow::ParameterNode).getName() = "client" // mongodb v3 provides a `Mongoclient` here
48+
// The callback parameter is either a MongoClient or Db depending on the mongodb package version,
49+
// but we just model it as both.
50+
result = getAMongoDbCallback().getParameter(1)
4951
}
5052

5153
/** Gets a data flow node referring to a MongoDB collection. */

0 commit comments

Comments
 (0)