Analyzing CVE-2022–22980 to discover a real exploitable path in the source code review process with CodeQL
A Spring Data MongoDB application used a repository query method annotated with @Query or @Aggregation containing SpEL parameter placeholders, and unsanitised user input reached that query, allowing expression injection that led to remote code execution. The author built a CodeQL query to find such exploitable paths and confirmed one in a demo application.
Published on infosecwriteups.com
In this post, I will walk you through a journey that starts analyzing CVE-2022–22980 and extracting a pattern of this vulnerability to query a codebase to discover the true exploitation path.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application passed unsanitised user input into a Spring Data MongoDB @Query or @Aggregation annotation whose value contained SpEL parameter placeholders, so the expression was evaluated with attacker-controlled data.
Impact
An attacker could achieve remote code execution on the server.
What the attacker needed
Spring Data MongoDB vulnerable version; repository method with @Query or @Aggregation; annotation contains SpEL parameter placeholders; unsanitised user input reaches the query
The fix
The vulnerability was fixed in Spring Data MongoDB versions 3.4.0 and 3.3.5, and users should upgrade.
How it was found
- Create a CodeQL database from the Java codebase.
- Import the database into the CodeQL extension in VSCode.
- Write and run a query that finds remote flow sources reaching @Query or @Aggregation annotations containing parameter placeholders.
- Review the query results to find a source-to-sink path.
- Send a POST request with a malicious payload to the /test endpoint.
- Observe that a file was created in the temporary directory, confirming remote code execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Some Java applications let you write database queries as annotations on methods. If those queries include a special expression language (SpEL) and the application puts user input straight into them, an attacker can make the expression run their own code on the server. This article shows how to search source code automatically to find places where that happens.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.