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

[SIEM] Fixes escape bug for filterQuery #43030

Merged
merged 11 commits into from
Sep 6, 2019
15 changes: 14 additions & 1 deletion x-pack/legacy/plugins/siem/public/lib/keury/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import expect from '@kbn/expect';
import { escapeKuery } from '.';
import { convertKueryToElasticSearchQuery, escapeKuery } from '.';

describe('Kuery escape', () => {
it('should not remove white spaces quotes', () => {
Expand Down Expand Up @@ -61,4 +61,17 @@ describe('Kuery escape', () => {
const expected = 'This\\nhas\\tnewlines\\r\\nwith\\ttabs';
expect(escapeKuery(value)).to.be(expected);
});

it('should return JSON that is not escaped for the final ES search', () => {
const kueryExpression =
'(host.name : siem-windows and event.action : "Registry value set \\(rule\\: RegistryEvent\\)") and @timestamp >= 1565274377369 and @timestamp <= 1565360777369';
const expected =
'{"bool":{"filter":[{"bool":{"filter":[{"bool":{"should":[{"match":{"host.name":"siem-windows"}}],"minimum_should_match":1}},{"bool":{"should":[{"match_phrase":{"event.action":"Registry value set (rule: RegistryEvent)"}}],"minimum_should_match":1}}]}},{"bool":{"filter":[{"bool":{"should":[{"range":{"@timestamp":{"gte":1565274377369}}}],"minimum_should_match":1}},{"bool":{"should":[{"range":{"@timestamp":{"lte":1565360777369}}}],"minimum_should_match":1}}]}}]}}';
expect(
convertKueryToElasticSearchQuery(kueryExpression, {
fields: [],
title: 'auditbeat-*,filebeat-*,packetbeat-*,winlogbeat-*',
})
).to.be(expected);
});
});
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/siem/public/lib/keury/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const convertKueryToElasticSearchQuery = (
) => {
try {
return kueryExpression
? JSON.stringify(toElasticsearchQuery(fromKueryExpression(kueryExpression), indexPattern))
? JSON.stringify(
toElasticsearchQuery(fromKueryExpression(kueryExpression), indexPattern)
).replace(/\\\\/g, '')
: '';
} catch (err) {
return '';
Expand Down