-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
36 lines (28 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const protect = require("@aikidosec/firewall/cloud-function");
const { MongoClient } = require("mongodb");
const { Users, User } = require("./users");
require("@aikidosec/firewall/nopp");
exports.getToken = protect(async (req, res) => {
const client = new MongoClient("mongodb://root:[email protected]:27017");
await client.connect();
const users = new Users(client);
const user = await users.findBy("[email protected]", "password");
if (!user) {
// Ensure a user exists for testing
await users.persist(new User("[email protected]", "password"));
}
if (!req.body.username || !req.body.password) {
return res.sendStatus(400);
}
// This is just for demo purposes, normally you'd use bcrypt or something
// This is a vulnerability, which can be abused for demo purposes
// If password is { $gt: "" } then it will match any password
const actualUser = await users.findBy(req.body.username, req.body.password);
if (!actualUser) {
return res.sendStatus(401);
}
return res.send({
token: "123",
success: true,
});
});