-
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
[SIEM] [Detections] Fixes filtering with large value lists to use "ands" between lists #72304
Conversation
bc7256a
to
8bb0ec9
Compare
Pinging @elastic/siem (Team:SIEM) |
x-pack/plugins/lists/server/scripts/lists/new/list_ip_item.json
Outdated
Show resolved
Hide resolved
@@ -106,6 +125,72 @@ describe('filterEventsAgainstList', () => { | |||
'ci-badguys.txt' | |||
); | |||
expect(res.hits.hits.length).toEqual(2); | |||
|
|||
// @ts-ignore |
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.
Is it possible for us to use an as cast
or better yet an is cast
using the io-ts is on this here or do we have to keep the ts-ignore
. We really should be more strict about allowing ts-ignore. Also there is ts-expect-error
which it supposed to replace the ts-ignore:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments
it will be better in that builds will fail once it is no longer an error condition, but I prefer we try to not use ts-ignore as much as possible.
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.
the ts-ignore says that .ip
is not available on item._source.source
Property 'ip' does not exist on type 'string | number | boolean | object | string[] | number[] | boolean[] | object[]'.
comes from here
kibana/x-pack/plugins/security_solution/server/lib/detection_engine/signals/types.ts
Lines 31 to 49 in a7a2b7c
export type SearchTypes = | |
| string | |
| string[] | |
| number | |
| number[] | |
| boolean | |
| boolean[] | |
| object | |
| object[] | |
| undefined; | |
export interface SignalSource { | |
[key: string]: SearchTypes; | |
'@timestamp': string; | |
signal?: { | |
parent: Ancestor; | |
ancestors: Ancestor[]; | |
}; | |
} |
I'm not sure there is a way to change that without making a more explicit structure with every ECS property.
expect(listClient.getListItemByValues as jest.Mock).toHaveBeenCalledTimes(2); | ||
expect(res.hits.hits.length).toEqual(6); | ||
|
||
// @ts-ignore |
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.
Same comment as above about the ts-ignore.
|
||
// @ts-ignore | ||
const ipVals = res.hits.hits.map((item) => item._source.source.ip); | ||
expect(['1.1.1.1', '3.3.3.3', '5.5.5.5', '7.7.7.7', '8.8.8.8', '9.9.9.9']).toEqual(ipVals); |
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 all the tests though! Much appreciated.
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.
Can you add some tests where there are multiple exception items in the exception list and each item has multiple list-based entries?
x-pack/plugins/security_solution/server/lib/detection_engine/signals/filter_events_with_list.ts
Outdated
Show resolved
Hide resolved
…ut a value list are passed in to the filter function
…ue lists when appearing in different exception items
4475636
to
597fa1d
Compare
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.
A couple of minor things, then LGTM
expect(['1.1.1.1', '3.3.3.3', '5.5.5.5', '7.7.7.7', '8.8.8.8', '9.9.9.9']).toEqual(ipVals); | ||
}); | ||
|
||
it('should respond with less items in the list given one exception item with two entries of type list if some values match', async () => { |
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.
nit: the description says one exception item
but the test has 2 exception items with one entry each
.filter((t): t is EntryList => entriesList.is(t)) | ||
.map(async (entry) => { | ||
const valueListExceptionItems = exceptionsList.filter((listItem: ExceptionListItemSchema) => { | ||
return listItem.entries.some((entry) => entriesList.is(entry)); |
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.
probably want listItem.entries.every
here since we can't support items that have both list-based and regular entries
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 should also modify the exception list item schema to prevent creation of an item with both list and non-list entries, but that can be a separate PR.
… filter logic should execute
💚 Build SucceededBuild metrics
History
To update your PR or re-run it, just comment with: |
…ds" between lists (elastic#72304) * wip - comment and sample json for exceptions * promise.all for OR-ing exception items and quick-start script * logging, added/updated json sample scripts, fixed missing await on filter with lists * WIP * bug fix where two lists when 'anded' together were not filtering down result set * undo changes from testing * fix changes to example json and fixes missed conflict with master * update log message and fix type errors * change log statement and add unit test for when exception items without a value list are passed in to the filter function * fix failing test * update expect on one test and adds a new test to ensure anding of value lists when appearing in different exception items * update test after rebasing with master * properly ands exception item entries together with proper test cases * fix test (log statement tests - need to come up with a better way to cover these) * cleans up json examples * rename test and use 'every' in lieu of 'some' when determining if the filter logic should execute
…ds" between lists (elastic#72304) * wip - comment and sample json for exceptions * promise.all for OR-ing exception items and quick-start script * logging, added/updated json sample scripts, fixed missing await on filter with lists * WIP * bug fix where two lists when 'anded' together were not filtering down result set * undo changes from testing * fix changes to example json and fixes missed conflict with master * update log message and fix type errors * change log statement and add unit test for when exception items without a value list are passed in to the filter function * fix failing test * update expect on one test and adds a new test to ensure anding of value lists when appearing in different exception items * update test after rebasing with master * properly ands exception item entries together with proper test cases * fix test (log statement tests - need to come up with a better way to cover these) * cleans up json examples * rename test and use 'every' in lieu of 'some' when determining if the filter logic should execute
…se "ands" between lists (#72304) (#72908) * wip - comment and sample json for exceptions * promise.all for OR-ing exception items and quick-start script * logging, added/updated json sample scripts, fixed missing await on filter with lists * WIP * bug fix where two lists when 'anded' together were not filtering down result set * undo changes from testing * fix changes to example json and fixes missed conflict with master * update log message and fix type errors * change log statement and add unit test for when exception items without a value list are passed in to the filter function * fix failing test * update expect on one test and adds a new test to ensure anding of value lists when appearing in different exception items * update test after rebasing with master * properly ands exception item entries together with proper test cases * fix test (log statement tests - need to come up with a better way to cover these) * cleans up json examples * rename test and use 'every' in lieu of 'some' when determining if the filter logic should execute
…se "ands" between lists (#72304) (#72909) * wip - comment and sample json for exceptions * promise.all for OR-ing exception items and quick-start script * logging, added/updated json sample scripts, fixed missing await on filter with lists * WIP * bug fix where two lists when 'anded' together were not filtering down result set * undo changes from testing * fix changes to example json and fixes missed conflict with master * update log message and fix type errors * change log statement and add unit test for when exception items without a value list are passed in to the filter function * fix failing test * update expect on one test and adds a new test to ensure anding of value lists when appearing in different exception items * update test after rebasing with master * properly ands exception item entries together with proper test cases * fix test (log statement tests - need to come up with a better way to cover these) * cleans up json examples * rename test and use 'every' in lieu of 'some' when determining if the filter logic should execute
Pinging @elastic/security-solution (Team: SecuritySolution) |
Summary
This fixes a bug where an exception which includes two value lists "anded" together wouldn't return the right
signalsalerts.Checklist
Delete any items that are not applicable to this PR.
For maintainers