Mongoose NoSQL Injection via Unsanitized countDocuments (CVE-2026-125120)
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.
Vulnerability Intelligence
TheoreticalAffected Software
- Vendor
- npm
- Product
- mongoose
- Versions
- < 6.13.11, >= 7.0.0, < 7.8.12, >= 8.0.0, < 8.24.3, >= 9.0.0, < 9.9.2
Weakness (CWE)
Timeline
- Disclosed
- November 10, 2026
References & Proof of Concept
- https://github.com/Automattic/mongoose/security/advisories/GHSA-pcrw-h46h-c93h
- https://nvd.nist.gov/vuln/detail/CVE-2026-125120
- https://github.com/Automattic/mongoose/commit/7e912af3fac52cb0eea4cd71e24d65318916831a
- https://github.com/Automattic/mongoose/commit/8b10d5760bb181f5bf5d01495cde161c8aed0557
- https://github.com/Automattic/mongoose/commit/b1df045aab076b740fdaec14a15a44c694b85b7d
- https://github.com/Automattic/mongoose/commit/b5003d3915db1cf9209c38a4b93cf3a92cddd710
- https://github.com/Automattic/mongoose/releases/tag/6.13.11
- https://github.com/Automattic/mongoose/releases/tag/7.8.12
- https://github.com/Automattic/mongoose/releases/tag/8.24.3
- https://github.com/Automattic/mongoose/releases/tag/9.9.2
- https://github.com/advisories/GHSA-pcrw-h46h-c93h
CVSS
- Attack Vector
- Network
- Attack Complexity
- Low
- Privileges Required
- None
- User Interaction
- None
- Scope
- Unchanged
- Confidentiality
- High
- Integrity
- High
- Availability
- High
What is CVE-2026-125120 Mongoose NoSQL Injection via Unsanitized countDocuments (CVE-2026-125120)?
Mongoose NoSQL Injection via Unsanitized countDocuments (CVE-2026-125120) (CVE-2026-125120) maps to the Initial Access and Collection and Credential Access tactics — the adversary is trying to get into your network in MITRE ATT&CK.
This page provides production-ready detection logic for Mongoose NoSQL Injection via Unsanitized countDocuments (CVE-2026-125120), covering the data sources and telemetry it touches: IIS Web Server Logs, Azure Application Gateway WAF, Application HTTP Logs. The queries below are rated high severity at medium confidence, and ship for 7 SIEM platforms — KQL, SPL, Elastic, QRadar, Sumo, YARA-L, LogScale.
MITRE ATT&CK
// df00tech DF00-5bf92bc4d1 · https://df00tech.com/detections/CVE-2026-125120 · licence: https://df00tech.com/detections/licence
let OperatorPatterns = dynamic(["$where","$ne","$gt","$gte","$lt","$lte","$regex","$in","$nin","$or","$and","$expr","$function","$accumulator"]);
let suspiciousCount = W3CIISLog
| union (AzureDiagnostics | where Category =~ "ApplicationGatewayFirewallLog")
| extend Body = coalesce(column_ifexists("csUriQuery", ""), column_ifexists("requestBody_s", ""))
| extend DecodedBody = url_decode(tostring(Body))
| where DecodedBody has_any (OperatorPatterns) and DecodedBody matches regex @"%24|\$"
| where DecodedBody matches regex @"(\$where|\$ne|\$gt|\$regex|\$function|\$expr)"
| project TimeGenerated, SrcIp = coalesce(column_ifexists("cIP",""), column_ifexists("clientIp_s","")), Uri = coalesce(column_ifexists("csUriStem",""), column_ifexists("requestUri_s","")), DecodedBody;
suspiciousCount
| summarize Hits = count(), SampleBody = any(DecodedBody), Uris = make_set(Uri, 10) by SrcIp, bin(TimeGenerated, 10m)
| where Hits >= 3 Flags HTTP requests whose query string or body (reconstructed from IIS/App Gateway WAF logs) contains MongoDB query operators that Mongoose's sanitizeFilter is meant to strip, indicating NoSQL-injection attempts that may bypass the broken countDocuments path. Tune thresholds to request volume.
Data Sources
Required Tables
False Positives
- Legitimate applications that intentionally accept MongoDB operators in query parameters (e.g. admin search tools or JSON-filter APIs).
- Security scanners and DAST tools (Burp, ZAP, Nuclei) running authorized assessments that inject operator payloads.
- Developer or QA traffic from staging environments reusing production log pipelines.
Query fingerprint DF00-5bf92bc4d1 · licence
Sigma logsource & community rules
The detection logic for Mongoose NoSQL Injection via Unsanitized countDocuments (CVE-2026-125120) (CVE-2026-125120) above is provided in a vendor-neutral
form so you can deploy it on any SIEM. The same logic is shipped here as native
KQL (Microsoft Sentinel / Defender), SPL (Splunk), Elastic (Elastic Security (EQL)), QRadar (IBM QRadar (AQL)), Sumo (Sumo Logic CSE), YARA-L (Google Chronicle / SecOps), LogScale (CrowdStrike LogScale (CQL)) queries. In Sigma terms, this detection targets the
following logsource:
logsource:
product: azure Browse the community-maintained Sigma rules for this technique:
Platform-specific guides for CVE-2026-125120
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
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.
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.
Related Detections
Related Techniques
Same Tactic: Initial Access
Blog posts about this detection
- Mongoose Patches Query Sanitization Gap in countDocuments() November 12, 2026
Browse by tactic
- Reconnaissance TA0043
- Resource Development TA0042
- Initial Access TA0001
- Execution TA0002
- Persistence TA0003
- Privilege Escalation TA0004
- Stealth TA0005
- Defense Impairment TA0112
- Credential Access TA0006
- Discovery TA0007
- Lateral Movement TA0008
- Collection TA0009
- Command and Control TA0011
- Exfiltration TA0010
- Impact TA0040