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

Commit a1af6d3

Browse files
[client] fix handling of None values for externalReferences and killChainPhases (#922)
1 parent 8f8a338 commit a1af6d3

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

pycti/utils/opencti_stix2.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ def extract_embedded_relationships(
420420
stix_object["kill_chain_phases"] = self.opencti.get_attribute_in_extension(
421421
"kill_chain_phases", stix_object
422422
)
423-
if "kill_chain_phases" in stix_object:
423+
if (
424+
"kill_chain_phases" in stix_object
425+
and stix_object["kill_chain_phases"] is not None
426+
):
424427
for kill_chain_phase in stix_object["kill_chain_phases"]:
425428
if (
426429
kill_chain_phase["kill_chain_name"] + kill_chain_phase["phase_name"]
@@ -463,7 +466,10 @@ def extract_embedded_relationships(
463466
"type": kill_chain_phase["entity_type"],
464467
}
465468
kill_chain_phases_ids.append(kill_chain_phase["id"])
466-
elif "x_opencti_kill_chain_phases" in stix_object:
469+
elif (
470+
"x_opencti_kill_chain_phases" in stix_object
471+
and stix_object["x_opencti_kill_chain_phases"] is not None
472+
):
467473
for kill_chain_phase in stix_object["x_opencti_kill_chain_phases"]:
468474
if (
469475
kill_chain_phase["kill_chain_name"] + kill_chain_phase["phase_name"]
@@ -525,7 +531,10 @@ def extract_embedded_relationships(
525531
"external_references", stix_object
526532
)
527533
)
528-
if "external_references" in stix_object:
534+
if (
535+
"external_references" in stix_object
536+
and stix_object["external_references"] is not None
537+
):
529538
for external_reference in stix_object["external_references"]:
530539
try:
531540
url = (
@@ -706,7 +715,10 @@ def extract_embedded_relationships(
706715
self.opencti.app_logger.warning(
707716
"Cannot generate external reference"
708717
)
709-
elif "x_opencti_external_references" in stix_object:
718+
elif (
719+
"x_opencti_external_references" in stix_object
720+
and stix_object["x_opencti_external_references"] is not None
721+
):
710722
for external_reference in stix_object["x_opencti_external_references"]:
711723
url = external_reference["url"] if "url" in external_reference else None
712724
source_name = (
@@ -775,7 +787,10 @@ def extract_embedded_relationships(
775787
granted_refs_ids = self.opencti.get_attribute_in_extension(
776788
"granted_refs", stix_object
777789
)
778-
elif "x_opencti_granted_refs" in stix_object:
790+
elif (
791+
"x_opencti_granted_refs" in stix_object
792+
and stix_object["x_opencti_granted_refs"] is not None
793+
):
779794
granted_refs_ids = stix_object["x_opencti_granted_refs"]
780795
# Sample refs
781796
sample_refs_ids = (

pycti/utils/opencti_stix2_splitter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def enlist_element(
123123
else:
124124
item[key] = None
125125
# Case for embedded elements (deduplicating and cleanup)
126-
elif key == "external_references":
126+
elif key == "external_references" and item[key] is not None:
127127
# specific case of splitting external references
128128
# reference_ids = []
129129
deduplicated_references = []
@@ -149,7 +149,7 @@ def enlist_element(
149149
# reference_ids.append(reference_id)
150150
# nb_deps += self.enlist_element(reference_id, raw_data)
151151
item[key] = deduplicated_references
152-
elif key == "kill_chain_phases":
152+
elif key == "kill_chain_phases" and item[key] is not None:
153153
# specific case of splitting kill_chain phases
154154
# kill_chain_ids = []
155155
deduplicated_kill_chain = []

0 commit comments

Comments
 (0)