1
- import groovy.xml.MarkupBuilder
2
-
1
+ import groovy.xml.MarkupBuilder ;
2
+ import FsbClassifier ;
3
+ import static FsbClassifier.*;
3
4
@Grapes ([
4
- @Grab (group = ' com.github.spotbugs' , module = ' spotbugs' , version = ' 3.1.0-RC1 ' ),
5
+ @Grab (group = ' com.github.spotbugs' , module = ' spotbugs' , version = ' 3.1.0-RC2 ' ),
5
6
@Grab (group = ' com.mebigfatguy.fb-contrib' , module = ' fb-contrib' , version = ' 7.0.0' ),
6
7
@Grab (group = ' com.h3xstream.findsecbugs' , module = ' findsecbugs-plugin' , version = ' 1.6.0' )]
7
8
)
8
9
9
- // Includes all the bugs that are bundle with FindBugs by default
10
- findBugsPatterns = [" XSS_REQUEST_PARAMETER_TO_SEND_ERROR" ,
11
- " XSS_REQUEST_PARAMETER_TO_SERVLET_WRITER" ,
12
- " HRS_REQUEST_PARAMETER_TO_HTTP_HEADER" ,
13
- " HRS_REQUEST_PARAMETER_TO_COOKIE" ,
14
- " DMI_CONSTANT_DB_PASSWORD" ,
15
- " DMI_EMPTY_DB_PASSWORD" ,
16
- " SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" ,
17
- " SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" ,
18
- ]
19
-
20
- // Informational stuff that will interest Security Reviewer but will annoys the developers.
21
- informationnalPatterns = [" SERVLET_PARAMETER" ,
22
- " SERVLET_CONTENT_TYPE" ,
23
- " SERVLET_SERVER_NAME" ,
24
- " SERVLET_SESSION_ID" ,
25
- " SERVLET_QUERY_STRING" ,
26
- " SERVLET_HEADER" ,
27
- " SERVLET_HEADER_REFERER" ,
28
- " SERVLET_HEADER_USER_AGENT" ,
29
- " COOKIE_USAGE" ,
30
- " WEAK_FILENAMEUTILS" ,
31
- " JAXWS_ENDPOINT" ,
32
- " JAXRS_ENDPOINT" ,
33
- " TAPESTRY_ENDPOINT" ,
34
- " WICKET_ENDPOINT" ,
35
- " FILE_UPLOAD_FILENAME" ,
36
- " STRUTS1_ENDPOINT" ,
37
- " STRUTS2_ENDPOINT" ,
38
- " SPRING_ENDPOINT" ,
39
- " HTTP_RESPONSE_SPLITTING" ,
40
- " CRLF_INJECTION_LOGS" ,
41
- " EXTERNAL_CONFIG_CONTROL" ,
42
- " STRUTS_FORM_VALIDATION" ,
43
- " ESAPI_ENCRYPTOR" ,
44
- " ANDROID_BROADCAST" ,
45
- " ANDROID_GEOLOCATION" ,
46
- " ANDROID_WEB_VIEW_JAVASCRIPT" ,
47
- " ANDROID_WEB_VIEW_JAVASCRIPT_INTERFACE" ]
48
-
49
- // All the cryptography related bugs. Usually with issues related to confidentiality or integrity of data in transit.
50
- cryptoBugs = [
51
- " WEAK_TRUST_MANAGER" ,
52
- " WEAK_HOSTNAME_VERIFIER" ,
53
- // "WEAK_MESSAGE_DIGEST", //Deprecated
54
- " WEAK_MESSAGE_DIGEST_MD5" ,
55
- " WEAK_MESSAGE_DIGEST_SHA1" ,
56
- " CUSTOM_MESSAGE_DIGEST" ,
57
- " HAZELCAST_SYMMETRIC_ENCRYPTION" ,
58
- " NULL_CIPHER" ,
59
- " UNENCRYPTED_SOCKET" ,
60
- " DES_USAGE" ,
61
- " RSA_NO_PADDING" ,
62
- " RSA_KEY_SIZE" ,
63
- " BLOWFISH_KEY_SIZE" ,
64
- " STATIC_IV" ,
65
- " ECB_MODE" ,
66
- " PADDING_ORACLE" ,
67
- " CIPHER_INTEGRITY"
68
- ]
69
-
70
- majorBugsAuditOnly = [ // Mostly due to their high false-positive rate
71
- " TRUST_BOUNDARY_VIOLATION"
72
- ]
73
-
74
- // Important bugs but that have lower chance to get full compromise of system (see critical).
75
- majorBugs = [
76
- " PREDICTABLE_RANDOM" ,
77
- " PATH_TRAVERSAL_IN" ,
78
- " PATH_TRAVERSAL_OUT" ,
79
- " REDOS" ,
80
- " BAD_HEXA_CONVERSION" ,
81
- " HARD_CODE_PASSWORD" ,
82
- " HARD_CODE_KEY" ,
83
- " XSS_REQUEST_WRAPPER" ,
84
- " UNVALIDATED_REDIRECT" ,
85
- " ANDROID_EXTERNAL_FILE_ACCESS" ,
86
- " ANDROID_WORLD_WRITABLE" ,
87
- " INSECURE_COOKIE" ,
88
- " HTTPONLY_COOKIE" ,
89
- " TRUST_BOUNDARY_VIOLATION" ,
90
- " XSS_SERVLET" ,
91
- ]
92
-
93
- criticalBugs = [ // RCE or powerful function
94
- " COMMAND_INJECTION" ,
95
- " XXE_SAXPARSER" ,
96
- " XXE_XMLREADER" ,
97
- " XXE_DOCUMENT" ,
98
- " SQL_INJECTION_HIBERNATE" ,
99
- " SQL_INJECTION_JDO" ,
100
- " SQL_INJECTION_JPA" ,
101
- " LDAP_INJECTION" ,
102
- " XPATH_INJECTION" ,
103
- " XML_DECODER" ,
104
- " SCRIPT_ENGINE_INJECTION" ,
105
- " SPEL_INJECTION" ,
106
- " SQL_INJECTION_SPRING_JDBC" ,
107
- " SQL_INJECTION_JDBC" ,
108
- " EL_INJECTION" ,
109
- " SEAM_LOG_INJECTION" ,
110
- " OBJECT_DESERIALIZATION" ,
111
- " MALICIOUS_XSLT" ,
112
- " SPRING_CSRF_PROTECTION_DISABLED" ,
113
- " SPRING_CSRF_UNRESTRICTED_REQUEST_MAPPING"
114
- ]
115
-
116
- majorJspBugs = [" XSS_REQUEST_PARAMETER_TO_JSP_WRITER" ,
117
- " XSS_JSP_PRINT" , " JSP_JSTL_OUT" ]
118
-
119
- // RCE from JSP specific functions (taglibs)
120
- criticalJspBugs = [" JSP_INCLUDE" ," JSP_SPRING_EVAL" ," JSP_XSLT" ]
121
-
122
- exclusions = [' CUSTOM_INJECTION' ]
123
-
124
- deprecatedRules = [" XSS_REQUEST_PARAMETER_TO_JSP_WRITER" ]
125
10
126
11
// //////////// Generate rules files
127
12
128
13
def getSonarPriority (String type ,String category , String description ) {
129
- // FSB Specific
130
- if (type in criticalBugs || type in criticalJspBugs) return " CRITICAL" ;
131
- if (type in majorBugs || type in cryptoBugs || type in majorJspBugs) return " MAJOR" ;
132
- if (type in informationnalPatterns) return " INFO"
14
+ String priority = FsbClassifier . getPriorityFromType(type);
15
+ if (priority != null ) return priority
133
16
134
17
// Findbugs critical base on the type or message
135
18
if (type. contains(" IMPOSSIBLE" )) {
@@ -141,13 +24,17 @@ def getSonarPriority(String type,String category, String description) {
141
24
142
25
// Findbugs general
143
26
if (category in [" CORRECTNESS" , " PERFORMANCE" , " SECURITY" ," MULTI-THREADING" ," BAD_PRACTICE" ]) return " MAJOR" ;
144
- if (category in [" STYLE" , " MALICIOUS_CODE" , " I18N" ]) return " INFO"
27
+ if (category in [" STYLE" , " MALICIOUS_CODE" , " I18N" , " EXPERIMENTAL " ]) return " INFO"
145
28
146
29
println (" Unknown priority for " + type+ " (" + category+ " )" )
147
30
return " INFO" ;
148
31
}
149
32
150
- // Plugin definition
33
+ /**
34
+ * Plugin definition.
35
+ * Utility that read the messages and metadata from the plugin.
36
+ * It expecting that the jars are already present on disk (See Grape annotation that fetch each dependency)
37
+ */
151
38
class Plugin {
152
39
String groupId = " "
153
40
String artifactId = " "
@@ -191,7 +78,7 @@ String getFindBugsCategory(List<Plugin> plugins, String bugType) {
191
78
return " EXPERIMENTAL"
192
79
}
193
80
194
- FB = new Plugin (groupId : ' com.github.spotbugs' , artifactId : ' spotbugs' , version : ' 3.1.0-RC1 ' )
81
+ FB = new Plugin (groupId : ' com.github.spotbugs' , artifactId : ' spotbugs' , version : ' 3.1.0-RC2 ' )
195
82
CONTRIB = new Plugin (groupId : ' com.mebigfatguy.fb-contrib' , artifactId : ' fb-contrib' , version : ' 7.0.0' )
196
83
FSB = new Plugin (groupId : ' com.h3xstream.findsecbugs' , artifactId : ' findsecbugs-plugin' , version : ' 1.6.0' )
197
84
@@ -221,10 +108,8 @@ def writeRules(String rulesSetName,List<Plugin> plugins,List<String> includedBug
221
108
if (category == " NOISE" || pattern. attribute(" type" ) in [" TESTING" , " TESTING1" , " TESTING2" , " TESTING3" , " UNKNOWN" ]) return ;
222
109
if (category == " MT_CORRECTNESS" ) category = " MULTI-THREADING"
223
110
224
- // if(rulesSetName == 'jsp') println pattern.attribute("type")
225
111
226
112
if ((includedBugs. isEmpty() || includedBugs. contains(pattern. attribute(" type" ))) && ! excludedBugs. contains(pattern. attribute(" type" ))) {
227
- // if(rulesSetName == 'jsp') println "-INCLUDED"
228
113
229
114
rule(key : pattern. attribute(" type" ),
230
115
priority : getSonarPriority(pattern. attribute(" type" ),category,pattern.Details . text())) {
@@ -287,14 +172,10 @@ def writeRules(String rulesSetName,List<Plugin> plugins,List<String> includedBug
287
172
// Category related
288
173
tag(category. toLowerCase(). replace(" _" ," -" ))
289
174
290
-
291
175
if (category in [' PERFORMANCE' ,' CORRECTNESS' ,' MULTI-THREADING' ]) {
292
176
tag(" bug" )
293
177
}
294
178
295
- if (deprecatedRules. contains(pattern. attribute(" type" ))) {
296
- status(" DEPRECATED" )
297
- }
298
179
}
299
180
// name: pattern.ShortDescription.text(),
300
181
// 'description': pattern.Details.text(),
@@ -326,7 +207,7 @@ def writeProfile(String profileName,List<String> includedBugs,List<String> exclu
326
207
File f = new File (" out_sonar" ," profile-" + profileName+ " .xml" )
327
208
printf (" Building profile %s (%s)%n" ,profileName,f. getCanonicalPath())
328
209
329
-
210
+ def countBugs = 0 ;
330
211
331
212
def xml = new MarkupBuilder (new PrintWriter (f))
332
213
xml.FindBugsFilter {
@@ -338,11 +219,15 @@ def writeProfile(String profileName,List<String> includedBugs,List<String> exclu
338
219
if (! excludedBugs. contains(patternName)) {
339
220
Match {
340
221
Bug (pattern : patternName)
222
+
223
+ countBugs++
341
224
}
342
225
}
343
226
}
344
227
345
228
}
229
+
230
+ return countBugs
346
231
}
347
232
348
233
@@ -363,9 +248,11 @@ def getAllPatternsFromPlugin(Plugin plugin) {
363
248
return patterns;
364
249
}
365
250
366
-
251
+ totalCount = 0
367
252
writeProfile(" findbugs-only" , getAllPatternsFromPlugin(FB ), excludedJspRules);
368
- writeProfile(" findbugs-and-fb-contrib" , getAllPatternsFromPlugin(FB ) + getAllPatternsFromPlugin(CONTRIB ), excludedJspRules);
369
- writeProfile(" findbugs-security-audit" , informationnalPatterns + cryptoBugs + majorBugs + majorBugsAuditOnly + criticalBugs + findBugsPatterns)
253
+ totalCount + = writeProfile(" findbugs-and-fb-contrib" , getAllPatternsFromPlugin(FB ) + getAllPatternsFromPlugin(CONTRIB ), excludedJspRules);
254
+ totalCount + = writeProfile(" findbugs-security-audit" , informationnalPatterns + cryptoBugs + majorBugs + majorBugsAuditOnly + criticalBugs + findBugsPatterns)
370
255
writeProfile(" findbugs-security-minimal" , cryptoBugs + majorBugs + criticalBugs + findBugsPatterns)
371
- writeProfile(" findbugs-security-jsp" , majorJspBugs + criticalJspBugs)
256
+ totalCount + = writeProfile(" findbugs-security-jsp" , majorJspBugs + criticalJspBugs)
257
+
258
+ println " Total bugs patterns " + totalCount
0 commit comments