Skip to content

Commit d85bc0b

Browse files
committed
feat(parser): rework scoring to include partial match and weight
Previously, **all** SAST tools must have found the same CWE or location to count it. Now, if at least two SAST tools found the same CWE or location, it will be counted. Weight has been added to prioritize rarer matches.
1 parent f5dc47f commit d85bc0b

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

codesectools/sasts/all/parser.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@ def stats_by_scores(self) -> dict:
142142
for defect_file, defects in defect_files.items():
143143
defects_cwes = {d.cwe for d in defects if d.cwe.id != -1}
144144

145-
cwes_found_by_all_sasts = 0
145+
defects_same_cwe = 0
146146
for cwe in defects_cwes:
147147
cwes_sasts = {d.sast for d in defects if d.cwe == cwe}
148148
if set(self.sast_names) == cwes_sasts:
149-
cwes_found_by_all_sasts += 1
149+
defects_same_cwe += 1
150+
else:
151+
defects_same_cwe += (
152+
len(set(self.sast_names) & cwes_sasts) - 1
153+
) / len(self.sast_names)
150154

151155
defect_locations = {}
152156
for defect in defects:
@@ -171,15 +175,23 @@ def stats_by_scores(self) -> dict:
171175
self.sast_names
172176
):
173177
defects_same_location_same_cwe += 1
178+
else:
179+
defects_same_location_same_cwe += (
180+
len(
181+
set(defect.sast for defect in defects_)
182+
& set(self.sast_names)
183+
)
184+
- 1
185+
) / len(self.sast_names)
174186

175187
stats[defect_file] = {
176188
"score": {
177189
"defect_number": len(defects),
178-
"unique_cwes_number": len(defects_cwes),
179-
"cwes_found_by_all_sasts": cwes_found_by_all_sasts,
180-
"defects_same_location": defects_same_location,
181-
"defects_same_location_same_cwe": defects_same_location_same_cwe,
182-
}
190+
"defects_same_cwe": defects_same_cwe * 2,
191+
"defects_same_location": defects_same_location * 4,
192+
"defects_same_location_same_cwe": defects_same_location_same_cwe
193+
* 8,
194+
},
183195
}
184196

185197
return stats

0 commit comments

Comments
 (0)