-
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
[Security Solution][Endpoint Exceptions] Wildcard warning with IS operator for endpoint exceptions creation/editing #182903
Changes from all commits
0ee80c0
8982ba0
3c7644c
7769015
2e30f0c
e017929
67a18cc
a067bc7
4ebc021
0a70be9
9eff267
2e64791
24ac26d
35ac720
6023385
8e67f21
273975b
dba86b8
dcb1345
ec6eefd
1c90baa
87b1dcb
897f171
17b9665
ef2ad5d
6d4adf0
b2ad473
a448c9e
fddd40d
a4962c8
1772390
fd43dbb
4704ac4
deb623c
315b43a
885046d
351ee80
e685ab4
22d932a
f90749d
d86d499
8c11c8b
5fa9e41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React, { memo, useEffect, useCallback, useMemo, useReducer } from 'react'; | ||
import React, { memo, useEffect, useCallback, useMemo, useReducer, useState } from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import { isEmpty } from 'lodash/fp'; | ||
|
||
|
@@ -30,11 +30,13 @@ import { | |
import { ENDPOINT_LIST_ID } from '@kbn/securitysolution-list-constants'; | ||
import { ExceptionListTypeEnum } from '@kbn/securitysolution-io-ts-list-types'; | ||
import type { OsTypeArray, ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
import { hasWrongOperatorWithWildcard } from '@kbn/securitysolution-list-utils'; | ||
import type { | ||
ExceptionsBuilderExceptionItem, | ||
ExceptionsBuilderReturnExceptionItem, | ||
} from '@kbn/securitysolution-list-utils'; | ||
|
||
import { WildCardWithWrongOperatorCallout } from '@kbn/securitysolution-exception-list-components'; | ||
import type { Moment } from 'moment'; | ||
import type { Status } from '../../../../../common/api/detection_engine'; | ||
import * as i18n from './translations'; | ||
|
@@ -44,6 +46,7 @@ import { | |
retrieveAlertOsTypes, | ||
getPrepopulatedRuleExceptionWithHighlightFields, | ||
} from '../../utils/helpers'; | ||
import { RULE_EXCEPTION, ENDPOINT_EXCEPTION } from '../../utils/translations'; | ||
import type { AlertData } from '../../utils/types'; | ||
import { initialState, createExceptionItemsReducer } from './reducer'; | ||
import { ExceptionsFlyoutMeta } from '../flyout_components/item_meta_form'; | ||
|
@@ -58,6 +61,8 @@ import { useCloseAlertsFromExceptions } from '../../logic/use_close_alerts'; | |
import { ruleTypesThatAllowLargeValueLists } from '../../utils/constants'; | ||
import { useInvalidateFetchRuleByIdQuery } from '../../../rule_management/api/hooks/use_fetch_rule_by_id_query'; | ||
import { ExceptionsExpireTime } from '../flyout_components/expire_time'; | ||
import { CONFIRM_WARNING_MODAL_LABELS } from '../../../../management/common/translations'; | ||
import { ArtifactConfirmModal } from '../../../../management/components/artifact_list_page/components/artifact_confirm_modal'; | ||
|
||
const SectionHeader = styled(EuiTitle)` | ||
${() => css` | ||
|
@@ -117,6 +122,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
onConfirm, | ||
}: AddExceptionFlyoutProps) { | ||
const { euiTheme } = useEuiTheme(); | ||
const [showConfirmModal, setShowConfirmModal] = useState<boolean>(false); | ||
const { isLoading, indexPatterns, getExtendedFields } = useFetchIndexPatterns(rules); | ||
const [isSubmitting, submitNewExceptionItems] = useAddNewExceptionItems(); | ||
const [isClosingAlerts, closeAlerts] = useCloseAlertsFromExceptions(); | ||
|
@@ -165,6 +171,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
errorSubmitting, | ||
expireTime, | ||
expireErrorExists, | ||
wildcardWarningExists, | ||
}, | ||
dispatch, | ||
] = useReducer(createExceptionItemsReducer(), { | ||
|
@@ -193,6 +200,10 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
|
||
const setExceptionItemsToAdd = useCallback( | ||
(items: ExceptionsBuilderReturnExceptionItem[]): void => { | ||
dispatch({ | ||
type: 'setWildcardWithWrongOperator', | ||
warningExists: hasWrongOperatorWithWildcard(items), | ||
}); | ||
dispatch({ | ||
type: 'setExceptionItems', | ||
items, | ||
|
@@ -380,7 +391,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
return hasAlertData ? retrieveAlertOsTypes(alertData) : selectedOs ? [...selectedOs] : []; | ||
}, [hasAlertData, alertData, selectedOs]); | ||
|
||
const handleOnSubmit = useCallback(async (): Promise<void> => { | ||
const submitException = useCallback(async (): Promise<void> => { | ||
if (submitNewExceptionItems == null) return; | ||
|
||
try { | ||
|
@@ -451,6 +462,14 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
expireTime, | ||
]); | ||
|
||
const handleOnSubmit = useCallback(() => { | ||
if (wildcardWarningExists) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think that adding this if statement to the original handleOnSubmit makes sense? We could avoid having another layer of abstraction then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it would make sense in this case since I needed to separate the original submit handler for the confirmation modal. We allows the user to add the exception without addressing the warning in the confirmation modal so I wanted to have that logic on its own for the confirmation modal submit handler. |
||
setShowConfirmModal(true); | ||
} else { | ||
return submitException(); | ||
} | ||
}, [wildcardWarningExists, submitException]); | ||
|
||
const isSubmitButtonDisabled = useMemo( | ||
(): boolean => | ||
isSubmitting || | ||
|
@@ -499,6 +518,24 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
prefix: 'exceptionFlyoutTitle', | ||
}); | ||
|
||
const confirmModal = useMemo(() => { | ||
const { title, body, confirmButton, cancelButton } = CONFIRM_WARNING_MODAL_LABELS( | ||
listType === ExceptionListTypeEnum.ENDPOINT ? ENDPOINT_EXCEPTION : RULE_EXCEPTION | ||
); | ||
|
||
return ( | ||
<ArtifactConfirmModal | ||
title={title} | ||
body={body} | ||
confirmButton={confirmButton} | ||
cancelButton={cancelButton} | ||
onSuccess={submitException} | ||
onCancel={() => setShowConfirmModal(false)} | ||
data-test-subj="artifactConfirmModal" | ||
/> | ||
); | ||
}, [listType, submitException]); | ||
|
||
return ( | ||
<EuiFlyout | ||
size="l" | ||
|
@@ -567,7 +604,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
onSetErrorExists={setConditionsValidationError} | ||
getExtendedFields={getExtendedFields} | ||
/> | ||
|
||
{wildcardWarningExists && <WildCardWithWrongOperatorCallout />} | ||
{listType !== ExceptionListTypeEnum.ENDPOINT && !sharedListToAddTo?.length && ( | ||
<> | ||
<EuiHorizontalRule /> | ||
|
@@ -639,6 +676,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({ | |
</EuiButton> | ||
</FlyoutFooterGroup> | ||
</EuiFlyoutFooter> | ||
{showConfirmModal && confirmModal} | ||
</EuiFlyout> | ||
); | ||
}); |
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.
I was wondering if you could think of a different way to manage these errors/warning? Just updating multiple states at once seems odd, and also having wrappers just for calling prop function seems redundant.
Would you have some time to refactor this component a bit?
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.
I think refactoring would probably have to be at a later stage if that's OK