Skip to content

Commit b421345

Browse files
committed
add checks to initialize References() when missing, prevent empty TTPs tags. closes #366
1 parent cefbf2f commit b421345

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

stix/common/information_source.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class InformationSource(stix.Entity):
2222
_binding_class = stix_common_binding.InformationSourceType
2323
_namespace = 'http://stix.mitre.org/common-1'
2424

25-
identity = fields.TypedField("Identity", type_=Identity, factory=IdentityFactory)
25+
identity = fields.TypedField("Identity", Identity, factory=IdentityFactory)
2626
descriptions = fields.TypedField("Description", StructuredTextList)
2727
contributing_sources = fields.TypedField("Contributing_Sources", type_="stix.common.information_source.ContributingSources")
2828
time = fields.TypedField("Time", cybox.common.Time)
@@ -39,15 +39,15 @@ def __init__(self, description=None, identity=None, time=None, tools=None, contr
3939
self.time = time
4040
self.tools = tools
4141
self.references = references
42-
#self.roles = None
4342

4443
def add_contributing_source(self, value):
4544
self.contributing_sources.append(value)
4645

47-
4846
def add_reference(self, value):
4947
if not value:
5048
return
49+
if self.references is None:
50+
self.references = References()
5151
# TODO: Check if it's a valid URI?
5252
self.references.append(value)
5353

@@ -80,7 +80,6 @@ def add_description(self, description):
8080
"""
8181
self.descriptions.add(description)
8282

83-
8483
def add_role(self, value):
8584
self.roles.append(value)
8685

@@ -95,4 +94,3 @@ class ContributingSources(stix.EntityList):
9594
@classmethod
9695
def _dict_as_list(cls):
9796
return False
98-

stix/core/stix_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self, id_=None, idref=None, timestamp=None, stix_header=None,
104104
self.indicators = indicators or Indicators()
105105
self.incidents = incidents or Incidents()
106106
self.threat_actors = threat_actors or ThreatActors()
107-
self.ttps = ttps or TTPs()
107+
self.ttps = ttps
108108
self.related_packages = related_packages
109109
self.reports = reports or Reports()
110110
self.timestamp = timestamp

stix/core/ttps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ def __init__(self, ttps=None):
3232

3333
def add_ttp(self, ttp):
3434
self.ttp.append(ttp)
35+
36+
def add_kill_chain(self, kc):
37+
if self.kill_chains is None:
38+
self.kill_chains = KillChains()
39+
self.kill_chains.kill_chain.append(kc)

stix/exploit_target/vulnerability.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
from mixbox import fields
55

66
import stix
7-
import stix.utils as utils
87
import stix.bindings.exploit_target as exploit_target_binding
9-
import stix.bindings.stix_common as stix_common_binding
10-
from stix.common import DateTimeWithPrecision, StructuredTextList
8+
from stix.common import DateTimeWithPrecision, References, StructuredTextList
119
from stix.common.related import GenericRelationshipList, RelatedObservable
12-
from mixbox import entities, fields
13-
from stix.common import References
10+
1411

1512
class Vulnerability(stix.Entity):
1613
"""Implementation of STIX ``Vulnerability``.
@@ -44,7 +41,6 @@ def __init__(self, title=None, description=None, short_description=None):
4441
self.title = title
4542
self.descriptions = StructuredTextList(description)
4643
self.short_descriptions = StructuredTextList(short_description)
47-
self.references = []
4844

4945
@property
5046
def description(self):
@@ -102,9 +98,11 @@ def add_short_description(self, description):
10298
def add_reference(self, reference):
10399
if not reference:
104100
return
105-
101+
if self.references is None:
102+
self.references = References()
106103
self.references.append(reference)
107104

105+
108106
class CVSSVector(stix.Entity):
109107
"""
110108
Common Vulnerabilit Scoring System object, representing its component measures

0 commit comments

Comments
 (0)