forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.js
35 lines (31 loc) · 1.04 KB
/
product.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
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
/* jslint node: true */
const utils = require('../lib/utils')
const insecurity = require('../lib/insecurity')
const challenges = require('../data/datacache').challenges
module.exports = (sequelize, { STRING, DECIMAL }) => {
const Product = sequelize.define('Product', {
name: STRING,
description: {
type: STRING,
set (description) {
if (!utils.disableOnContainerEnv()) {
utils.solveIf(challenges.restfulXssChallenge, () => { return utils.contains(description, '<iframe src="javascript:alert(`xss`)">') })
} else {
description = insecurity.sanitizeSecure(description)
}
this.setDataValue('description', description)
}
},
price: DECIMAL,
deluxePrice: DECIMAL,
image: STRING
}, { paranoid: true })
Product.associate = ({ Basket, BasketItem }) => {
Product.belongsToMany(Basket, { through: BasketItem, foreignKey: { name: 'ProductId', noUpdate: true } })
}
return Product
}