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] Fixes a bug where invalid regular expressions within the index patterns can cause UI toaster errors #73754

Merged
merged 7 commits into from
Jul 31, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,17 @@ describe('Schema Beat', () => {
const result = getIndexAlias([leadingWildcardIndex], leadingWildcardIndex);
expect(result).toBe(leadingWildcardIndex);
});

test('getIndexAlias no match returns "unknown" string', () => {
const index = 'auditbeat-*';
const result = getIndexAlias([index], 'hello');
expect(result).toBe('unknown');
});

test('empty index should not cause an error to return although it will cause an invalid regular expression to occur', () => {
const index = '';
const result = getIndexAlias([index], 'hello');
expect(result).toBe('unknown');
});
});
});
14 changes: 10 additions & 4 deletions x-pack/plugins/security_solution/server/utils/beat_schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ const convertFieldsToAssociativeArray = (
: {};

export const getIndexAlias = (defaultIndex: string[], indexName: string): string => {
const found = defaultIndex.find((index) => `\\${indexName}`.match(`\\${index}`) != null);
if (found != null) {
return found;
} else {
try {
const found = defaultIndex.find((index) => `\\${indexName}`.match(`\\${index}`) != null);
if (found != null) {
return found;
} else {
return 'unknown';
}
} catch (error) {
// if we encounter an error because the index contains invalid regular expressions then we should return an unknown
// rather than blow up with a toaster error upstream
return 'unknown';
}
};
Expand Down