forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Validate exception list size when adding new items (
elastic#73399) (elastic#73600) * Validate exception list size when adding new items * Update comment * Extract list size validation and apply to endpoint route also Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
5e2bde2
commit 58d97f5
Showing
8 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ExceptionListClient } from '../services/exception_lists/exception_list_client'; | ||
import { MAX_EXCEPTION_LIST_SIZE } from '../../common/constants'; | ||
import { foundExceptionListItemSchema } from '../../common/schemas'; | ||
import { NamespaceType } from '../../common/schemas/types'; | ||
import { validate } from '../../common/siem_common_deps'; | ||
|
||
export const validateExceptionListSize = async ( | ||
exceptionLists: ExceptionListClient, | ||
listId: string, | ||
namespaceType: NamespaceType | ||
): Promise<{ body: string; statusCode: number } | null> => { | ||
const exceptionListItems = await exceptionLists.findExceptionListItem({ | ||
filter: undefined, | ||
listId, | ||
namespaceType, | ||
page: undefined, | ||
perPage: undefined, | ||
sortField: undefined, | ||
sortOrder: undefined, | ||
}); | ||
if (exceptionListItems == null) { | ||
// If exceptionListItems is null then we couldn't find the list so it may have been deleted | ||
return { | ||
body: `Unable to find list id: ${listId} to verify max exception list size`, | ||
statusCode: 500, | ||
}; | ||
} | ||
const [validatedItems, err] = validate(exceptionListItems, foundExceptionListItemSchema); | ||
if (err != null) { | ||
return { | ||
body: err, | ||
statusCode: 500, | ||
}; | ||
} | ||
// Unnecessary since validatedItems comes from exceptionListItems which is already | ||
// checked for null, but typescript fails to detect that | ||
if (validatedItems == null) { | ||
return { | ||
body: `Unable to find list id: ${listId} to verify max exception list size`, | ||
statusCode: 500, | ||
}; | ||
} | ||
if (validatedItems.total > MAX_EXCEPTION_LIST_SIZE) { | ||
return { | ||
body: `Failed to add exception item, exception list would exceed max size of ${MAX_EXCEPTION_LIST_SIZE}`, | ||
statusCode: 400, | ||
}; | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters