Skip to content

Commit f24f03e

Browse files
committed
JS: add mongodb .connect tests
1 parent e61f522 commit f24f03e

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let dbClient = require("mongodb").MongoClient,
2+
db = null;
3+
module.exports = {
4+
db: () => {
5+
return db;
6+
},
7+
connect: fn => {
8+
dbClient.connect(process.env.DB_URL, {}, (err, client) => {
9+
db = client.db(process.env.DB_NAME);
10+
return fn(err);
11+
});
12+
}
13+
};

javascript/ql/test/query-tests/Security/CWE-089/untyped/mongodb.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,22 @@ app.post('/documents/find', (req, res) => {
6565
doc.find(query);
6666
});
6767
});
68+
69+
app.post("/logs/count-by-tag", (req, res) => {
70+
let tag = req.query.tag;
71+
72+
MongoClient.connect(process.env.DB_URL, {}, (err, client) => {
73+
client
74+
.db(process.env.DB_NAME)
75+
.collection("logs")
76+
// NOT OK: query is tainted by user-provided object value
77+
.count({ tags: tag });
78+
});
79+
80+
let importedDbo = require("./dbo.js");
81+
importedDbo
82+
.db()
83+
.collection("logs")
84+
// NOT OK: query is tainted by user-provided object value
85+
.count({ tags: tag });
86+
});

0 commit comments

Comments
 (0)