fix(jssecurity:S5147): prevent database query injection from user input in routes/index.js [SonarQube AZhSVLrd4wErqc9Ey1Y3] - #36
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Remediation details — SonarQube
|
CI status analysis (issue
|
095e9a6 to
cd03716
Compare
Remediation details — SonarQube
|
cd03716 to
3544e2c
Compare
Remediation — SonarQube
|
3544e2c to
7826bb9
Compare
SonarQube Vulnerability Fix: NoSQL Injection (S5147)SonarQube Issue Key: What was changedIn Fix appliedBoth User.find({ username: String(req.body.username), password: String(req.body.password) }, ...)
|
7826bb9 to
0332e86
Compare
SonarQube Vulnerability RemediationSonarQube Issue Key: What was changedIn Fix appliedAdded explicit |
|
|
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
1 similar comment
|
Devin is archived and cannot be woken up. Please unarchive Devin if you want to continue using it. |
SonarQube
|
Verification — SonarQube
|
SonarQube
|
SonarQube
|
|
Remediation for SonarQube issue AZhSVLrd4wErqc9Ey1Y3 (rule What was wrong: What changed:
Scope: only the login handler in |
Remediation verification — SonarQube
|
…be AZhSVLrd4wErqc9Ey1Y3) Co-Authored-By: Joao Esteves <joao.esteves@cognition.ai>
c88c116 to
d6b66e5
Compare
| if (validator.isEmail(req.body.username)) { | ||
| User.find({ username: req.body.username, password: req.body.password }, function (err, users) { | ||
| if (typeof req.body.username === 'string' && typeof req.body.password === 'string' && validator.isEmail(req.body.username)) { | ||
| User.find({ username: { $eq: req.body.username }, password: { $eq: req.body.password } }, function (err, users) { |
Remediation summary — SonarQube
|
Summary
Remediates SonarQube issue AZhSVLrd4wErqc9Ey1Y3 (rule
jssecurity:S5147, BLOCKER — NoSQL injection) atroutes/index.js:39.Vulnerability:
loginHandlerpassedreq.body.username/req.body.passworddirectly intoUser.find(...). Express's body parser produces objects (not just strings) from JSON or bracketed form input, so an attacker could send{"username": "admin@[REDACTED SECRET].com", "password": {"$gt": ""}}— the$gtoperator matches any stored password, bypassing authentication (MongoDB operator injection).Fix (minimal):
Non-string inputs (objects carrying query operators) now fail the type check and receive a 401;
$eqadditionally guarantees literal equality matching even if a non-string ever reached the query. Behavior for legitimate string credentials is unchanged; no other code in this intentionally-vulnerable demo app was touched.Testing
node --check routes/index.jspasses.npm testruns a Snyk dependency scan requiring Snyk auth, and running the app end-to-end requires MongoDB, so functional verification was limited to review of the query construction.Devin-Org: engineering
Link to Devin session: https://app.devin.ai/sessions/9f4991cf8ba14b10a8cc158d7a36dfcd
Open in Devin Desktop: https://app.devin.ai/desktop/session/9f4991cf8ba14b10a8cc158d7a36dfcd?variant=devin
Requested by: @joao-cognition