Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 46f5f3c

Browse files
[client] Improve stix splitter to excludes unsupported references (#332)
1 parent 428c29d commit 46f5f3c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pycti/utils/opencti_stix2_splitter.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import json
22
import uuid
3+
import re
4+
5+
MITRE_X_CAPEC = (
6+
"x_capec_*" # https://github.com/mitre-attack/attack-stix-data/issues/34
7+
)
8+
unsupported_ref_patterns = [MITRE_X_CAPEC]
39

410

511
class OpenCTIStix2Splitter:
612
def __init__(self):
713
self.cache_index = {}
814
self.elements = []
15+
self.unsupported_patterns = list(
16+
map(lambda pattern: re.compile(pattern), unsupported_ref_patterns)
17+
)
18+
19+
def is_ref_key_supported(self, key):
20+
for pattern in self.unsupported_patterns:
21+
if pattern.match(key):
22+
return False
23+
return True
924

1025
def enlist_element(self, item_id, raw_data):
1126
nb_deps = 1
@@ -18,14 +33,14 @@ def enlist_element(self, item_id, raw_data):
1833
item = raw_data[item_id]
1934
for key in list(item.keys()):
2035
value = item[key]
21-
if key.endswith("_refs"):
36+
if key.endswith("_refs") and self.is_ref_key_supported(key):
2237
to_keep = []
2338
for element_ref in item[key]:
2439
if element_ref != item_id:
2540
nb_deps += self.enlist_element(element_ref, raw_data)
2641
to_keep.append(element_ref)
2742
item[key] = to_keep
28-
elif key.endswith("_ref"):
43+
elif key.endswith("_ref") and self.is_ref_key_supported(key):
2944
if item[key] == item_id:
3045
item[key] = None
3146
else:

0 commit comments

Comments
 (0)