fix: reject MongoDB operator injection in query filter params#1423
Open
theeggorchicken wants to merge 1 commit intoidurar:devfrom
Open
fix: reject MongoDB operator injection in query filter params#1423theeggorchicken wants to merge 1 commit intoidurar:devfrom
theeggorchicken wants to merge 1 commit intoidurar:devfrom
Conversation
The filter and equal query parameters are interpolated directly into MongoDB queries as [filter]: equal, allowing an attacker to pass object values like equal[$regex]=.* or equal[$gt]= to inject arbitrary MongoDB operators. This enables enumeration of any field across any collection that uses paginatedList. Validates that equal is a plain string before including it in the query. Object values (which Express parses from bracket notation) are rejected with a 400 response.
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.
Description
The
filterandequalquery parameters inpaginatedList.js(line 22) get interpolated directly into the MongoDB query as[filter]: equal. Express parses bracket notation in query strings into nested objects, soequal[$regex]=.*becomes{ $regex: ".*" }by the time it hits Mongoose. That turns the filter into an arbitrary MongoDB operator.Vulnerable Lines
File:
backend/src/controllers/middlewaresControllers/createCRUDController/paginatedList.js#L6-L22What could happen
I tested this against a running instance. With
$regex, you can extract every email address in the database:With
$gt, you can enumerate all records by ID:This works against any model that uses
paginatedList-- people, invoices, payments, products.What this PR does
Checks whether
equalis a plain string before including it in the query. If Express parsed it into an object (from bracket notation likeequal[$regex]=.*), the request gets a 400 response instead of passing the operator through to MongoDB.Evidence
Full
curl --trace-asciicaptures showing both$regexand$gtoperator injection: evidence gistRelated Issue
Security fix -- MongoDB operator injection via Express query string parsing.
Steps to Test
npm startor Dockercurl "http://localhost:8888/api/people/list?filter=email&equal[$regex]=.*"with authChecklist