Detect Mongoose NoSQL Injection via Unsanitized countDocuments (CVE-2026-125120) in Google Chronicle
Detects potential exploitation and the vulnerable-condition footprint of CVE-2026-125120, a NoSQL injection (CWE-943) in the Mongoose ODM for MongoDB. The `sanitizeFilter` option, which strips attacker-supplied query operators (e.g. `$where`, `$gt`, `$ne`, `$regex`) from filter objects, was not applied to the `countDocuments()` code path. An application that enabled `sanitizeFilter` as a defense and passed user-controlled input into `Model.countDocuments(filter)` would still be injectable, allowing query-operator injection to bypass authentication checks, enumerate data via boolean/blind count oracles, or trigger server-side JavaScript evaluation. Affects mongoose < 6.13.11, 7.0.0-7.8.11, 8.0.0-8.24.2, and 9.0.0-9.9.1. Because exploitation occurs inside the Node.js process and is visible primarily as anomalous HTTP request bodies and MongoDB query shapes, detection correlates web/application logs (operator-laden JSON parameters) with MongoDB command logs (count operations containing injected operators) and inventory signals for vulnerable mongoose package versions.
MITRE ATT&CK
YARA-L Detection Query
// df00tech DF00-5bf92bc4d1 · https://df00tech.com/detections/CVE-2026-125120 · licence: https://df00tech.com/detections/licence
rule mongoose_nosql_injection_countdocuments_cve_2026_125120 {
meta:
author = "Argus Detection Platform"
description = "NoSQL operator injection in HTTP requests targeting Mongoose sanitizeFilter bypass"
severity = "HIGH"
cve = "CVE-2026-125120"
events:
$e.metadata.event_type = "NETWORK_HTTP"
(
re.regex($e.network.http.response.body, `\$where|\$ne|\$gt|\$regex|\$function|\$expr`) nocase or
re.regex($e.target.url, `%24where|%24ne|\$where|\$ne|\$regex`) nocase
)
$ip = $e.principal.ip
match:
$ip over 10m
condition:
#e >= 3
} YARA-L rule grouping HTTP events per source IP that contain MongoDB operators in body or URL, indicating NoSQL-injection attempts against Mongoose-backed services.
Data Sources
Required Tables
False Positives & Tuning
- Operator-accepting filter APIs.
- Authorized scanners generating operator payloads.
- QA/staging HTTP traffic.
Other platforms for CVE-2026-125120
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are further down this page.
- Test 1 Operator injection into count endpoint via JSON body
Expected signal: Web/app access log entry with request body containing the $ne operator and a MongoDB count command log with an injected filter.
- Test 2 Query-string operator injection (blind count oracle)
Expected signal: Web log with URL-encoded %24gt operator in the query string.
- Test 3 Server-side JavaScript injection via $where in count filter
Expected signal: Application and MongoDB logs showing a count operation with a $where expression.
References (5)
- https://github.com/Automattic/mongoose/security/advisories/GHSA-pcrw-h46h-c93h
- https://nvd.nist.gov/vuln/detail/CVE-2026-125120
- https://github.com/advisories/GHSA-pcrw-h46h-c93h
- https://github.com/Automattic/mongoose/commit/7e912af3fac52cb0eea4cd71e24d65318916831a
- https://github.com/Automattic/mongoose/releases/tag/8.24.3
Response Playbook
Triage
- Confirm whether the targeted application uses Mongoose and relies on `sanitizeFilter` as a NoSQL-injection defense; grep the app's package-lock/yarn.lock for an affected mongoose version (< 6.13.11, 7.x < 7.8.12, 8.x < 8.24.3, 9.x < 9.9.2).
- Extract the full offending request (URL, headers, body) from the alert and identify which endpoint and parameter carried the MongoDB operator; determine whether that parameter flows into a `countDocuments()` call.
- Correlate the source IP against authentication and WAF logs to decide whether the traffic is an authorized scanner, a known integration, or an unexpected external actor.
- Review MongoDB command/profiler logs for the same time window for `count` operations whose filter contains injected operators (`$where`, `$ne`, `$regex`, `$function`).
Containment
- Deploy a WAF/reverse-proxy rule to reject request bodies and query parameters containing raw `$`-prefixed MongoDB operators on affected endpoints until the library is patched.
- Upgrade mongoose to the fixed release for the running major (6.13.11 / 7.8.12 / 8.24.3 / 9.9.2) and redeploy; as a stopgap, add explicit server-side input validation/casting before any `countDocuments(filter)` call.
- If active data enumeration is confirmed, rotate any secrets or session tokens that could have been exposed via a count-based blind oracle and restrict database account privileges.
Evidence Collection
- Preserve raw web/WAF access logs containing the operator payloads and the correlated MongoDB profiler/command logs showing the injected count queries.
- Capture the application's dependency manifest (package-lock.json / yarn.lock) and running process version to document the exact vulnerable mongoose build.
- Snapshot relevant application logs and any server-side JavaScript evaluation errors (from `$where`/`$function`) for timeline reconstruction.
Escalation Criteria
- !Escalate to incident response if MongoDB logs confirm injected count operators returned attacker-controlled boolean oracles indicating successful data enumeration or auth bypass.
- !Escalate if the injection reached a `$where`/`$function` server-side JS path, indicating potential code-evaluation impact beyond data disclosure.
- !Escalate to application owners and change management to expedite the mongoose upgrade when a vulnerable version is confirmed in production.
Investigation Guide
Forensic Artifacts
- >
Web/WAF access logs with `$`-prefixed MongoDB operators in query strings or JSON bodies. - >
MongoDB profiler/command audit entries showing `count`/`countDocuments` filters containing injected operators. - >
Application dependency lockfile recording the vulnerable mongoose version.
Tuning Guidance
First inventory which application endpoints legitimately accept MongoDB operator syntax and allowlist them, since those will generate benign matches. Lower the per-IP count threshold in low-traffic environments and raise it where operator-based filter APIs are common. Prioritize alerts that correlate a web-layer operator payload with a matching MongoDB count operation in the same time window, and deprioritize traffic attributable to authorized scanners by source IP.
Hunting Queries
Baseline hunt for any HTTP traffic carrying MongoDB operators across all endpoints to find injection probing beyond the alerting threshold.
// df00tech DF00-5bf92bc4d1 · https://df00tech.com/detections/CVE-2026-125120 · licence: https://df00tech.com/detections/licence
W3CIISLog | extend d = url_decode(tostring(csUriQuery)) | where d matches regex @"(\$where|\$ne|\$regex|\$function)" | summarize count() by cIP, csUriStem, bin(TimeGenerated, 1h) ``` df00tech DF00-5bf92bc4d1 · https://df00tech.com/detections/CVE-2026-125120 · licence: https://df00tech.com/detections/licence ```
index=web | eval d=urldecode(coalesce(request_body,uri_query)) | where match(d,"\$where|\$ne|\$regex|\$function") | stats count by src_ip, uri_path Atomic Red Team Tests
Sends an HTTP request with a MongoDB operator ($ne) embedded in a JSON filter to an endpoint that performs countDocuments, simulating a sanitizeFilter bypass attempt.
Command
curl -s -X POST http://localhost:3000/api/users/count -H 'Content-Type: application/json' -d '{"username": {"$ne": null}}' Cleanup
echo 'No persistent changes; clear app request logs if desired: truncate -s 0 /var/log/app/access.log' Expected Telemetry
Web/app access log entry with request body containing the $ne operator and a MongoDB count command log with an injected filter.
Expected Detection
KQL/SPL operator-injection rule fires on the $ne payload in the request body.
Injects a $gt operator via URL query parameters to probe a count-based boolean oracle against a Mongoose-backed endpoint.
Command
curl -s 'http://localhost:3000/api/items/count?qty%5B%24gt%5D=0' Cleanup
echo 'No cleanup required; stateless read request.' Expected Telemetry
Web log with URL-encoded %24gt operator in the query string.
Expected Detection
Detection decodes the URL and matches the $gt MongoDB operator pattern.
Attempts to inject a $where clause into a count request, simulating the most severe server-side JS evaluation path of the vulnerability.
Command
curl -s -X POST http://localhost:3000/api/accounts/count -H 'Content-Type: application/json' -d '{"$where": "this.role == \"admin\""}' Cleanup
echo 'Stateless; no cleanup needed.' Expected Telemetry
Application and MongoDB logs showing a count operation with a $where expression.
Expected Detection
Rules flag the $where operator in the request body and correlate with the MongoDB count command.