Skip to content

Instantly share code, notes, and snippets.

@Sailias
Created January 13, 2014 17:17
Show Gist options
  • Save Sailias/8404091 to your computer and use it in GitHub Desktop.
Save Sailias/8404091 to your computer and use it in GitHub Desktop.
// Subject to SQL injection
Student.query(
"SELECT * FROM student INNER JOIN course ON course.studentId=student.id WHERE student.id=" + req.param('student_id'),
function(err, students) {
}
)
// uses prepared statements to protect against sql injection
// https://github.com/brianc/node-postgres/wiki/Prepared-Statements#parameterized-queries
Student.query({
text: "SELECT * FROM student INNER JOIN course ON course.studentId=student.id WHERE student.id=$1",
values: [req.param('student_id')],
}, function(err, students) {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment