Skip to content

Commit 42077f8

Browse files
frack113phantinuss
andauthored
fix: issue #56 (#57)
* fix: πŸ› Fix SigmahqTagsTechniquesWithoutTacticsValidator with invalid technique code 56 * style: πŸ’„ Run black * Apply suggestions from code review Co-authored-by: phantinuss <79651203+phantinuss@users.noreply.github.com> --------- Co-authored-by: phantinuss <79651203+phantinuss@users.noreply.github.com>
1 parent acf2959 commit 42077f8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

β€Žsigma/validators/sigmahq/tags.pyβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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(

β€Žtests/test_tags.pyβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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) == []

0 commit comments

Comments
Β (0)