Skip to content

Commit

Permalink
[backend] prevent wrong type for empty numeric value (OpenCTI-Platfor…
Browse files Browse the repository at this point in the history
  • Loading branch information
frapuks authored Jun 14, 2024
1 parent e364f82 commit 4c020e0
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { addFilter } from '../utils/filtering/filtering-utils';
import { ENTITY_TYPE_INDICATOR } from '../modules/indicator/indicator-types';
import { controlUserConfidenceAgainstElement } from '../utils/confidence-level';
import { uploadToStorage } from '../database/file-storage-helper';
import { isNumericAttribute } from '../schema/schema-attributes';

export const findById = (context, user, stixCyberObservableId) => {
return storeLoadById(context, user, stixCyberObservableId, ABSTRACT_STIX_CYBER_OBSERVABLE);
Expand Down Expand Up @@ -276,6 +277,10 @@ export const stixCyberObservableEditField = async (context, user, stixCyberObser
input,
opts
);
// Delete the key when updating a numeric field with an empty value (e.g. to delete this value) to avoid a schema error
Object.entries(stixCyberObservable).forEach(([key, value]) => {
if (isNumericAttribute(key) && value === '') delete stixCyberObservable[key];
});
if (input[0].key === 'x_opencti_score') {
const indicators = await listAllFromEntitiesThroughRelations(
context,
Expand Down

0 comments on commit 4c020e0

Please sign in to comment.