fix(security): prevent NoSQL injection from user-controlled data (SonarQube jssecurity:S5147) - #197
Conversation
…be jssecurity:S5147) Co-Authored-By: Joao Esteves <joao.esteves@cognition.ai>
🤖 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:
|
|
SonarQube remediation — issue key What was changed (
Why: the Mongo filter was constructed directly from user-controlled JSON, so a body such as Scope kept minimal: no other vulnerabilities in the file were touched, and the SonarQube issue status was not modified. |
|
|
||
| exports.loginHandler = function (req, res, next) { | ||
| if (typeof req.body.username !== 'string' || typeof req.body.password !== 'string') { | ||
| return res.status(401).send() |
Summary
Remediates SonarQube issue
AZhSVLrd4wErqc9Ey1Y3(rulejssecurity:S5147, BLOCKER) atroutes/index.js:39.loginHandlerpassedreq.body.username/req.body.passwordstraight into a Mongo query. Because Express body parsing yields objects for JSON bodies, a payload like{"username": "a@b.com", "password": {"$gt": ""}}injects a query operator and bypasses authentication.Non-string credentials are now rejected with 401 before the query is built, so operator objects can never reach Mongo. Scoped strictly to this finding; other vulnerabilities in the file are untouched.
Note: an earlier PR (#36) exists on the exact branch name
devin/sonarqube-fix-AZhSVLrd4wErqc9Ey1Y3, so this PR uses a timestamped branch.Link to Devin session: https://app.devin.ai/sessions/dea6f4e57ffd45e38b2a35ce70907922
Requested by: @joao-cognition
Devin Review