-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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][Investigations][Timeline] - Update getExceptions to use parameters #145889
Changes from all commits
e77189e
d56a35d
cc75ce9
41fd2b7
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ import { useDispatch } from 'react-redux'; | |
import { EuiContextMenuItem } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { ALERT_RULE_EXCEPTIONS_LIST } from '@kbn/rule-data-utils'; | ||
import { ALERT_RULE_EXCEPTIONS_LIST, ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; | ||
import type { ExceptionListId } from '@kbn/securitysolution-io-ts-list-types'; | ||
import { useApi } from '@kbn/securitysolution-list-hooks'; | ||
|
||
|
@@ -52,9 +52,27 @@ export const useInvestigateInTimeline = ({ | |
|
||
const getExceptionFilter = useCallback( | ||
async (ecsData: Ecs): Promise<Filter | undefined> => { | ||
const exceptionsLists = (getField(ecsData, ALERT_RULE_EXCEPTIONS_LIST) ?? []).reduce( | ||
(acc: ExceptionListId[], next: string) => { | ||
const parsedList = JSON.parse(next); | ||
// This pulls exceptions list information from `_source` | ||
// This primarily matters for the old `signal` alerts a user may be viewing | ||
// as new exception lists are pulled from kibana.alert.rule.parameters[0].exception_lists; | ||
// Source was removed in favour of the fields api which passes the exceptions_list via `kibana.alert.rule.parameters` | ||
let exceptionsList = getField(ecsData, ALERT_RULE_EXCEPTIONS_LIST) ?? []; | ||
|
||
if (exceptionsList.length === 0) { | ||
try { | ||
const ruleParameters = getField(ecsData, ALERT_RULE_PARAMETERS) ?? {}; | ||
if (ruleParameters.length > 0) { | ||
const parametersObject = JSON.parse(ruleParameters[0]); | ||
exceptionsList = parametersObject?.exceptions_list ?? []; | ||
} | ||
} catch (error) { | ||
// do nothing, just fail silently as parametersObject is initialized | ||
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.
Did you mean exceptionList? 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. Yea, I updated the code, but not the comment, will do a follow up cleanup PR for this. Thanks! |
||
} | ||
} | ||
const detectionExceptionsLists = exceptionsList.reduce( | ||
(acc: ExceptionListId[], next: string | object) => { | ||
// parsed rule.parameters returns an object else use the default string representation | ||
const parsedList = typeof next === 'string' ? JSON.parse(next) : next; | ||
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. Do you think that this line( 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'm not sure exceptions list will ever actually be |
||
if (parsedList.type === 'detection') { | ||
const formattedList = { | ||
exception_list_id: parsedList.list_id, | ||
|
@@ -67,14 +85,15 @@ export const useInvestigateInTimeline = ({ | |
[] | ||
); | ||
|
||
if (exceptionsLists.length > 0) { | ||
let exceptionFilter; | ||
if (detectionExceptionsLists.length > 0) { | ||
await getExceptionFilterFromIds({ | ||
exceptionListIds: exceptionsLists, | ||
exceptionListIds: detectionExceptionsLists, | ||
excludeExceptions: true, | ||
chunkSize: 20, | ||
alias: 'Exceptions', | ||
onSuccess: (filter) => { | ||
return filter; | ||
exceptionFilter = filter; | ||
}, | ||
onError: (err: string[]) => { | ||
addError(err, { | ||
|
@@ -86,7 +105,7 @@ export const useInvestigateInTimeline = ({ | |
}, | ||
}); | ||
} | ||
return undefined; | ||
return exceptionFilter; | ||
}, | ||
[addError, getExceptionFilterFromIds] | ||
); | ||
|
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.
Thanks for context here.