bug: fix NoSQL operator injection in admin loginHandler - #231
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
bug: fix NoSQL operator injection in admin loginHandler#231devin-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 like{"username":"admin@snyk.io","password":{"$gt":""}}(or{"$gt":""}for both) turned the credential check into an operator query and granted an admin session (CWE-943).loginHandlernow rejects anything that is not a primitive string before touching the DB, and compares with explicit$eqso a nested object can never be interpreted as an operator:errfrom the query is now propagated tonextinstead of being ignored (it previously caused ausers.lengthTypeError).tests/login-nosql-injection.spec.jsstubs the mongoose model with an in-memory collection implementing$eq/$gt/$nesemantics (mongoose 4.2.4 can't talk to a modern mongod) and asserts operator payloads and object usernames get 401 with no session, while valid credentials still redirect to/admin. README andexploits/nosql-exploits.shupdated to reflect that the ns4/ns5 payloads now fail.Written by Devin
Devin-Org: engineering
Devin Review