From a9b7ceec7339626f5dd45f7371dd7fdb28e43e8f Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Tue, 5 Sep 2023 13:24:52 -0700 Subject: [PATCH] added cidr modifier for detection; fixed detection parsing (#693) Signed-off-by: Amardeepsingh Siglani (cherry picked from commit 7e5985fbdeed097f545cede1ffd0b2a5710271d2) --- .../RuleEditor/DetectionVisualEditor.tsx | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx index 6edbbf2c1..2c20e2392 100644 --- a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx +++ b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx @@ -86,6 +86,7 @@ const detectionModifierOptions = [ { value: 'base64', label: 'base64' }, { value: 'endswith', label: 'endswith' }, { value: 'startswith', label: 'startswith' }, + { value: 'cidr', label: 'cidr' }, ]; const defaultDetectionObj: DetectionObject = { @@ -177,24 +178,28 @@ export class DetectionVisualEditor extends React.Component< const selectionMapJSON = detectionJSON[selectionKey]; const selectionDataEntries: SelectionData[] = []; - Object.keys(selectionMapJSON).forEach((fieldKey, dataIdx) => { - const [field, modifier] = fieldKey.split('|'); - const val = selectionMapJSON[fieldKey]; - const values: any[] = typeof val === 'string' ? [val] : val; - selectionDataEntries.push({ - field, - modifier, - values, - selectedRadioId: `${ - values.length <= 1 ? SelectionMapValueRadioId.VALUE : SelectionMapValueRadioId.LIST - }-${selectionIdx}-${dataIdx}`, + if (typeof selectionMapJSON === 'object') { + Object.keys(selectionMapJSON).forEach((fieldKey, dataIdx) => { + const [field, modifier] = fieldKey.split('|'); + const val = selectionMapJSON[fieldKey]; + const values: any[] = Array.isArray(val) ? val : [val]; + selectionDataEntries.push({ + field, + modifier, + values, + selectedRadioId: `${ + values.length <= 1 ? SelectionMapValueRadioId.VALUE : SelectionMapValueRadioId.LIST + }-${selectionIdx}-${dataIdx}`, + }); }); - }); + } - detectionObj.selections.push({ - name: selectionKey, - data: selectionDataEntries, - }); + if (selectionDataEntries.length) { + detectionObj.selections.push({ + name: selectionKey, + data: selectionDataEntries, + }); + } }); return detectionObj;