Skip to content

Commit

Permalink
Modify S3649(js): Fix code samples (#3759)
Browse files Browse the repository at this point in the history
  • Loading branch information
loris-s-sonarsource authored Mar 13, 2024
1 parent a1a88a2 commit c8fc3ff
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rules/S3649/javascript/how-to-fix-it/sequelize.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ include::../../common/fix/code-rationale.adoc[]
async function index(req, res) {
const { db, User } = req.app.get('sequelize');
const user = req.query.user;
const pass = req.query.pass;
let loggedInUser = await db.query(
`SELECT * FROM users WHERE user = '${req.query.user}' AND pass = '${req.query.pass}'`,
`SELECT * FROM users WHERE user = '${user}' AND pass = '${pass}'`,
{
model: User,
}
); // Noncompliant
res.send(JSON.stringify(loggedInUser));
res.end();
}}
}
----

==== Compliant solution
Expand All @@ -30,8 +33,8 @@ async function index(req, res) {
async function index(req, res) {
const { db, User, QueryTypes } = req.app.get('sequelize');
let user = req.query.user;
let pass = req.query.pass;
const user = req.query.user;
const pass = req.query.pass;
let loggedInUser = await db.query(
`SELECT * FROM users WHERE user = $user AND pass = $pass`,
Expand Down

0 comments on commit c8fc3ff

Please sign in to comment.