Skip to content

Commit 06b0dab

Browse files
committed
DATACMNS-1285 - PropertyPath now limits the depth of its parsing to 1000 segments.
1 parent 6293ff3 commit 06b0dab

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
@EqualsAndHashCode
4747
public class PropertyPath implements Streamable<PropertyPath> {
4848

49+
private static final String PARSE_DEPTH_EXCEEDED = "Trying to parse a path with depth greater than 1000! This has been disabled for security reasons to prevent parsing overflows.";
50+
4951
private static final String DELIMITERS = "_\\.";
5052
private static final String ALL_UPPERCASE = "[A-Z0-9._$]+";
5153
private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));
@@ -366,6 +368,10 @@ private static PropertyPath create(String source, TypeInformation<?> type, List<
366368
*/
367369
private static PropertyPath create(String source, TypeInformation<?> type, String addTail, List<PropertyPath> base) {
368370

371+
if (base.size() > 1000) {
372+
throw new IllegalArgumentException(PARSE_DEPTH_EXCEEDED);
373+
}
374+
369375
PropertyReferenceException exception = null;
370376
PropertyPath current = null;
371377

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ public void rejectsNonExistantNestedPath() {
369369
.withMessageContaining("Bar.user");
370370
}
371371

372+
@Test // DATACMNS-1285
373+
public void rejectsTooLongPath() {
374+
375+
String source = "foo.bar";
376+
377+
for (int i = 0; i < 9; i++) {
378+
source = source + "." + source;
379+
}
380+
381+
assertThat(source.split("\\.").length).isGreaterThan(1000);
382+
383+
final String path = source;
384+
385+
assertThatExceptionOfType(IllegalArgumentException.class) //
386+
.isThrownBy(() -> PropertyPath.from(path, Left.class));
387+
}
388+
372389
private class Foo {
373390

374391
String userName;
@@ -403,4 +420,14 @@ private class Sample2 {
403420
private FooBar user;
404421
private Foo _foo;
405422
}
423+
424+
// DATACMNS-1285
425+
426+
private class Left {
427+
Right foo;
428+
}
429+
430+
private class Right {
431+
Left bar;
432+
}
406433
}

0 commit comments

Comments
 (0)