Skip to content

Commit fcab916

Browse files
committed
update
1 parent 93880fa commit fcab916

2 files changed

Lines changed: 43 additions & 12 deletions

File tree

dojo/tools/n0s1/parser.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
12
import json
23

34
from dojo.models import Finding
5+
from dojo.tools.parser_test import ParserTest
46

57

68
class N0s1Parser:
@@ -13,27 +15,45 @@ def get_label_for_scan_types(self, scan_type):
1315
def get_description_for_scan_types(self, scan_type):
1416
return "JSON output from the n0s1 scanner."
1517

16-
def get_findings(self, filename, test):
17-
dupes = {}
18-
tree = filename.read()
19-
try:
20-
data = json.loads(str(tree, "utf-8"))
21-
except Exception:
22-
data = json.loads(tree)
18+
def get_tests(self, scan_type, handle):
19+
data = json.load(handle)
20+
tests = []
21+
22+
# Determine sub-scanner type based on platform or regex_config
23+
subscanner = "n0s1"
24+
findings = data.get("findings", {})
25+
platforms = {f.get("details", {}).get("platform", "") for f in findings.values()}
26+
if "Confluence" in platforms:
27+
subscanner = "n0s1 Confluence"
28+
elif "GitHub" in platforms:
29+
subscanner = "n0s1 GitHub"
30+
elif "GitLab" in platforms:
31+
subscanner = "n0s1 GitLab"
32+
# Add more platform checks as needed
33+
34+
test = ParserTest(
35+
name=subscanner,
36+
parser_type=subscanner,
37+
version=data.get("tool", {}).get("version", ""),
38+
description=f"Scan from {subscanner}",
39+
)
2340

24-
# Load global regex rules
41+
test.findings = self.get_findings_from_data(data, test)
42+
tests.append(test)
43+
return tests
44+
45+
def get_findings_from_data(self, data, test):
46+
dupes = {}
2547
regex_configs = {}
2648
if "regex_config" in data and "rules" in data["regex_config"]:
2749
for rule in data["regex_config"]["rules"]:
2850
regex_configs[rule["id"]] = rule
2951

30-
# Iterate over findings
3152
for finding_id, finding_data in data.get("findings", {}).items():
3253
details = finding_data.get("details", {})
3354
regex_ref = details.get("matched_regex_config", {})
3455
regex_id = regex_ref.get("id")
3556

36-
# Merge global config with local override
3757
regex_info = regex_configs.get(regex_id, {})
3858
merged_regex = {
3959
"id": regex_id,
@@ -42,7 +62,6 @@ def get_findings(self, filename, test):
4262
"keywords": regex_info.get("keywords", []),
4363
"tags": regex_info.get("tags", []),
4464
}
45-
4665
title = merged_regex["id"] or "n0s1 Finding"
4766
description = f"**URL:** {finding_data.get('url', 'N/A')}\n"
4867
description += f"**Secret:** {finding_data.get('secret', 'N/A')}\n"
@@ -62,7 +81,7 @@ def get_findings(self, filename, test):
6281
title=title,
6382
test=test,
6483
description=description,
65-
severity="High", # Adjust if needed
84+
severity="High",
6685
dynamic_finding=True,
6786
static_finding=False,
6887
unique_id_from_tool=dupe_key,

unittests/tools/test_n0s1_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ def test_n0s1_parser_with_multiple_findings(self):
1515
self.assertEqual(finding.title, "AWS")
1616
self.assertIsNotNone(finding.description)
1717
self.assertTrue(finding.dynamic_finding)
18+
19+
def test_n0s1_get_tests_returns_correct_subscanner(self):
20+
with (get_unit_tests_scans_path("n0s1") / "many_findings.json").open(encoding="utf-8") as testfile:
21+
parser = N0s1Parser()
22+
tests = parser.get_tests("n0s1 Scanner", testfile)
23+
self.assertEqual(1, len(tests))
24+
test = tests[0]
25+
self.assertEqual("n0s1 Confluence", test.name)
26+
self.assertEqual("n0s1 Confluence", test.parser_type)
27+
self.assertEqual("Scan from n0s1 Confluence", test.description)
28+
self.assertEqual(17, len(test.findings))
29+
self.assertTrue(all(f.dynamic_finding for f in test.findings))

0 commit comments

Comments
 (0)