| 
14 | 14 | package com.querydsl.core.types.dsl;  | 
15 | 15 | 
 
  | 
16 | 16 | import static org.junit.Assert.*;  | 
 | 17 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;  | 
 | 18 | +import static org.junit.jupiter.api.Assertions.assertThrows;  | 
17 | 19 | 
 
  | 
18 | 20 | import com.querydsl.core.BooleanBuilder;  | 
 | 21 | +import com.querydsl.core.domain.Cat;  | 
 | 22 | +import com.querydsl.core.types.Order;  | 
 | 23 | +import com.querydsl.core.types.OrderSpecifier;  | 
19 | 24 | import com.querydsl.core.util.BeanMap;  | 
20 | 25 | import java.sql.Time;  | 
21 | 26 | import java.util.Date;  | 
@@ -129,4 +134,26 @@ public void calling_get_with_the_same_name_and_different_types_returns_correct_t  | 
129 | 134 |     assertEquals(String.class, entity.get(pathName, Comparable.class).getType());  | 
130 | 135 |     assertEquals(String.class, entity.get(pathName, Object.class).getType());  | 
131 | 136 |   }  | 
 | 137 | + | 
 | 138 | +  @Test  | 
 | 139 | +  public void order_HQL_injection() {  | 
 | 140 | +    var orderBy = "breed";  | 
 | 141 | +    var pathBuilder = new PathBuilder<Cat>(Cat.class, "entity");  | 
 | 142 | +    assertDoesNotThrow(() -> new OrderSpecifier(Order.ASC, pathBuilder.get(orderBy)));  | 
 | 143 | +  }  | 
 | 144 | + | 
 | 145 | +  @Test  | 
 | 146 | +  // CVE-2024-49203  | 
 | 147 | +  // https://github.com/OpenFeign/querydsl/security/advisories/GHSA-6q3q-6v5j-h6vg  | 
 | 148 | +  public void unsafe_order_HQL_injection() {  | 
 | 149 | +    var orderBy =  | 
 | 150 | +        "test.name INTERSECT SELECT t FROM Test t WHERE (SELECT cast(pg_sleep(10) AS text))='2'"  | 
 | 151 | +            + " ORDER BY t.id";  | 
 | 152 | +    var pathBuilder = new PathBuilder<Cat>(Cat.class, "entity");  | 
 | 153 | +    var error =  | 
 | 154 | +        assertThrows(  | 
 | 155 | +            IllegalStateException.class,  | 
 | 156 | +            () -> new OrderSpecifier(Order.ASC, pathBuilder.get(orderBy)));  | 
 | 157 | +    assertTrue(error.getMessage().contains("CVE-2024-49203"));  | 
 | 158 | +  }  | 
132 | 159 | }  | 
0 commit comments