Skip to content

Commit 025bedb

Browse files
[Security Solution][Exceptions] - Fixes exception builder bug that includes matches operator (#136340) (#136652)
## Summary Addresses Kibana issue #36224 (cherry picked from commit ff3853c) Co-authored-by: Yara Tercero <[email protected]>
1 parent 5f681db commit 025bedb

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

packages/kbn-securitysolution-autocomplete/src/get_operators/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {
1010
doesNotExistOperator,
1111
EVENT_FILTERS_OPERATORS,
12-
EXCEPTION_OPERATORS,
12+
ALL_OPERATORS,
1313
existsOperator,
1414
isNotOperator,
1515
isOperator,
@@ -53,6 +53,6 @@ describe('#getOperators', () => {
5353
test('it returns all operator types when field type is not null, boolean, or nested', () => {
5454
const operator = getOperators(getField('machine.os.raw'));
5555

56-
expect(operator).toEqual(EXCEPTION_OPERATORS);
56+
expect(operator).toEqual(ALL_OPERATORS);
5757
});
5858
});

packages/kbn-securitysolution-autocomplete/src/get_operators/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { DataViewFieldBase } from '@kbn/es-query';
1010

1111
import {
12-
EXCEPTION_OPERATORS,
12+
ALL_OPERATORS,
1313
EVENT_FILTERS_OPERATORS,
1414
OperatorOption,
1515
doesNotExistOperator,
@@ -34,6 +34,6 @@ export const getOperators = (field: DataViewFieldBase | undefined): OperatorOpti
3434
} else if (field.name === 'file.path.text') {
3535
return EVENT_FILTERS_OPERATORS;
3636
} else {
37-
return EXCEPTION_OPERATORS;
37+
return ALL_OPERATORS;
3838
}
3939
};

packages/kbn-securitysolution-list-utils/src/autocomplete_operators/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,22 @@ export const EVENT_FILTERS_OPERATORS: OperatorOption[] = [
102102
matchesOperator,
103103
];
104104

105-
export const EXCEPTION_OPERATORS: OperatorOption[] = [
105+
/*
106+
* !IMPORTANT! - Please only add to this list if it is an operator
107+
* supported by the detection engine.
108+
*/
109+
export const DETECTION_ENGINE_EXCEPTION_OPERATORS: OperatorOption[] = [
110+
isOperator,
111+
isNotOperator,
112+
isOneOfOperator,
113+
isNotOneOfOperator,
114+
existsOperator,
115+
doesNotExistOperator,
116+
isInListOperator,
117+
isNotInListOperator,
118+
];
119+
120+
export const ALL_OPERATORS: OperatorOption[] = [
106121
isOperator,
107122
isNotOperator,
108123
isOneOfOperator,

packages/kbn-securitysolution-list-utils/src/helpers/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ import {
3636
} from '@kbn/es-query';
3737

3838
import {
39-
EXCEPTION_OPERATORS,
39+
ALL_OPERATORS,
4040
EXCEPTION_OPERATORS_SANS_LISTS,
4141
doesNotExistOperator,
4242
existsOperator,
4343
isNotOperator,
4444
isOneOfOperator,
4545
isOperator,
46+
DETECTION_ENGINE_EXCEPTION_OPERATORS,
4647
} from '../autocomplete_operators';
4748

4849
import {
@@ -192,7 +193,7 @@ export const getExceptionOperatorSelect = (item: BuilderEntry): OperatorOption =
192193
return isOperator;
193194
} else {
194195
const operatorType = getOperatorType(item);
195-
const foundOperator = EXCEPTION_OPERATORS.find((operatorOption) => {
196+
const foundOperator = ALL_OPERATORS.find((operatorOption) => {
196197
return item.operator === operatorOption.operator && operatorType === operatorOption.type;
197198
});
198199

@@ -687,12 +688,12 @@ export const getOperatorOptions = (
687688
return isBoolean ? [isOperator] : [isOperator, isOneOfOperator];
688689
} else if (item.nested != null && listType === 'detection') {
689690
return isBoolean ? [isOperator, existsOperator] : [isOperator, isOneOfOperator, existsOperator];
691+
} else if (isBoolean) {
692+
return [isOperator, isNotOperator, existsOperator, doesNotExistOperator];
693+
} else if (!includeValueListOperators) {
694+
return EXCEPTION_OPERATORS_SANS_LISTS;
690695
} else {
691-
return isBoolean
692-
? [isOperator, isNotOperator, existsOperator, doesNotExistOperator]
693-
: includeValueListOperators
694-
? EXCEPTION_OPERATORS
695-
: EXCEPTION_OPERATORS_SANS_LISTS;
696+
return listType === 'detection' ? DETECTION_ENGINE_EXCEPTION_OPERATORS : ALL_OPERATORS;
696697
}
697698
};
698699

x-pack/plugins/lists/public/exceptions/components/builder/helpers.test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import {
1818
ListOperatorTypeEnum as OperatorTypeEnum,
1919
} from '@kbn/securitysolution-io-ts-list-types';
2020
import {
21+
ALL_OPERATORS,
2122
BuilderEntry,
22-
EXCEPTION_OPERATORS,
23+
DETECTION_ENGINE_EXCEPTION_OPERATORS,
2324
EXCEPTION_OPERATORS_SANS_LISTS,
2425
EmptyEntry,
2526
ExceptionsBuilderExceptionItem,
@@ -596,13 +597,6 @@ describe('Exception builder helpers', () => {
596597
expect(output).toEqual(expected);
597598
});
598599

599-
test('it returns all operator options if "listType" is "detection"', () => {
600-
const payloadItem: FormattedBuilderEntry = getMockBuilderEntry();
601-
const output = getOperatorOptions(payloadItem, 'detection', false);
602-
const expected: OperatorOption[] = EXCEPTION_OPERATORS;
603-
expect(output).toEqual(expected);
604-
});
605-
606600
test('it returns "isOperator", "isNotOperator", "doesNotExistOperator" and "existsOperator" if field type is boolean', () => {
607601
const payloadItem: FormattedBuilderEntry = getMockBuilderEntry();
608602
const output = getOperatorOptions(payloadItem, 'detection', true);
@@ -618,14 +612,27 @@ describe('Exception builder helpers', () => {
618612
test('it returns list operators if specified to', () => {
619613
const payloadItem: FormattedBuilderEntry = getMockBuilderEntry();
620614
const output = getOperatorOptions(payloadItem, 'detection', false, true);
621-
expect(output).toEqual(EXCEPTION_OPERATORS);
615+
expect(output.some((operator) => operator.value === 'is_not_in_list')).toBeTruthy();
616+
expect(output.some((operator) => operator.value === 'is_in_list')).toBeTruthy();
622617
});
623618

624619
test('it does not return list operators if specified not to', () => {
625620
const payloadItem: FormattedBuilderEntry = getMockBuilderEntry();
626621
const output = getOperatorOptions(payloadItem, 'detection', false, false);
627622
expect(output).toEqual(EXCEPTION_OPERATORS_SANS_LISTS);
628623
});
624+
625+
test('it returns all possible operators if list type is not "detection"', () => {
626+
const payloadItem: FormattedBuilderEntry = getMockBuilderEntry();
627+
const output = getOperatorOptions(payloadItem, 'endpoint_events', false, true);
628+
expect(output).toEqual(ALL_OPERATORS);
629+
});
630+
631+
test('it returns all operators supported by detection engine if list type is "detection"', () => {
632+
const payloadItem: FormattedBuilderEntry = getMockBuilderEntry();
633+
const output = getOperatorOptions(payloadItem, 'detection', false, true);
634+
expect(output).toEqual(DETECTION_ENGINE_EXCEPTION_OPERATORS);
635+
});
629636
});
630637

631638
describe('#getEntryOnFieldChange', () => {

0 commit comments

Comments
 (0)