Skip to content

Commit

Permalink
adds lowercasing for hash values
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Jul 29, 2020
1 parent 1b2ae14 commit d59a07c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { AddExceptionComments } from '../add_exception_comments';
import {
enrichNewExceptionItemsWithComments,
enrichExceptionItemsWithOS,
lowercaseHashValues,
defaultEndpointExceptionItems,
entryHasListType,
entryHasNonEcsType,
Expand Down Expand Up @@ -256,7 +257,7 @@ export const AddExceptionModal = memo(function AddExceptionModal({
: exceptionItemsToAdd;
if (exceptionListType === 'endpoint') {
const osTypes = retrieveAlertOsTypes();
enriched = enrichExceptionItemsWithOS(enriched, osTypes);
enriched = lowercaseHashValues(enrichExceptionItemsWithOS(enriched, osTypes));
}
return enriched;
}, [comment, exceptionItemsToAdd, exceptionListType, retrieveAlertOsTypes]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
getOperatingSystems,
entryHasListType,
entryHasNonEcsType,
lowercaseHashValues,
} from '../helpers';
import { Loader } from '../../loader';

Expand Down Expand Up @@ -195,7 +196,7 @@ export const EditExceptionModal = memo(function EditExceptionModal({
];
if (exceptionListType === 'endpoint') {
const osTypes = exceptionItem._tags ? getOperatingSystems(exceptionItem._tags) : [];
enriched = enrichExceptionItemsWithOS(enriched, osTypes);
enriched = lowercaseHashValues(enrichExceptionItemsWithOS(enriched, osTypes));
}
return enriched;
}, [exceptionItemsToAdd, exceptionItem, comment, exceptionListType]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,36 @@ export const enrichExceptionItemsWithOS = (
});
};

/**
* Returns given exceptionItems with all hash-related entries lowercased
*/
export const lowercaseHashValues = (
exceptionItems: Array<ExceptionListItemSchema | CreateExceptionListItemSchema>
): Array<ExceptionListItemSchema | CreateExceptionListItemSchema> => {
return exceptionItems.map((item) => {
const newEntries = item.entries.map((itemEntry) => {
if (itemEntry.field.includes('.hash')) {
if (itemEntry.type === 'match') {
return {
...itemEntry,
value: itemEntry.value.toLowerCase(),
};
} else if (itemEntry.type === 'match_any') {
return {
...itemEntry,
value: itemEntry.value.map((val) => val.toLowerCase()),
};
}
}
return itemEntry;
});
return {
...item,
entries: newEntries,
};
});
};

/**
* Returns the value for the given fieldname within TimelineNonEcsData if it exists
*/
Expand Down

0 comments on commit d59a07c

Please sign in to comment.