Skip to content

Commit

Permalink
cve-filter: Add variables to set the SCORE Cut off values
Browse files Browse the repository at this point in the history
Signed-off-by: Rodrigo M. Duarte <[email protected]>
(cherry picked from commit f2a3f41)
  • Loading branch information
mdrodrigo committed Jul 4, 2024
1 parent 4b71ce7 commit 7ea8815
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions classes/cve-filter.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
# Example: "CVE-2017-6264 CVE-2023-1234"
# Default: empty

# CVE_FILTER_SCOREV2_CUTTOFF and CVE_FILTER_SCOREV3_CUTTOFF:
# Set the value of cut off CVE Score to SCOREV2 and V3. CVEs below the value
# set here will no be considered.
# Example: "9"
# Default: "0"

# Set the PATH to find the old CVE Json list
CVE_FILTER_PREVIOUS_FILE ??= ""
CVE_FILTER_PREVIOUS_VERSION ??= "0.0.0"
Expand All @@ -51,6 +57,10 @@ CVE_FILTER_MARKDOWN_FILE = "${IMGDEPLOYDIR}/${CVE_FILTER_MARKDOWN_FILE_NAME}"
# List of CVE should be ignored Eg: CVE-2023-1234
CVE_FILTER_IGNORED_CVES ??= ""

# Cut off score V2 and V3 value
CVE_FILTER_SCOREV2_CUTOFF ??= "0"
CVE_FILTER_SCOREV3_CUTOFF ??= "0"

inherit python3native

python do_cve_filter (){
Expand All @@ -59,6 +69,8 @@ python do_cve_filter (){
previousFile = d.getVar("CVE_FILTER_PREVIOUS_FILE")
previousVersion = d.getVar("CVE_FILTER_PREVIOUS_VERSION")
cveIgnoreList = d.getVar("CVE_FILTER_IGNORED_CVES").split()
scoreV2CutOff = int(d.getVar("CVE_FILTER_SCOREV2_CUTOFF"))
scoreV3CutOff = int(d.getVar("CVE_FILTER_SCOREV3_CUTOFF"))

cve_prev = Cve()
cve_prev.setMarkdonFileName(d.getVar("CVE_FILTER_MARKDOWN_FILE"))
Expand All @@ -67,13 +79,17 @@ python do_cve_filter (){
if previousFile:
cve_prev.loadCVEfile(previousFile)
cve_prev.setCVEVersion(previousVersion)
cve_prev.setScoreV2CutOff(scoreV2CutOff)
cve_prev.setScoreV3CutOff(scoreV3CutOff)
cve_prev.setIgnoreCVEList(cveIgnoreList)
cve_prev.loadCVEData()
else:
bb.warn("Previous CVE File Not Defined!!!")

cve_curr.loadCVEfile(d.getVar("CVE_FILTER_CURRENT_FILE"))
cve_curr.setCVEVersion(d.getVar("CVE_FILTER_CURRENT_VERSION"))
cve_curr.setScoreV2CutOff(scoreV2CutOff)
cve_curr.setScoreV3CutOff(scoreV3CutOff)
cve_curr.setIgnoreCVEList(cveIgnoreList)
cve_curr.loadCVEData()
cve_prev.compareCVes(cve_curr)
Expand Down
10 changes: 9 additions & 1 deletion lib/ossystems/cve_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def __init__(self):
self.__printIssues = []
self.__ignored_cves = []
self.__version = 0
self.__scoreV2cf = 0
self.__scoreV3cf = 0

# def __del__ (self):
# self.__cveJsonFile.close()
Expand Down Expand Up @@ -112,6 +114,12 @@ def setIgnoreCVEList(self, listcve):
def setCVEVersion(self, version=0):
self.__version = version

def setScoreV2CutOff(self, score):
self.__scoreV2cf = score

def setScoreV3CutOff(self, score):
self.__scoreV3cf = score

def getCVEPackages(self):
return self.__packages

Expand All @@ -126,7 +134,7 @@ def loadCVEData(self):
p = Package(pack["name"], pack["version"])
entry = False
for id in pack["issue"]:
if (float(id["scorev2"]) >= 9 or float(id["scorev3"]) >= 9) and id[
if (float(id["scorev2"]) >= self.__scoreV2cf or float(id["scorev3"]) >= self.__scoreV3cf) and id[
"status"
] != "Ignored":
if not (id["id"] in self.__ignored_cves):
Expand Down

0 comments on commit 7ea8815

Please sign in to comment.