Created
January 13, 2014 17:17
-
-
Save Sailias/8404091 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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