Skip to content

Commit

Permalink
DATACMNS-1285 - PropertyPath now limits the depth of its parsing to 1…
Browse files Browse the repository at this point in the history
…000 segments.
  • Loading branch information
odrotbohm committed Apr 3, 2018
1 parent 999d264 commit 371f659
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
public class PropertyPath implements Iterable<PropertyPath> {

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.";

private static final String DELIMITERS = "_\\.";
private static final String ALL_UPPERCASE = "[A-Z0-9._$]+";
private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));
Expand Down Expand Up @@ -321,6 +323,10 @@ private static PropertyPath create(String source, TypeInformation<?> type, List<
*/
private static PropertyPath create(String source, TypeInformation<?> type, String addTail, List<PropertyPath> base) {

if (base.size() > 1000) {
throw new IllegalArgumentException(PARSE_DEPTH_EXCEEDED);
}

PropertyReferenceException exception = null;
PropertyPath current = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2017 the original author or authors.
* Copyright 2011-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -346,6 +346,24 @@ public void includesPropertyHintsOnTypos() {
from("userAme", Foo.class);
}

@Test // DATACMNS-1285
public void rejectsTooLongPath() {

String source = "foo.bar";

for (int i = 0; i < 9; i++) {
source = source + "." + source;
}

assertThat(source.split("\\.").length, is(greaterThan(1000)));

final String path = source;

exception.expect(IllegalArgumentException.class);

PropertyPath.from(path, Left.class);
}

private class Foo {

String userName;
Expand Down Expand Up @@ -379,4 +397,14 @@ private class Sample2 {
private FooBar user;
private Foo _foo;
}

// DATACMNS-1285

private class Left {
Right foo;
}

private class Right {
Left bar;
}
}

0 comments on commit 371f659

Please sign in to comment.