Skip to content

HQL injection trough orderBy #3757

Closed
Closed
@CSIRTTrizna

Description

@CSIRTTrizna

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/

  1. Create JPAQuery object instance:
JPAQuery<Test> query = new JPAQuery<Test>(entityManager).from(test);
  1. 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.

  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions