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 Solution][Detections] Fix EQL search request filter when built with exceptions #79753

Merged
merged 1 commit into from
Oct 6, 2020
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 @@ -1105,11 +1105,17 @@ describe('get_filter', () => {
size: 100,
query: 'process where true',
filter: {
range: {
'@timestamp': {
gte: 'now-5m',
lte: 'now',
},
bool: {
filter: [
{
range: {
'@timestamp': {
gte: 'now-5m',
lte: 'now',
},
},
},
],
},
},
},
Expand All @@ -1135,11 +1141,17 @@ describe('get_filter', () => {
size: 100,
query: 'process where true',
filter: {
range: {
'event.ingested': {
gte: 'now-5m',
lte: 'now',
},
bool: {
filter: [
{
range: {
'event.ingested': {
gte: 'now-5m',
lte: 'now',
},
},
},
],
},
},
},
Expand All @@ -1164,44 +1176,52 @@ describe('get_filter', () => {
size: 100,
query: 'process where true',
filter: {
range: {
'@timestamp': {
gte: 'now-5m',
lte: 'now',
},
},
bool: {
must_not: {
bool: {
should: [
{
filter: [
{
range: {
'@timestamp': {
gte: 'now-5m',
lte: 'now',
},
},
},
{
bool: {
must_not: {
bool: {
filter: [
should: [
{
nested: {
path: 'some.parentField',
query: {
bool: {
minimum_should_match: 1,
should: [
{
match_phrase: {
'some.parentField.nested.field': 'some value',
bool: {
filter: [
{
nested: {
path: 'some.parentField',
query: {
bool: {
minimum_should_match: 1,
should: [
{
match_phrase: {
'some.parentField.nested.field': 'some value',
},
},
],
},
},
],
score_mode: 'none',
},
},
},
score_mode: 'none',
},
},
{
bool: {
minimum_should_match: 1,
should: [
{
match_phrase: {
'some.not.nested.field': 'some value',
bool: {
minimum_should_match: 1,
should: [
{
match_phrase: {
'some.not.nested.field': 'some value',
},
},
],
},
},
],
Expand All @@ -1210,9 +1230,9 @@ describe('get_filter', () => {
],
},
},
],
},
},
},
],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,35 @@ export const buildEqlSearchRequest = (
exceptionFilter = buildExceptionFilter(exceptionQueries, indexPattern, config, true, 1024);
}
const indexString = index.join();
const requestFilter: unknown[] = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you could use EsRangeFilter here in place of the unknown:

Suggested change
const requestFilter: unknown[] = [
const requestFilter: EsRangeFilter[] = [

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since you're pushing the bool object below as well, not sure what the recommended generic Filter type that should be used here...

{
range: {
[timestamp]: {
gte: from,
lte: to,
},
},
},
];
if (exceptionFilter !== undefined) {
requestFilter.push({
bool: {
must_not: {
bool: exceptionFilter?.query.bool,
},
},
});
}
const baseRequest = {
method: 'POST',
path: `/${indexString}/_eql/search?allow_no_indices=true`,
body: {
size,
query,
filter: {
range: {
[timestamp]: {
gte: from,
lte: to,
},
bool: {
filter: requestFilter,
},
bool:
exceptionFilter !== undefined
? {
must_not: {
bool: exceptionFilter?.query.bool,
},
}
: undefined,
},
},
};
Expand Down