Skip to content

Commit d4b2a60

Browse files
committed
Twistlock Parser add support for discoveredDate
1 parent e188bb4 commit d4b2a60

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

dojo/tools/twistlock/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import textwrap
77
from datetime import datetime
88

9+
import dateutil.parser
10+
911
from dojo.models import Finding
1012

1113
logger = logging.getLogger(__name__)
@@ -235,6 +237,10 @@ def get_item(vulnerability, test, image_metadata=""):
235237
status = vulnerability.get("status", "There seems to be no fix yet. Please check description field.")
236238
cvssv3_score = vulnerability.get("cvss")
237239
riskFactors = vulnerability.get("riskFactors", "No risk factors.")
240+
try:
241+
date = str(dateutil.parser.parse(vulnerability.get("discoveredDate")).date())
242+
except (ValueError, TypeError, dateutil.parser.ParserError):
243+
date = datetime.now()
238244

239245
# Build impact field combining severity and image metadata which can change between scans, so we add it to the impact field as the description field is sometimes used for hash code calculation
240246
impact_parts = [severity]
@@ -264,6 +270,7 @@ def get_item(vulnerability, test, image_metadata=""):
264270
cvssv3=cvssv3,
265271
cvssv3_score=cvssv3_score,
266272
impact=impact_text,
273+
date=date,
267274
)
268275
finding.unsaved_vulnerability_ids = [vulnerability["id"]] if "id" in vulnerability else None
269276
finding.description = finding.description.strip()

unittests/tools/test_twistlock_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def test_parse_file_with_no_link_no_description(self):
113113
self.assertIsNotNone(finding)
114114
self.assertEqual(1, len(finding.unsaved_vulnerability_ids))
115115
self.assertEqual("PRISMA-2021-0013", finding.unsaved_vulnerability_ids[0])
116+
self.assertEqual("2022-11-16", finding.date)
116117
break
117118

118119
def test_parse_file_with_no_cvss(self):
@@ -141,6 +142,7 @@ def test_parse_file_with_no_cvss(self):
141142
self.assertIn("Image ID:", finding.impact)
142143
self.assertIn("Distribution:", finding.impact)
143144
self.assertIn("Debian GNU/Linux 12", finding.impact)
145+
self.assertEqual("2025-07-08", finding.date)
144146

145147
def test_parse_file_with_many_vulns(self):
146148
testfile = (get_unit_tests_scans_path("twistlock") / "many_vulns.json").open(encoding="utf-8")

0 commit comments

Comments
 (0)