I'm using Sequelize with Node.js/Express and I'm not sure how to escape with Sequelize in the where part.
var sequelize = ...;
var productId = 5; var productName = "test";
var product = sequelize.define('product',findAll({
where: {
$or: [
{productId: this.mysql.escapeId(productId)},
{productName: {$like: this.mysql.escapeId('%' + productName + '%')}},
]
}
})
.then(result => ...);
This is not working, I obtain the bellowing query :
SELECT `productId`, `productName` FROM `product` AS `product` WHERE (`product`.`productId` = '`5`' OR `product`.`productName` LIKE '\'%test%\'' ORDER BY `product`.`productId` ASC
which give me nothing as results. So how to escape with Sequelize ? I also tried the function Sequelize.escape, but I got the error "TypeError: Sequelize.escape is not a function".
And if there's no need to escape the values thanks to Sequelize, I don't understand how it will stay safe from a SQL injection attack. Example : productId = '5; DELETE * FROM SOMETHING;'
Thanks a lot for your help !
Have a good day,
vanessa