Skip to content

Commit f0e5b35

Browse files
author
Dave Wichers
committed
More improvements to scoring for Fortify, Semgrep and Klockwork.
1 parent e8f2ff6 commit f0e5b35

File tree

3 files changed

+90
-18
lines changed

3 files changed

+90
-18
lines changed

plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/FortifyReader.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,33 @@ private int cweLookup(String vtype, String subtype, Node unifiedNode, String cla
234234
case "Access Specifier Manipulation":
235235
return CweNumber.IMPROPER_ACCESS_CONTROL;
236236

237+
case "Code Correctness":
238+
{
239+
switch (subtype) {
240+
case "Call to sleep() in Lock":
241+
return 833; // Deadlock
242+
case "Call to Thread.run()":
243+
return 572; // Call to Thread run() instead of start()
244+
case "Erroneous finalize() Method":
245+
return 568; // finalize() Method without super.finalize()
246+
case "Erroneous String Compare":
247+
return 597; // Use of Wrong Operator in String Comparison
248+
249+
case "ToString on Array":
250+
case "Multiple Stream Commits":
251+
return CweNumber.DONTCARE;
252+
253+
default:
254+
if (classname != null)
255+
System.out.println(
256+
"Fortify parser found vulnerability type: 'Code Correctness', with unmapped subtype: "
257+
+ subtype
258+
+ " in class: "
259+
+ classname);
260+
}
261+
return CweNumber.UNKNOWN;
262+
}
263+
237264
case "Command Injection":
238265
return CweNumber.COMMAND_INJECTION;
239266

@@ -295,6 +322,7 @@ private int cweLookup(String vtype, String subtype, Node unifiedNode, String cla
295322
case "Insecure Transport":
296323
return 319; // Cleartext Transmission of Sensitive Info
297324

325+
// Deprecated rule set last updated in 2017
298326
case "Insider Threat":
299327
{
300328
switch (subtype) {
@@ -367,6 +395,7 @@ private int cweLookup(String vtype, String subtype, Node unifiedNode, String cla
367395
case "Missing Check against Null":
368396
case "Missing Check for Null Parameter":
369397
case "Null Dereference":
398+
case "Redundant Null Check":
370399
return 476; // Null Pointer Dereference
371400

372401
case "Missing XML Validation":
@@ -462,8 +491,16 @@ private int cweLookup(String vtype, String subtype, Node unifiedNode, String cla
462491
case "Poor Style":
463492
{
464493
switch (subtype) {
494+
case "Non-final Public Static Field":
495+
return 500; // Public Static Field Not Marked Final
496+
case "Value Never Read":
497+
return 563; // Assignment to Variable without Use
465498
case "Empty Synchronized Block":
466499
return 585; // Empty Synchronized Block
500+
case "Explicit Call to finalize()":
501+
return 586; // Explicit Call to finalize()
502+
case "Redundant Initialization":
503+
return CweNumber.DONTCARE;
467504
default:
468505
System.out.println(
469506
"Fortify parser found vulnerability type: 'Poor Style', with unmapped subtype: "
@@ -478,8 +515,6 @@ private int cweLookup(String vtype, String subtype, Node unifiedNode, String cla
478515
return 359; // Exposure of Private Personal Info
479516
case "Race Condition":
480517
return 362;
481-
case "Redundant Null Check":
482-
return 1041; // Use of Redundant Code
483518
case "Resource Injection":
484519
return 99; // Resource Injection
485520

@@ -563,7 +598,6 @@ private int cweLookup(String vtype, String subtype, Node unifiedNode, String cla
563598

564599
// Things we don't care about
565600
case "Build Misconfiguration":
566-
case "Code Correctness":
567601
case "Hardcoded Domain in HTML":
568602
case "J2EE Misconfiguration":
569603
case "Poor Logging Practice":

plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/KlocworkCSVReader.java

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,16 @@ static int cweLookup(String checkerKey) {
8383
switch (checkerKey) {
8484
case "ESCMP.EMPTYSTR": // Inefficient empty string comparison
8585
case "JD.CAST.DOWNCAST": // Possible ClassCastException for subtypes
86-
case "NPE.RET": // Null Pointer Returned from Method
87-
case "NPE.RET.UTIL": // Null Pointer Returned from Map or Collection
86+
case "JD.METHOD.CBS": // Method can be declared static
8887
case "REDUN.FINAL": // Redundant Final Modifier
89-
case "REDUN.NULL": // Use of Variable instead of Null Constant
90-
case "REDUN.OP": // Suspicious operation w/ same expression on both sides
91-
case "RLK.IN": // Input stream not closed on exit
92-
case "RLK.OUT": // Output stream not closed on exit
93-
case "SV.DATA.DB": // Data Injection - Untrusted data inserted into a Database
88+
case "SV.IL.FILE": // File Name Leaking
9489
case "SV.IL.SESSION": // Logging of Session ID
90+
case "SV.IL.SESSION.CLIENT": // HttpServletRequest.getRequestedSessionId() should not be
91+
// used
92+
case "SV.EXPOSE.IFIELD": // Non-final public field could be changed by malicious code or
93+
// accident
9594
case "SV.LOADLIB.INJ": // Untrusted call to loadLibrary method
9695
case "SV.SERIAL.NON": // Class implements Serializable
97-
case "SV.SERIAL.NOREAD": // Method readObject() should be defined for serializable class
98-
case "SV.SERIAL.NOWRITE": // Method writeObject() should be defined for serializable
99-
// class
10096
case "SV.SHARED.VAR": // Unsynchronized access to static variable from servlet
10197
case "SV.UMD.MAIN": // Unnecessary Main() method
10298
return CweNumber.DONTCARE;
@@ -108,9 +104,6 @@ static int cweLookup(String checkerKey) {
108104
case "SV.EXEC.LOCAL": // Process Injection. Local Arguments
109105
case "SV.EXEC.PATH": // Untrusted Search Path
110106
return CweNumber.COMMAND_INJECTION;
111-
case "SV.HASH.NO_SALT": // Use of a one-way cryptographic hash without a salt
112-
return 759; // CWE-759: Use of a One-Way Hash without a Salt
113-
// Not the same as: CweNumber.WEAK_HASH_ALGO; - CWE: 328 Weak Hashing
114107
case "SV.LDAP": // Unvalidated user input is used as LDAP filter
115108
return CweNumber.LDAP_INJECTION;
116109
case "SV.PATH": // Path and file name injection
@@ -121,13 +114,16 @@ static int cweLookup(String checkerKey) {
121114
case "SV.SSRF.URI":
122115
return CweNumber.SSRF;
123116
case "SV.SQL": // SQL Injection
117+
case "SV.SQL.DBSOURCE": // Unchecked info from DB used in SQL Statement
124118
return CweNumber.SQL_INJECTION;
125119
case "SV.WEAK.CRYPT": // Use of a Broken or Risky Cryptographic Algorithm
126120
return CweNumber.WEAK_CRYPTO_ALGO;
127121
case "SV.XPATH": // Unvalidated user input is used as an XPath expression
128122
return CweNumber.XPATH_INJECTION;
129123
case "SV.XSS.COOKIE": // Sensitive cookie without setHttpOnly flag
130124
return CweNumber.COOKIE_WITHOUT_HTTPONLY;
125+
case "SV.XSS.COOKIE.SECURE":
126+
return CweNumber.INSECURE_COOKIE;
131127
case "SV.XSS.DB": // Cross Site Scripting (Stored XSS)
132128
case "SV.XSS.REF": // Cross Site Scripting (Reflected XSS)
133129
return CweNumber.XSS;
@@ -141,25 +137,35 @@ static int cweLookup(String checkerKey) {
141137

142138
case "SV.TAINT_NATIVE":
143139
return 111; // Direct Use of Unsafe JNI
140+
case "SV.HTTP_SPLIT":
141+
return 113; // HTTP Response Splitting
144142
case "SV.LOG_FORGING":
145143
return 117; // Log Forging
146144
case "SV.DOS.ARRINDEX":
147145
return 129; // Improper Validation of Array Index
148146
case "SV.INT_OVF":
149147
return 190; // Integer Overflow
148+
// case "SV.IL.DEV": // App reveals design info in param back to web interface
149+
// return 209; // Generation of Error Message Containing Sensitive Info
150+
case "SV.STRBUF.CLEAN": // Sensitive buffer not cleaned before garage collection
151+
return 226; // Sensitive Info in Resource Not Removed Before Reuse
150152
case "SV.SOCKETS":
151153
return 246; // J2EE: Direct Use of Sockets
152154
case "JD.UNCAUGHT":
153155
return 248; // Uncaught Exception
154156
case "RR.IGNORED":
155157
return 252; // Unchecked Return Value
158+
case "SV.PASSWD.PLAIN": // Plain-text Password
159+
return 256; // Plaintext Storage of a Password
156160
case "SV.PASSWD.HC":
157161
case "SV.PASSWD.HC.MINLEN": // Minimum 15 char length Hardcoded pwd
158162
case "SV.PASSWD.PLAIN.HC":
159163
return 259; // Hardcoded Password
160-
case "SV.PASSWD.PLAIN": // Plain-text Password
161164
case "SV.SENSITIVE.DATA": // Unencrypted sensitive data is written
162165
return 312; // Cleartext Storage of Sensitive Info
166+
case "SV.UMC.EXIT":
167+
case "UMC.EXIT":
168+
return 382; // J2EE: Use of System.exit()
163169
case "SV.UMC.THREADS":
164170
return 383; // J2EE: Direct Use of Threads
165171
case "ECC.EMPTY": // Empty Exception Block
@@ -170,20 +176,29 @@ static int cweLookup(String checkerKey) {
170176
case "EXC.BROADTHROWS":
171177
return 397; // Decl of Throws for Generic Exception
172178
case "REDUN.DEF": // Assignment of variable to itself
179+
case "REDUN.OP": // Suspicious operation w/ same expression on both sides
173180
return 398; // Code quality
174181
case "SV.DOS.TMPFILEDEL":
175182
case "SV.DOS.TMPFILEEXIT":
176183
return 459; // Incomplete Cleanup
184+
case "SV.TAINT": // Unvalidated user input passed to security sensitive method
185+
return 470; // Unsafe Reflection
186+
case "NPE.COND":
177187
case "NPE.CONST":
188+
case "NPE.RET.UTIL": // Null Pointer Returned from Map or Collection
178189
case "NPE.STAT":
190+
case "REDUN.NULL": // Use of Variable instead of Null Constant
179191
return 476; // Null Pointer Dereference
180192
case "JD.BITR":
181193
return 481; // Assigning Instead of Comparing
182194
case "JD.IFBAD": // Redundant 'if' statement
183195
return 483; // Incorrect Block Delimitation
196+
case "SV.EXPOSE.FIELD": // Non-final public static field could be changed
197+
return 500; // Public Static Field Not Marked Final
184198
case "SV.PASSWD.HC.EMPTY": // Empty Password
185199
return 521; // Weak Password
186200
case "JD.RC.EXPR.DEAD":
201+
case "JD.UN.MET": // Method is never called
187202
case "JD.UN.PMET": // Unused Private Method
188203
return 561; // Dead Code
189204
case "JD.VNU":
@@ -196,9 +211,15 @@ static int cweLookup(String checkerKey) {
196211
return 571; // Expression always true
197212
case "JD.THREAD.RUN":
198213
return 572; // Call to Thread run() instead of start()
214+
case "SV.SERIAL.NOREAD": // Method readObject() should be defined for serializable class
215+
case "SV.SERIAL.NOWRITE": // Method writeObject() should be defined for serializable
216+
// class
217+
return 573; // Improper Following of Spec by Caller
199218
case "EHC.EQ":
200219
case "EHC.HASH":
201220
return 581; // Just One of Equals and Hashcode Defined
221+
case "SV.EXPOSE.MUTABLEFIELD": // Public field references mutable object
222+
return 582; // Array Declared Public, Final, Static
202223
case "JD.FINRET":
203224
return 584; // Return in Finally Block
204225
case "JD.UMC.FINALIZE":
@@ -207,15 +228,32 @@ static int cweLookup(String checkerKey) {
207228
return 597; // Use of Wrong Operator in String Comparison
208229
case "JD.SYNC.DCL":
209230
return 609; // Double-Checked Locking
231+
case "JD.LOCK": // Lock acquired but not released
232+
return 667; // Improper Locking
210233
case "JD.INF.AREC":
211234
return 674; // Uncontrolled Recursion
235+
case "NPE.RET": // Null Pointer Returned from Method
236+
return 690; // Unchecked Return Value to Null Pointer Dereference
212237
case "JD.BITCMP": // Questionable use of Bit compare operation
213238
return 754; // Improper Check for Unusual or Exceptional Conditions
239+
case "SV.HASH.NO_SALT": // Use of a one-way cryptographic hash without a salt
240+
return 759; // CWE-759: Use of a One-Way Hash without a Salt
241+
// Not the same as: CweNumber.WEAK_HASH_ALGO; - CWE: 328 Weak Hashing
242+
case "RLK.SQLCON": // SQL Connection not closed on exit
243+
case "RLK.SQLOBJ": // SQL Object not closed on exit
244+
return 772; // Missing Release of Resource after Effective Lifetime
245+
case "RLK.IN": // Input stream not closed on exit
246+
case "RLK.OUT": // Output stream not closed on exit
247+
case "RLK.ZIP":
248+
return 775; // Missing Release of File Descriptor
249+
case "JD.INF.ALLOC": // Memory alloc in infinite loop can lead to OutOfMemoryError
214250
case "SV.DOS.ARRSIZE": // Unvalidated user input used for array size
215251
return 789; // Memory alloc w/ Excessive Size Value
216252
case "JD.SYNC.IN":
217253
case "JD.LOCK.SLEEP":
218254
return 833; // Deadlock
255+
case "SV.DATA.DB": // Data Injection - Untrusted data inserted into a Database
256+
return 1287; // Improper Validation of Specified Type of Input
219257

220258
default:
221259
System.out.println(

plugin/src/main/java/org/owasp/benchmarkutils/score/parsers/SemgrepReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public static int translate(int cwe) {
129129
case 90: // CweNumber.LDAP_INJECTION;
130130
case 326: // Counts as Weak Crypto due to categories.xml mapping
131131
case 327: // CweNumber.WEAK_CRYPTO_ALGO
132-
case 329: // Generation of Predictable IV with CBC Mode
133132
case 328: // CweNumber.WEAK_HASH_ALGO;
133+
case 329: // Generation of Predictable IV with CBC Mode
134134
case 330: // return CweNumber.WEAK_RANDOM;
135135
case 338: // Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)
136136
// 338 Counts as Weak Random due to categories.xml mapping

0 commit comments

Comments
 (0)