From d43657aeb8bcd81a00c74603af5b6b7a0a920fab Mon Sep 17 00:00:00 2001 From: Adrien Servel <50013774+Kedae@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:20:57 +0100 Subject: [PATCH] [backend] Fix on instance trigger incorrect message when updating the standard Id (#6198) --- .../src/utils/filtering/filtering-resolution.ts | 8 +++++--- .../src/utils/filtering/filtering-stix/stix-testers.ts | 2 +- .../tests/01-unit/database/stix-filtering-testers-test.ts | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/utils/filtering/filtering-resolution.ts b/opencti-platform/opencti-graphql/src/utils/filtering/filtering-resolution.ts index 61d5c57b22aef..055b3d7bbe5b5 100644 --- a/opencti-platform/opencti-graphql/src/utils/filtering/filtering-resolution.ts +++ b/opencti-platform/opencti-graphql/src/utils/filtering/filtering-resolution.ts @@ -23,6 +23,7 @@ import { ENTITY_TYPE_RESOLVED_FILTERS } from '../../schema/stixDomainObject'; import { extractFilterGroupValues, isFilterGroupNotEmpty } from './filtering-utils'; import { ENTITY_TYPE_STATUS } from '../../schema/internalObject'; import type { BasicWorkflowStatus } from '../../types/store'; +import { STIX_EXT_OCTI } from '../../types/stix-extensions'; // list of all filters that needs resolution export const RESOLUTION_FILTERS = [ @@ -125,7 +126,7 @@ export const resolveFilterGroup = async ( /** * Build a resolution map thanks to the cache */ -const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser, filter: Filter, cache: Map) : Promise => { +const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser, filter: Filter, cache: Map): Promise => { const map: Map = new Map(); if (Object.keys(STIX_RESOLUTION_MAP_PATHS).includes(filter.key[0])) { for (let index = 0; index < filter.values.length; index += 1) { @@ -139,8 +140,9 @@ const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser, if (!(await isUserCanAccessStixElement(context, user, cachedObject))) { // invalidate the filter value; it won't match ever, but we keep track of this invalidation for debug purposes map.set(v, ''); + } else if (filter.key[0] === CONNECTED_TO_INSTANCE_FILTER) { + map.set(v, cachedObject.extensions[STIX_EXT_OCTI].id); } else { - // resolve according to path const cachedValue = cachedObject[path]; if (typeof cachedValue === 'string') { map.set(v, cachedValue); @@ -153,7 +155,7 @@ const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser, return map; }; -const mergeMaps = (mapArray: Map[]) : Map => { +const mergeMaps = (mapArray: Map[]): Map => { const mergedMap = new Map(); mapArray.forEach((map) => { diff --git a/opencti-platform/opencti-graphql/src/utils/filtering/filtering-stix/stix-testers.ts b/opencti-platform/opencti-graphql/src/utils/filtering/filtering-stix/stix-testers.ts index d9fe3d6071c07..1dc4a80231cf2 100644 --- a/opencti-platform/opencti-graphql/src/utils/filtering/filtering-stix/stix-testers.ts +++ b/opencti-platform/opencti-graphql/src/utils/filtering/filtering-stix/stix-testers.ts @@ -274,7 +274,7 @@ export const testConnectedTo = (stix: any, filter: Filter) => { if (filter.operator && filter.operator !== 'eq') { return false; } - return testStringFilter(filter, [stix.id]); + return testStringFilter(filter, [stix.extensions[STIX_EXT_OCTI].id]); }; /** diff --git a/opencti-platform/opencti-graphql/tests/01-unit/database/stix-filtering-testers-test.ts b/opencti-platform/opencti-graphql/tests/01-unit/database/stix-filtering-testers-test.ts index f0e835011c189..033c48d4eeb96 100644 --- a/opencti-platform/opencti-graphql/tests/01-unit/database/stix-filtering-testers-test.ts +++ b/opencti-platform/opencti-graphql/tests/01-unit/database/stix-filtering-testers-test.ts @@ -648,7 +648,7 @@ describe('Stix filter testers', () => { key: ['connectedToId'], mode: 'or', operator: 'eq', - values: ['', 'report--f3e554eb-60f5-587c-9191-4f25e9ba9f32'] + values: ['', 'f13cd64f-9268-4d77-9850-eb6fbe322463'] } as Filter; expect(testers.testConnectedTo(stixReport, filter)).toEqual(true); expect(testers.testConnectedTo(stixSighting, filter)).toEqual(false);