Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CWE array to the support #309 #310

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CveXplore/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.36
0.3.37
27 changes: 19 additions & 8 deletions CveXplore/core/database_maintenance/sources_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import glob
import hashlib
import json
import re
import shutil
import time
from typing import Any, Tuple
Expand Down Expand Up @@ -694,17 +695,27 @@ def process_the_item(self, item: dict = None):
self.stem(cpeuri["criteria"]),
)
if "weaknesses" in item["cve"]:
cwe_set = set()

for problem in item["cve"]["weaknesses"]:
for cwe in problem[
"description"
]: # NVD JSON not clear if we can get more than one CWE per CVE (until we take the last one) -
# NVD-CWE-Other??? list?
for cwe in problem.get("description", []):
if cwe["lang"] == "en":
cve["cwe"] = cwe["value"]
if not ("cwe" in cve):
cve["cwe"] = defaultvalue["cwe"]
cwe_set.add(cwe["value"])

cve["cwe"] = sorted(cwe_set)

# If at least one valid CWE exists, remove all "NVD-CWE-*" entries
if any(not re.match(r"^NVD-CWE-", cwe) for cwe in cve["cwe"]):
cve["cwe"] = [
cwe for cwe in cve["cwe"] if not re.match(r"^NVD-CWE-", cwe)
]

# If the list is empty after filtering, assign the default value
if not cve["cwe"]:
cve["cwe"] = [defaultvalue["cwe"]]
else:
cve["cwe"] = defaultvalue["cwe"]
# Assign the default value if "weaknesses" is not present
cve["cwe"] = [defaultvalue["cwe"]]

cve["vulnerable_configuration_cpe_2_2"] = []

Expand Down
2 changes: 1 addition & 1 deletion CveXplore/database_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Cves(CveXploreBase):
cvssTime = Column(DateTime, doc="Time of the CVSS of the CVE")
cvssVector = Column(String(100), doc="Vector of the CVSS of the CVE")
configurations = Column(JSON, doc="Vulnerable configurations of the CVE")
cwe = Column(String(50), index=True, doc="Related CWEs to the CVE")
cwe = Column(JSON, default=[], doc="Related CWEs to the CVE")
epss = Column(Float, index=True, doc="Epss of the CVE")
epssMetric = Column(JSON, doc="Epss metric of the CVE")
exploitabilityScore = Column(Float, doc="Exploitability Score of the CVE")
Expand Down