CVE-2026-59342
Patch Available.
This Vulnerability has been fixed in the Never-Ending Support (NES) version offered by HeroDevs.
Overview
Spring Data MongoDB is the Spring Data module for the MongoDB document database. It provides MongoTemplate and a repository abstraction whose query methods can be declared with JSON-based MongoDB query and aggregation templates through annotations such as @Query and @Aggregation.
A command injection vulnerability (CVE-2026-59342) has been identified in the parameter binding of Spring Data MongoDB's string-based queries, which allows attackers to break out of a quoted string literal in a query template and inject their own logic into server-side JavaScript expressions such as $where, $function or $accumulator. Depending on the query, this can expose documents the application did not intend to return or degrade the availability of the database.
Per OWASP: Code Injection is the general term for attack types which consist of injecting code that is then interpreted/executed by the application. This type of attack exploits poor handling of untrusted data.
This issue affects multiple versions of Spring Data MongoDB.
Details
Module Info
- Product: Spring Data MongoDB
- Affected packages: org.springframework.data:spring-data-mongodb
- Affected versions: <=3.4.21, >=4.4.0 <=4.4.16, >=4.5.0 <=4.5.14, >=5.0.0 <=5.0.8, >=5.1.0 <=5.1.2
- GitHub repository: https://github.com/spring-projects/spring-data-mongodb
- Published packages: https://central.sonatype.com/artifact/org.springframework.data/spring-data-mongodb
- Package manager: Maven
- Fixed in:
- OSS Spring Data MongoDB 5.0.9, 5.1.3
- NES for Spring Data MongoDB
Vulnerability Info
This Medium-severity vulnerability is found in the org.springframework.data:spring-data-mongodb package in multiple versions of Spring Data MongoDB.
String-based repository queries are parsed by ParameterBindingJsonReader, which replaces positional placeholders (?0, ?1, ...) and SpEL placeholders (?#{...}) with the arguments passed to the query method. When a placeholder appears inside a quoted JSON string token, bindableValueFor substitutes the argument's string form directly into the token text:
while (matcher.find()) {
String group = matcher.group();
int index = computeParameterIndex(group);
computedValue = computedValue.replace(group, nullSafeToString(getBindableValueForIndex(index)));
}In later release lines, such as 4.5.x, the substituted value passes through escapeIfQuoted, but that method only rewrites the reader's internal regular-expression quote marker (\E). Neither form escapes a backslash or the quotation mark that encloses the placeholder, so a bound String containing ', " or \ ends the string literal early and the rest of the argument is read as part of the query.
This matters most when the placeholder sits inside a server-side JavaScript expression, as in the following repository method:
@Query("{ $where : 'return this.firstname == \"?0\"' }")
List<Person> findByFirstnameScript(String firstname);An argument such as x" || true || " closes the JavaScript string and turns the comparison into an expression that is always true, so the query returns every document in the collection. Other payloads can make the script run expensive logic on the database server. An application is exposed when MongoDB server-side JavaScript is enabled, a repository method annotated with an MQL template (for example @Query or @Aggregation) places a placeholder inside a script expression such as $where, $function or $accumulator, and an untrusted String reaches that method argument without prior sanitization.
Mitigation
Only recent versions of Spring Data MongoDB receive community support. Older lines are End-of-Life and will not receive public updates to address this issue.
Users of the affected components should apply one of the following mitigations:
- Upgrade to a currently supported version of Spring Data MongoDB.
- Leverage a commercial support partner like HeroDevs for post-EOL security support.
Credits
- Tim Zheng (finder)