Skip to content

Commit cc5d8ef

Browse files
wiz: handle mitigated timestamps (#12168)
* wiz: handle mitigated timestamps * wiz: handle mitigated timestamps * wiz: handle mitigated timestamps * wiz: handle mitigated timestamps * wiz: failsafe * wiz: failsafe * finalize datetime parsing format
1 parent 4dee30e commit cc5d8ef

File tree

4 files changed

+195
-100
lines changed

4 files changed

+195
-100
lines changed

dojo/tools/wiz/parser.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import contextlib
12
import csv
23
import io
34
import json
45
import logging
56
import sys
7+
from datetime import datetime
68

79
from dateutil import parser as date_parser
810

@@ -57,6 +59,35 @@ def parse_findings(self, test: Test, reader: csv.DictReader) -> list[Finding]:
5759
mitigation = row.get("Remediation Recommendation")
5860
description = ""
5961
status_dict = WizcliParsers.convert_status(row.get("Status", None))
62+
if status_dict.get("is_mitigated", False):
63+
# If the finding is mitigated, set the date to the mitigation date
64+
mitigated_timestamp = None
65+
66+
if row.get("Resolved Time", None):
67+
with contextlib.suppress(ValueError):
68+
mitigated_timestamp = date_parser.parse(row.get("Resolved Time"))
69+
70+
if not mitigated_timestamp:
71+
# other timestamps in the wiz scans are ISO8601
72+
# but the Resolved Time is in a different format based on data we've seen
73+
# example value: 2025-04-03 20:20:00.43042 +0000 UTC
74+
75+
resolved_time_string = row.get("Resolved Time")
76+
# need to use suppress as try-except ValueError doesn't work here for some reason
77+
78+
# File "/usr/local/lib/python3.11/_strptime.py", line 352, in _strptime
79+
# raise ValueError("unconverted data remains: %s" %
80+
# ValueError: unconverted data remains: CET
81+
with contextlib.suppress(ValueError):
82+
mitigated_timestamp = datetime.strptime(
83+
resolved_time_string, "%Y-%m-%d %H:%M:%S.%f %z %Z",
84+
)
85+
86+
if not mitigated_timestamp:
87+
logger.warning(f"Unable to parse Resolved Time: {resolved_time_string}")
88+
89+
status_dict["mitigated"] = mitigated_timestamp
90+
6091
# Iterate over the description fields to create the description
6192
for field in description_fields:
6293
if (field_value := row.get(field)) is not None and len(field_value) > 0:

0 commit comments

Comments
 (0)