forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrackOrder.js
26 lines (23 loc) · 945 Bytes
/
trackOrder.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
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const utils = require('../lib/utils')
const challenges = require('../data/datacache').challenges
const db = require('../data/mongodb')
module.exports = function trackOrder () {
return (req, res) => {
const id = utils.disableOnContainerEnv() ? String(req.params.id).replace(/[^\w-]+/g, '') : req.params.id
utils.solveIf(challenges.reflectedXssChallenge, () => { return utils.contains(id, '<iframe src="javascript:alert(`xss`)">') })
db.orders.find({ $where: `this.orderId === '${id}'` }).then(order => {
const result = utils.queryResultToJson(order)
utils.solveIf(challenges.noSqlOrdersChallenge, () => { return result.data.length > 1 })
if (result.data[0] === undefined) {
result.data[0] = { orderId: id }
}
res.json(result)
}, () => {
res.status(400).json({ error: 'Wrong Param' })
})
}
}