-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Admin][Policy][Event Filters] Update event filters creation to include more match options #170495
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
Changes from all commits
d8a2be1
ca3dea7
cdf7dae
0fc5496
667e55e
ed5ab97
02825c0
f0000a3
e1a5144
dea8dc1
b441f5c
18d3e33
7cece88
65c75fb
787c441
99d6a87
0a6f34d
0d642c0
173de02
c5a1ced
75f1a7d
0461dae
cb569a7
fa71a65
bd4c109
c6c27e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ | |
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| export const FILENAME_WILDCARD_WARNING = i18n.translate('utils.filename.wildcardWarning', { | ||
| defaultMessage: `Using wildcards in file paths can impact Endpoint performance`, | ||
| export const WILDCARD_WARNING = i18n.translate('utils.wildcardWarning', { | ||
| defaultMessage: `Using wildcards can impact Endpoint performance`, | ||
| }); | ||
|
|
||
| export const FILEPATH_WARNING = i18n.translate('utils.filename.pathWarning', { | ||
|
|
@@ -52,39 +52,60 @@ export enum OperatingSystem { | |
| export type EntryTypes = 'match' | 'wildcard' | 'match_any'; | ||
| export type TrustedAppEntryTypes = Extract<EntryTypes, 'match' | 'wildcard'>; | ||
|
|
||
| export const validateFilePathInput = ({ | ||
| export const validatePotentialWildcardInput = ({ | ||
| field = '', | ||
| os, | ||
| value = '', | ||
| }: { | ||
| field?: string; | ||
| os: OperatingSystem; | ||
| value?: string; | ||
| }): string | undefined => { | ||
| const textInput = value.trim(); | ||
| if (field === 'file.path.text') { | ||
| return validateFilePathInput({ os, value: textInput }); | ||
| } | ||
| return validateWildcardInput(textInput); | ||
| }; | ||
|
|
||
| export const validateFilePathInput = ({ | ||
| os, | ||
| value, | ||
| }: { | ||
| os: OperatingSystem; | ||
| value: string; | ||
| }): string | undefined => { | ||
| const isValidFilePath = isPathValid({ | ||
| os, | ||
| field: 'file.path.text', | ||
| type: 'wildcard', | ||
| value: textInput, | ||
| value, | ||
| }); | ||
| const hasSimpleFileName = hasSimpleExecutableName({ | ||
| os, | ||
| type: 'wildcard', | ||
| value: textInput, | ||
| value, | ||
| }); | ||
|
|
||
| if (!textInput.length) { | ||
| if (!value.length) { | ||
| return FILEPATH_WARNING; | ||
| } | ||
|
|
||
| if (isValidFilePath) { | ||
| if (hasSimpleFileName !== undefined && !hasSimpleFileName) { | ||
| return FILENAME_WILDCARD_WARNING; | ||
| return WILDCARD_WARNING; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would expect to see only FILEPATH_WARNING in this function as it only deals with if (
!isValidFilePath ||
!value.length ||
(hasSimpleFileName !== undefined && !hasSimpleFileName)
) {
return FILEPATH_WARNING;
}and that's all the function should return.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah you're absolutely right! Perhaps the following may be simpler to reason with: if (!isValidFilePath || !value.length) {
return FILEPATH_WARNING;
}
if (hasSimpleFileName !== undefined && !hasSimpleFileName) {
return WILDCARD_WARNING;
} |
||
| } | ||
| } else { | ||
| return FILEPATH_WARNING; | ||
| } | ||
| }; | ||
|
|
||
| export const validateWildcardInput = (value?: string): string | undefined => { | ||
| if (/[*?]/.test(value ?? '')) { | ||
| return WILDCARD_WARNING; | ||
| } | ||
| }; | ||
|
|
||
| export const hasSimpleExecutableName = ({ | ||
| os, | ||
| type, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,7 +212,7 @@ describe('Exception builder helpers', () => { | |
| expect(output).toEqual(expected); | ||
| }); | ||
|
|
||
| test('it returns all fields unfiletered if "item.nested" is not "child" or "parent"', () => { | ||
| test('it returns all fields unfiltered if "item.nested" is not "child" or "parent"', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 thanks for fixing type |
||
| const payloadIndexPattern = getMockIndexPattern(); | ||
| const payloadItem: FormattedBuilderEntry = getMockBuilderEntry(); | ||
| const output = getFilteredIndexPatterns(payloadIndexPattern, payloadItem); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now see the
FILEPATH_WARNINGfor any field when selecting for matches operator.