Skip to content

Commit

Permalink
Fix for CVE-2024-49203 (#743)
Browse files Browse the repository at this point in the history
Signed-off-by: Marvin Froeder <[email protected]>
  • Loading branch information
velo authored Dec 15, 2024
1 parent 49d975a commit e6ca103
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Pattern;

/** {@code PathBuilderValidator} validates {@link PathBuilder} properties at creation time */
public interface PathBuilderValidator extends Serializable {
Expand All @@ -35,8 +36,14 @@ public interface PathBuilderValidator extends Serializable {

PathBuilderValidator DEFAULT =
new PathBuilderValidator() {

private Pattern SPACES = Pattern.compile("\\s");

@Override
public Class<?> validate(Class<?> parent, String property, Class<?> propertyType) {
if (SPACES.matcher(property).find()) {
throw new IllegalStateException("Unsafe due to CVE-2024-49203");
}
return propertyType;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
package com.querydsl.core.types.dsl;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.domain.Cat;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.util.BeanMap;
import java.sql.Time;
import java.util.Date;
Expand Down Expand Up @@ -128,4 +133,25 @@ public void calling_get_with_the_same_name_and_different_types_returns_correct_t
assertThat(entity.get(pathName, Comparable.class).getType()).isEqualTo(String.class);
assertThat(entity.get(pathName, Object.class).getType()).isEqualTo(String.class);
}

@Test
public void order_HQL_injection() {
var orderBy = "breed";
var pathBuilder = new PathBuilder<Cat>(Cat.class, "entity");
assertDoesNotThrow(() -> new OrderSpecifier(Order.ASC, pathBuilder.get(orderBy)));
}

@Test
// CVE-2024-49203
// https://github.com/OpenFeign/querydsl/security/advisories/GHSA-6q3q-6v5j-h6vg
public void unsafe_order_HQL_injection() {
var orderBy =
"test.name INTERSECT SELECT t FROM Test t WHERE (SELECT cast(pg_sleep(10) AS text))='2' ORDER BY t.id";
var pathBuilder = new PathBuilder<Cat>(Cat.class, "entity");
var error =
assertThrows(
IllegalStateException.class,
() -> new OrderSpecifier(Order.ASC, pathBuilder.get(orderBy)));
assertThat(error).hasMessageContaining("CVE-2024-49203");
}
}

0 comments on commit e6ca103

Please sign in to comment.