@@ -51,6 +51,7 @@ def __init__(self, e, context):
5151
5252
5353logger = logging .getLogger (__name__ )
54+ _defaultThreatsFile = os .path .dirname (__file__ ) + "/threatlib/threats.json"
5455
5556
5657class var (object ):
@@ -787,8 +788,7 @@ class TM:
787788 )
788789 name = varString ("" , required = True , doc = "Model name" )
789790 description = varString ("" , required = True , doc = "Model description" )
790- threatsFile = varStrings ("" )
791- threatsFileInit = False
791+ threatsFile = varStrings ([_defaultThreatsFile ])
792792 isOrdered = varBool (False , doc = "Automatically order all Dataflows" )
793793 mergeResponses = varBool (False , doc = "Merge response edges in DFDs" )
794794 ignoreUnused = varBool (False , doc = "Ignore elements not used in any Dataflow" )
@@ -836,9 +836,9 @@ def _init_threats(self):
836836
837837 def _add_threats (self ):
838838
839- for threat_file in self .threatsFile :
839+ for tf in self .threatsFile :
840840 try :
841- with open (threat_file , "r" , encoding = "utf8" ) as threat_file :
841+ with open (tf , "r" , encoding = "utf8" ) as threat_file :
842842 threats_json = json .load (threat_file )
843843 except (FileNotFoundError , PermissionError , IsADirectoryError ) as e :
844844 raise UIError (
@@ -1131,14 +1131,19 @@ def _process(self):
11311131
11321132 # delaying loading of threats to accomodate multiple threat files in the
11331133 # command line
1134- if self .threatsFileInit == False :
1135- tfs = [os .path .dirname (__file__ ) + "/threatlib/threats.json" ]
1136- if result .threat_files :
1137- tfs .extend (result .threat_files )
1138- self .threatsFile = tfs
1139- self ._init_threats ()
1140- self .threatsFileInit = True
1141-
1134+ if result .threat_files :
1135+ # start by removing the default
1136+ del self .threatsFile [0 ]
1137+ if "default" in result .threat_files :
1138+ index = result .threat_files .index ("default" )
1139+ result .threat_files [index ] = _defaultThreatsFile
1140+ for x in result .threat_files :
1141+ self .threatsFile .append (x )
1142+ else :
1143+ # it is just the default file, so no need to do anything
1144+ pass
1145+ self ._init_threats ()
1146+
11421147 if result .debug :
11431148 logger .setLevel (logging .DEBUG )
11441149
0 commit comments