Fix NoSQL operator injection in login handler - #238
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Fix NoSQL operator injection in login handler#238devin-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
POST /loginpassedreq.body.username/req.body.passwordstraight intoUser.find(...), so a JSON body could smuggle Mongo query operators and authenticate as admin without a password ({"username":"admin@snyk.io","password":{"$gt":""}}). CWE-943.loginHandlernow rejects any credential that is not a primitive string before querying, and wraps both values in explicit$eqcomparisons so an object payload can never be interpreted as a query operator:errfrom the query is now propagated tonextinstead of being ignored.tests/login-nosql-injection.spec.jscovers$gt/$ne/$regex/ array payloads on both fields (all 401, no session), a wrong password, and a successful real login. The README andexploits/nosql-exploits.shnotes for these payloads were updated to say they are now rejected.Note: the scan finding was filed against
COG-GTM/2025-Federal-Agency-AI-Use-Case-Inventory, but that repo contains only CSV/XLSX inventory data — the referenced code (CSV vulnerability inventory, reponodejs-goof, vuln_id 81) lives here, so the fix is opened againstnodejs-goof.Written by Devin
Devin-Org: engineering
Devin Review