Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security] Include an empty json object in an json array when FLS filters out all fields #30709

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ private static List<Object> filter(Iterable<?> iterable, CharacterRunAutomaton i
continue;
}
Map<String, Object> filteredValue = filter((Map<String, ?>)value, includeAutomaton, state);
if (filteredValue.isEmpty() == false) {
filtered.add(filteredValue);
}
filtered.add(filteredValue);
} else if (value instanceof Iterable) {
List<Object> filteredValue = filter((Iterable<?>) value, includeAutomaton, initialState);
if (filteredValue.isEmpty() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,22 @@ public void testSourceFiltering() {
expected.put("foo", subArray);

assertEquals(expected, filtered);

// json array objects that have no matching fields should be left empty instead of being removed:
// (otherwise nested inner hit source filtering fails with AOOB)
map = new HashMap<>();
map.put("foo", "value");
List<Map<?, ?>> values = new ArrayList<>();
values.add(Collections.singletonMap("foo", "1"));
values.add(Collections.singletonMap("baz", "2"));
map.put("bar", values);

include = new CharacterRunAutomaton(Automatons.patterns("bar.baz"));
filtered = FieldSubsetReader.filter(map, include, 0);

expected = new HashMap<>();
expected.put("bar", Arrays.asList(new HashMap<>(), Collections.singletonMap("baz", "2")));
assertEquals(expected, filtered);
}

/**
Expand Down