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

[Security Solution] [CTI] Fixes bug that caused Threshold and Indicator Match rules to ignore custom rule filters if a saved query was used in the rule definition. #109253

Merged
merged 13 commits into from
Sep 2, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,52 @@ describe('get_filter', () => {
});
});

test('returns the query persisted to the threat_match rule, despite saved_id being specified', async () => {
const filter = await getFilter({
type: 'threat_match',
filters: undefined,
language: 'kuery',
query: 'host.name: siem',
savedId: 'some-id',
services: servicesMock,
index: ['auditbeat-*'],
lists: [],
});
expect(filter).toEqual({
bool: {
filter: [
{ bool: { minimum_should_match: 1, should: [{ match: { 'host.name': 'siem' } }] } },
],
must: [],
must_not: [],
should: [],
},
});
});

test('returns the query persisted to the threshold rule, despite saved_id being specified', async () => {
const filter = await getFilter({
type: 'threat_match',
filters: undefined,
language: 'kuery',
query: 'host.name: siem',
savedId: 'some-id',
services: servicesMock,
index: ['auditbeat-*'],
lists: [],
});
expect(filter).toEqual({
bool: {
filter: [
{ bool: { minimum_should_match: 1, should: [{ match: { 'host.name': 'siem' } }] } },
],
must: [],
must_not: [],
should: [],
},
});
});

test('throws on saved query if saved_id is undefined', async () => {
await expect(
getFilter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ export const getFilter = async ({

switch (type) {
case 'threat_match':
case 'threshold': {
return savedId != null ? savedQueryFilter() : queryFilter();
}
case 'threshold':
case 'query': {
return queryFilter();
}
Expand Down