Skip to content

Commit 10fc6ec

Browse files
committed
Do not allow escaped pipe in extensions
1 parent 9b9747f commit 10fc6ec

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CefParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class CefParser {
6060
// New patterns for extension parsing
6161
private static final String EXTENSION_KEY_PATTERN = "(?:[\\w-]+(?:\\.[^\\.=\\s\\|\\\\\\[\\]]+)*(?:\\[[0-9]+\\])?(?==))";
6262
private static final Pattern EXTENSION_KEY_ARRAY_CAPTURE = Pattern.compile("^([^\\[\\]]+)((?:\\[[0-9]+\\])+)$");
63-
private static final String EXTENSION_VALUE_PATTERN = "(?:\\S|\\s(?!" + EXTENSION_KEY_PATTERN + "=))*";
63+
private static final String EXTENSION_VALUE_PATTERN = "(?:[^\\s\\\\]|\\\\[^|]|\\s(?!" + EXTENSION_KEY_PATTERN + "=))*";
6464
private static final Pattern EXTENSION_NEXT_KEY_VALUE_PATTERN = Pattern.compile(
6565
"(" + EXTENSION_KEY_PATTERN + ")=(" + EXTENSION_VALUE_PATTERN + ")(?:\\s+|$)"
6666
);

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CefProcessorTests.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -282,24 +282,7 @@ public void testEscapedPipeInExtension() {
282282
source.put("message", message);
283283
document = new IngestDocument("index", "id", 1L, null, null, source);
284284
CefProcessor processor = new CefProcessor("tag", "description", "message", "cef", false, true, null);
285-
processor.execute(document);
286-
287-
Map<String, Object> expectedMap = Map.ofEntries(
288-
entry(
289-
"cef",
290-
Map.ofEntries(
291-
entry("version", "0"),
292-
entry("device", Map.of("vendor", "security", "product", "threatmanager", "version", "1.0", "event_class_id", "100")),
293-
entry("name", "trojan successfully stopped"),
294-
entry("severity", "10"),
295-
entry("extensions", Map.of("moo", "this\\|has an escaped pipe"))
296-
)
297-
),
298-
entry("event", Map.of("code", "100")),
299-
entry("observer", Map.of("product", "threatmanager", "vendor", "security", "version", "1.0")),
300-
entry("message", message)
301-
);
302-
assertThat(document.getSource(), equalTo(expectedMap));
285+
expectThrows(IllegalArgumentException.class, () -> processor.execute(document));
303286
}
304287

305288
public void testPipeInMessage() {

0 commit comments

Comments
 (0)