Closed
Description
Observed vs. expected behavior
When using JPAQuery.orderBy
with user provided input there is a possibility to inject HQL
query, which is then executed in database.
Steps to reproduce
Full POC code is available in repository:
https://github.com/CSIRTTrizna/CVE-2024-49203/
- 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();
Environment
Library versions used in proof of concept to reproduce the vulnerability:
querydsl-jpa: 5.1.0
querydsl-apt: 5.1.0
hibernate-core: 6.1.1.Final
jakarta.persistence-api: 3.1.0
postgresql: 42.7.4
Querydsl version: 5.1.0
Querydsl module: querydsl-jpa
Database: postgresql
JDK: 23
Additional details
Article detailing the vulnerability : https://www.csirt.sk/querydsl-java-library-vulnerability-permits-sql-hql-injection.html