fix(auth): prevent NoSQL injection in login (vuln_id 81) - #249
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
fix(auth): prevent NoSQL injection in login (vuln_id 81)#249devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
| }); | ||
| } else { | ||
| const username = req.body.username; | ||
| const password = req.body.password; |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remediates security finding vuln_id 81 — NoSQL injection in user authentication (CWE-943), a bug in
routes/index.jsloginHandler.Confirmed exploitable path:
POST /loginpassedreq.body.username/req.body.passwordverbatim intoUser.find({ username, password }), so a JSON body like{"username":"admin@snyk.io","password":{"$gt":""}}injected a MongoDB operator and authenticated without the password.Fix:
loginHandlerrejects (401) any credential that is not a primitive string before querying.$eqcomparisons so they can never be interpreted as operators.next(err)instead of being ignored.Reviewer notes / behavior change: requests with non-string
username/passwordnow get 401 instead of a query attempt; valid string logins are unchanged. README andexploits/nosql-exploits.shcomments updated to reflect that ns4/ns5 payloads now return 401.Testing
tests/login-nosql-injection.spec.js(fails before fix):NODE_OPTIONS=--openssl-legacy-provider ./node_modules/.bin/tap tests/login-nosql-injection.spec.js --no-coverage→ 4/4 pass.node --check routes/index.jsNote: this finding duplicates the loginHandler NoSQLi previously fixed in PRs #130, #153, #169, #186, #193, #205, #218, #231 (unmerged); this PR fixes it independently on a fresh branch.
Written by Devin
Devin-Org: engineering
Devin Review