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

[SIEM] [Detections] Fixes filtering with large value lists to use "ands" between lists #72304

Merged
merged 16 commits into from
Jul 22, 2020

Conversation

dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Jul 17, 2020

Summary

This fixes a bug where an exception which includes two value lists "anded" together wouldn't return the right signals alerts.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dhurley14 dhurley14 force-pushed the lists-and-exceptions branch 2 times, most recently from bc7256a to 8bb0ec9 Compare July 20, 2020 21:26
@dhurley14 dhurley14 self-assigned this Jul 21, 2020
@dhurley14 dhurley14 added release_note:skip Skip the PR/issue when compiling release notes review Team:SIEM v7.10.0 v7.9.0 v8.0.0 labels Jul 21, 2020
@dhurley14 dhurley14 marked this pull request as ready for review July 21, 2020 12:53
@dhurley14 dhurley14 requested review from a team as code owners July 21, 2020 12:53
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@@ -106,6 +125,72 @@ describe('filterEventsAgainstList', () => {
'ci-badguys.txt'
);
expect(res.hits.hits.length).toEqual(2);

// @ts-ignore
Copy link
Contributor

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.

Copy link
Contributor Author

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

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
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

@marshallmain marshallmain left a 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?

@dhurley14 dhurley14 force-pushed the lists-and-exceptions branch from 4475636 to 597fa1d Compare July 22, 2020 03:12
Copy link
Contributor

@marshallmain marshallmain left a 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 () => {
Copy link
Contributor

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));
Copy link
Contributor

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

Copy link
Contributor

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.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dhurley14 dhurley14 merged commit f9cbc99 into elastic:master Jul 22, 2020
@dhurley14 dhurley14 deleted the lists-and-exceptions branch July 22, 2020 16:39
dhurley14 added a commit to dhurley14/kibana that referenced this pull request Jul 22, 2020
…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
dhurley14 added a commit to dhurley14/kibana that referenced this pull request Jul 22, 2020
…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
dhurley14 added a commit that referenced this pull request Jul 22, 2020
…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
dhurley14 added a commit that referenced this pull request Jul 22, 2020
…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
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes review Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.9.0 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants