Skip to content

Commit 7a31b64

Browse files
committed
Significantly enhance scorecard generator:
1) Add commercial average score calculation 2) Add ability to create anonymous scorecards for commercial tools 3) Add ability to suppress commercial tool scorecards and only include the commercial average 4) Add details table to Home and Vulnerability pages
1 parent 5b5e58d commit 7a31b64

File tree

11 files changed

+1043
-420
lines changed

11 files changed

+1043
-420
lines changed

src/main/java/org/owasp/benchmark/score/BenchmarkScore.java

Lines changed: 442 additions & 108 deletions
Large diffs are not rendered by default.

src/main/java/org/owasp/benchmark/score/parsers/Counter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
public class Counter {
2222

23-
public double tp = 0;
24-
public double fn = 0;
25-
public double tn = 0;
26-
public double fp = 0;
23+
public int tp = 0;
24+
public int fn = 0;
25+
public int tn = 0;
26+
public int fp = 0;
2727

2828
}

src/main/java/org/owasp/benchmark/score/parsers/OverallResult.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,26 @@
1919
package org.owasp.benchmark.score.parsers;
2020

2121
public class OverallResult {
22-
public String category;
23-
public double tpr;
24-
public double fpr;
25-
public int total;
26-
public double score;
22+
public final String category;
23+
public final double truePositiveRate;
24+
public final double falsePositiveRate;
25+
public final int total;
26+
public final double score;
2727

28+
/**
29+
* The overall results for a single vulnerability category for a single tool.
30+
* @param category - The vulnerability category.
31+
* @param tpr - The true positive rate
32+
* @param fpr - The false positive rate
33+
* @param total - The total number of TP, FP, TN, FN in this category
34+
* @param score - The tool's score in this category
35+
*/
2836
public OverallResult( String category, double tpr, double fpr, int total, double score) {
2937
this.category = category;
30-
this.tpr = tpr;
31-
this.fpr = fpr;
38+
this.truePositiveRate = tpr;
39+
this.falsePositiveRate = fpr;
3240
this.total = total;
3341
this.score = score;
3442
}
35-
36-
public String getCategory() {
37-
return category;
38-
}
3943

40-
public double getFalsePositiveRate() {
41-
return fpr;
42-
}
43-
44-
public double getTruePositiveRate() {
45-
return tpr;
46-
}
47-
48-
public double getScore() {
49-
return score;
50-
}
5144
}

src/main/java/org/owasp/benchmark/score/parsers/OverallResults.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
public class OverallResults {
3232

3333
private Map<String,OverallResult> map = new TreeMap<String,OverallResult>();
34-
private double score = 0;
34+
private double score = 0; // The overall score for this tool
35+
private int total = 0; // The total number of TP, FP, FN, TN across all test cases for this tool.
3536

3637
// The overall True and False positive rates for this tool. These are values between 1 and 0.
3738
private double TPRate = 0;
3839
private double FPRate = 0;
3940

41+
private Counter findingCounts;
42+
4043
private String time = "Unknown";
4144

4245
public void add( String category, double tpr, double fpr, int total, double score ) {
@@ -110,6 +113,22 @@ public void setFalsePositiveRate(double rate) {
110113
this.FPRate = rate;
111114
}
112115

116+
/**
117+
* Returns the total number of test cases processed with this tool.
118+
* @return The total.
119+
*/
120+
public int getTotal() {
121+
return total;
122+
}
123+
124+
/**
125+
* Set the total number of test cases processed with this tool.
126+
* @param The total.
127+
*/
128+
public void setTotal( int total ) {
129+
this.total = total;
130+
}
131+
113132
/**
114133
* Returns the amount of time it took to run a scan of the Benchmark with this tool.
115134
* @return The Benchmark scan time.
@@ -126,4 +145,16 @@ public void setTime( String elapsed ) {
126145
this.time = elapsed;
127146
}
128147

148+
public void setFindingCounts(int tp, int fp, int fn, int tn) {
149+
this.findingCounts = new Counter();
150+
this.findingCounts.tp = tp;
151+
this.findingCounts.fp = fp;
152+
this.findingCounts.fn = fn;
153+
this.findingCounts.tn = tn;
154+
}
155+
156+
public Counter getFindingCounts() {
157+
return this.findingCounts;
158+
}
159+
129160
}

src/main/java/org/owasp/benchmark/score/parsers/SonarQubeReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public TestResults parse( File f ) throws Exception {
4141
{
4242
TestCaseResult tcr = parseSonarQubeFinding( arr.getJSONObject(i) );
4343
if ( tcr != null ) {
44-
// System.out.println( tcr.getNumber() + " " + tcr.getName() + " -> " + tcr.getCWE() + "\t" + tcr.getEvidence() );
44+
// System.out.println( tcr.getNumber() + "\t" + tcr.getCWE() + "\t" + tcr.getEvidence() );
4545
tr.put( tcr );
4646
}
4747
}

src/main/java/org/owasp/benchmark/score/parsers/TestResults.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,45 @@
2727
import java.util.concurrent.TimeUnit;
2828

2929
/*
30-
* This class contains the actual results for a single tool against the entire Benchmark.
30+
* This class contains the actual results for a single tool against the entire Benchmark, or the
31+
* expected results, if its initialized with the expected results file.
3132
*/
3233

3334
public class TestResults {
34-
private String tool = "Unknown Tool";
35-
private String toolVersion = null;
36-
private String time = "Unknown";
37-
public boolean isCommercial;
38-
public ToolType toolType;
39-
private Map<Integer, List<TestCaseResult>> map = new TreeMap<Integer, List<TestCaseResult>>();
35+
36+
// The types of tools that can generate results
4037
public static enum ToolType{
4138
SAST,
4239
DAST,
4340
IAST
4441
}
45-
public TestResults( String toolname,boolean isCommercial,ToolType toolType) {
42+
43+
// The version of the Benchmark these test results are for
44+
private String benchmarkVersion = "notSet";
45+
46+
private String tool = "Unknown Tool";
47+
private String toolVersion = null;
48+
private String time = "Unknown";
49+
public final boolean isCommercial;
50+
public final ToolType toolType;
51+
private Map<Integer, List<TestCaseResult>> map = new TreeMap<Integer, List<TestCaseResult>>();
52+
53+
public TestResults( String toolname, boolean isCommercial, ToolType toolType) {
4654
this.setTool( toolname );
4755
this.isCommercial = isCommercial;
4856
this.toolType = toolType;
4957

5058
}
5159

60+
// Set the Benchmark version number for this specific set of TestResults
61+
public void setBenchmarkVersion( String version ) {
62+
this.benchmarkVersion = version;
63+
}
64+
65+
public String getBenchmarkVersion() {
66+
return this.benchmarkVersion;
67+
}
68+
5269
public void put( TestCaseResult tcr ) {
5370
List<TestCaseResult> results = map.get( tcr.getNumber() );
5471
if ( results == null ) {

src/main/java/org/owasp/benchmark/score/parsers/ZapReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public TestResults parse(File f) throws Exception {
3939
InputSource is = new InputSource( new FileInputStream(f) );
4040
Document doc = docBuilder.parse(is);
4141

42-
TestResults tr = new TestResults( "ZAP", false, TestResults.ToolType.DAST);
42+
TestResults tr = new TestResults( "OWASP ZAP", false, TestResults.ToolType.DAST);
4343

4444
// If the filename includes an elapsed time in seconds (e.g., TOOLNAME-seconds.xml), set the compute time on the score card.
4545
tr.setTime(f);

0 commit comments

Comments
 (0)