Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
SQL Injection mssql Node.js

I'm trying to prevent an SQL Injection in my Node.js Backend. I'm using the mssql package, i was doing some tests and i found that if in a parameter there's the character ' the query doesn't work (obviously).

sql.connect(sqlConfig, function (err) {
    str_query = 'SELECT * FROM table WHERE notes= '+req.query.notes+'';
    if (err) console.log(err);
       
    var request = new sql.Request();

    // query to the database and get the records
    request.query(str_query, function (err, recordset) {
    //here do things 

} 

How i can prevent this ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is untested but here's how I would do it.

Here's a bit of information about what's going on from google.

Parameterized queries force the developer to first define all the SQL code, and then pass in each parameter to the query later. This coding style allows the database to distinguish between code and data, regardless of what user input is supplied.

sql.connect(sqlConfig, function (err) {
    str_query = 'SELECT * FROM table WHERE notes=?';
    if (err) console.log(err);
       
    var request = new sql.Request();

    // query to the database and get the records
    request.query(str_query, [req.query.notes] , function (err, recordset) {
    //here do things 

} 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!