Skip to content

Commit

Permalink
added cidr modifier for detection; fixed detection parsing (#693)
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
(cherry picked from commit 7e5985f)
  • Loading branch information
amsiglan authored and github-actions[bot] committed Nov 22, 2023
1 parent 9263c3a commit a9b7cee
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a9b7cee

Please sign in to comment.