Skip to content

Commit 6c10710

Browse files
Dont add ext def to report (#130)
* remove ext defs from report.object_refs #126 * make `incident_classification` a list #127 --------- Co-authored-by: Fadl <[email protected]>
1 parent 422d4d9 commit 6c10710

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

txt2stix/ai_extractor/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RelationshipList(BaseModel):
3333
class DescribesIncident(BaseModel):
3434
describes_incident: bool = Field(description="does the <document> include malware analysis, APT group reports, data breaches and vulnerabilities?")
3535
explanation: str = Field(description="Two or three sentence summary of the incidents it describes OR summary of what it describes instead of an incident")
36-
incident_classification : str = Field(description="One of valid incident classifications that best describes this document/report")
36+
incident_classification : list[str] = Field(description="All the valid incident classifications that describe this document/report")
3737

3838
class AttackFlowItem(BaseModel):
3939
position : int = Field(description="order of object starting at 0")

txt2stix/stix.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def __init__(
240240
confidence=confidence,
241241
)
242242
self.report.object_refs.clear() # clear object refs
243+
self.added_objects = set()
243244
self.set_defaults()
244245

245246
def set_defaults(self):
@@ -264,18 +265,20 @@ def add_extension(self, object):
264265
logger.info(f'getting extension definition for "{_type}" from `{url}`')
265266
self.EXTENSION_MAPPING[_type] = self.load_object_from_json(url)
266267
extension = self.EXTENSION_MAPPING[_type]
267-
self.add_ref(extension)
268+
self.add_ref(extension, is_report_object=False)
268269

269270
@staticmethod
270271
def load_object_from_json(url):
271272
resp = requests.get(url)
272273
return dict_to_stix2(resp.json())
273274

274-
def add_ref(self, sdo):
275+
def add_ref(self, sdo, is_report_object=True):
275276
self.add_extension(sdo)
276277
sdo_id = sdo["id"]
277-
if sdo_id not in self.report.object_refs:
278-
self.report.object_refs.append(sdo_id)
278+
if sdo_id not in self.added_objects:
279+
self.added_objects.add(sdo_id)
280+
if is_report_object:
281+
self.report.object_refs.append(sdo_id)
279282
self.bundle.objects.append(sdo)
280283

281284
sdo_value = ""
@@ -426,5 +429,6 @@ def flow_objects(self, objects):
426429
for obj in objects:
427430
if obj['id'] == self.report.id:
428431
continue
429-
self.add_ref(obj)
432+
is_report_object = obj['type'] != "extension-definition"
433+
self.add_ref(obj, is_report_object=is_report_object)
430434
self._flow_objects = objects

0 commit comments

Comments
 (0)