File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ def validate(self, rule: SigmaRuleBase) -> List[SigmaValidationIssue]:
125125 for technique in technique_tags :
126126 technique_upper = technique .upper ()
127127
128+ # Check if the technique exists in mapping before accessing it
128129 if technique_upper in mitre_attack_techniques_tactics_mapping :
129130 required_tactics = mitre_attack_techniques_tactics_mapping [technique_upper ]
130131 missing_tactics .extend (
@@ -133,10 +134,12 @@ def validate(self, rule: SigmaRuleBase) -> List[SigmaValidationIssue]:
133134
134135 if missing_tactics :
135136 for missing_tactic in set (missing_tactics ):
137+ # Add safety check to ensure technique exists before accessing mapping
136138 techniques = [
137139 technique
138140 for technique in technique_tags
139- if missing_tactic in mitre_attack_techniques_tactics_mapping [technique .upper ()]
141+ if technique .upper () in mitre_attack_techniques_tactics_mapping
142+ and missing_tactic in mitre_attack_techniques_tactics_mapping [technique .upper ()]
140143 ]
141144 issues .append (
142145 SigmahqTagsTechniquesWithoutTacticsIssue (
Original file line number Diff line number Diff line change @@ -275,3 +275,26 @@ def test_validator_SigmahqTagsTechniquesWithoutTactics_valid():
275275 """
276276 )
277277 assert validator .validate (rule ) == []
278+
279+
280+ def test_validator_SigmahqTagsInvalidTechnique ():
281+ """Test that invalid MITRE technique codes don't cause KeyError"""
282+ validator = SigmahqTagsTechniquesWithoutTacticsValidator ()
283+ # This rule contains an invalid T123456789 technique code
284+ rule = SigmaRule .from_yaml (
285+ """
286+ title: test
287+ status: unsupported
288+ tags:
289+ - attack.t123456789
290+ - tlp.clear
291+ logsource:
292+ category: test
293+ detection:
294+ sel:
295+ field: path\\ *something
296+ condition: sel
297+ """
298+ )
299+ # Should not raise KeyError, should return empty list since invalid technique is ignored
300+ assert validator .validate (rule ) == []
You canβt perform that action at this time.
0 commit comments