diff --git a/support/scripts/cve-check b/support/scripts/cve-check index bcd970bad8..5047523ade 100755 --- a/support/scripts/cve-check +++ b/support/scripts/cve-check @@ -12,10 +12,10 @@ from collections import defaultdict from pathlib import Path from typing import TypedDict +from datetime import datetime, timezone import argparse import sys import json - import cve as cvecheck @@ -35,6 +35,24 @@ locally. brpath = Path(__file__).parent.parent.parent +def datetime_to_rfc3339(dt_string): + """Normalize datetime string to RFC 3339 format with Z suffix. + + NVD dates are already in ISO format, just need to add the Z suffix. + + Input: "1999-01-01T05:00:00.000" + Output: "1999-01-01T05:00:00.000Z" + """ + dt = datetime.fromisoformat(dt_string.replace('Z', '+00:00')) + + if dt.tzinfo is None: + dt = dt.replace(tzinfo=timezone.utc) + else: + dt = dt.astimezone(timezone.utc) + + return dt.isoformat().replace('+00:00', 'Z') + + def cve_api_get_lang_from_list(values, lang="en") -> (str | None): for x in values: if x.get("lang") == lang: @@ -134,10 +152,10 @@ def nvd_cve_to_cdx_vulnerability(nvd_cve): "url": f"https://nvd.nist.gov/vuln/detail/{nvd_cve['id']}" }, **({ - "published": nvd_cve["published"], + "published": datetime_to_rfc3339(nvd_cve["published"]), } if "published" in nvd_cve else {}), **({ - "updated": nvd_cve["lastModified"], + "updated": datetime_to_rfc3339(nvd_cve["lastModified"]), } if "lastModified" in nvd_cve else {}), **({ "cwes": nvd_cve_weaknesses_to_cdx(nvd_cve["weaknesses"]),