15
15
import static datadog .trace .api .iast .VulnerabilityMarks .XPATH_INJECTION_MARK ;
16
16
import static datadog .trace .api .iast .VulnerabilityMarks .XSS_MARK ;
17
17
18
+ import datadog .trace .api .iast .SourceTypes ;
18
19
import datadog .trace .api .iast .VulnerabilityTypes ;
19
20
import java .io .File ;
21
+ import java .util .BitSet ;
20
22
import java .util .function .BiFunction ;
21
23
import java .util .zip .CRC32 ;
22
24
import javax .annotation .Nonnull ;
23
25
24
26
public interface VulnerabilityType {
25
27
26
- VulnerabilityType WEAK_CIPHER = type (VulnerabilityTypes .WEAK_CIPHER ).build ();
27
- VulnerabilityType WEAK_HASH = type (VulnerabilityTypes .WEAK_HASH ).build ();
28
+ BitSet DB_EXCLUDED = new BitSet (SourceTypes .SQL_TABLE );
29
+
30
+ VulnerabilityType WEAK_CIPHER =
31
+ type (VulnerabilityTypes .WEAK_CIPHER ).excludedSources (DB_EXCLUDED ).build ();
32
+ VulnerabilityType WEAK_HASH =
33
+ type (VulnerabilityTypes .WEAK_HASH ).excludedSources (DB_EXCLUDED ).build ();
28
34
VulnerabilityType INSECURE_COOKIE =
29
- type (VulnerabilityTypes .INSECURE_COOKIE ).hash (VulnerabilityType ::evidenceHash ).build ();
35
+ type (VulnerabilityTypes .INSECURE_COOKIE )
36
+ .hash (VulnerabilityType ::evidenceHash )
37
+ .excludedSources (DB_EXCLUDED )
38
+ .build ();
30
39
VulnerabilityType NO_HTTPONLY_COOKIE =
31
- type (VulnerabilityTypes .NO_HTTPONLY_COOKIE ).hash (VulnerabilityType ::evidenceHash ).build ();
40
+ type (VulnerabilityTypes .NO_HTTPONLY_COOKIE )
41
+ .hash (VulnerabilityType ::evidenceHash )
42
+ .excludedSources (DB_EXCLUDED )
43
+ .build ();
32
44
VulnerabilityType HSTS_HEADER_MISSING =
33
- type (VulnerabilityTypes .HSTS_HEADER_MISSING ).hash (VulnerabilityType ::serviceHash ).build ();
45
+ type (VulnerabilityTypes .HSTS_HEADER_MISSING )
46
+ .hash (VulnerabilityType ::serviceHash )
47
+ .excludedSources (DB_EXCLUDED )
48
+ .build ();
34
49
VulnerabilityType XCONTENTTYPE_HEADER_MISSING =
35
50
type (VulnerabilityTypes .XCONTENTTYPE_HEADER_MISSING )
36
51
.hash (VulnerabilityType ::serviceHash )
52
+ .excludedSources (DB_EXCLUDED )
37
53
.build ();
38
54
VulnerabilityType NO_SAMESITE_COOKIE =
39
- type (VulnerabilityTypes .NO_SAMESITE_COOKIE ).hash (VulnerabilityType ::evidenceHash ).build ();
55
+ type (VulnerabilityTypes .NO_SAMESITE_COOKIE )
56
+ .hash (VulnerabilityType ::evidenceHash )
57
+ .excludedSources (DB_EXCLUDED )
58
+ .build ();
40
59
41
60
VulnerabilityType SQL_INJECTION =
42
61
type (VulnerabilityTypes .SQL_INJECTION ).mark (SQL_INJECTION_MARK ).build ();
43
62
VulnerabilityType COMMAND_INJECTION =
44
- type (VulnerabilityTypes .COMMAND_INJECTION ).mark (COMMAND_INJECTION_MARK ).build ();
63
+ type (VulnerabilityTypes .COMMAND_INJECTION )
64
+ .mark (COMMAND_INJECTION_MARK )
65
+ .excludedSources (DB_EXCLUDED )
66
+ .build ();
45
67
VulnerabilityType PATH_TRAVERSAL =
46
68
type (VulnerabilityTypes .PATH_TRAVERSAL )
47
69
.separator (File .separatorChar )
48
70
.mark (PATH_TRAVERSAL_MARK )
71
+ .excludedSources (DB_EXCLUDED )
49
72
.build ();
50
73
VulnerabilityType LDAP_INJECTION =
51
- type (VulnerabilityTypes .LDAP_INJECTION ).mark (LDAP_INJECTION_MARK ).build ();
52
- VulnerabilityType SSRF = type (VulnerabilityTypes .SSRF ).mark (SSRF_MARK ).build ();
74
+ type (VulnerabilityTypes .LDAP_INJECTION )
75
+ .mark (LDAP_INJECTION_MARK )
76
+ .excludedSources (DB_EXCLUDED )
77
+ .build ();
78
+ VulnerabilityType SSRF =
79
+ type (VulnerabilityTypes .SSRF ).mark (SSRF_MARK ).excludedSources (DB_EXCLUDED ).build ();
53
80
VulnerabilityType UNVALIDATED_REDIRECT =
54
- type (VulnerabilityTypes .UNVALIDATED_REDIRECT ).mark (UNVALIDATED_REDIRECT_MARK ).build ();
55
- VulnerabilityType WEAK_RANDOMNESS = type (VulnerabilityTypes .WEAK_RANDOMNESS ).build ();
81
+ type (VulnerabilityTypes .UNVALIDATED_REDIRECT )
82
+ .mark (UNVALIDATED_REDIRECT_MARK )
83
+ .excludedSources (DB_EXCLUDED )
84
+ .build ();
85
+ VulnerabilityType WEAK_RANDOMNESS =
86
+ type (VulnerabilityTypes .WEAK_RANDOMNESS ).excludedSources (DB_EXCLUDED ).build ();
56
87
57
88
VulnerabilityType XPATH_INJECTION =
58
- type (VulnerabilityTypes .XPATH_INJECTION ).mark (XPATH_INJECTION_MARK ).build ();
89
+ type (VulnerabilityTypes .XPATH_INJECTION )
90
+ .mark (XPATH_INJECTION_MARK )
91
+ .excludedSources (DB_EXCLUDED )
92
+ .build ();
59
93
60
94
VulnerabilityType TRUST_BOUNDARY_VIOLATION =
61
- type (VulnerabilityTypes .TRUST_BOUNDARY_VIOLATION ).mark (TRUST_BOUNDARY_VIOLATION_MARK ).build ();
95
+ type (VulnerabilityTypes .TRUST_BOUNDARY_VIOLATION )
96
+ .mark (TRUST_BOUNDARY_VIOLATION_MARK )
97
+ .excludedSources (DB_EXCLUDED )
98
+ .build ();
62
99
63
100
VulnerabilityType XSS = type (VulnerabilityTypes .XSS ).mark (XSS_MARK ).build ();
64
101
65
102
VulnerabilityType HEADER_INJECTION =
66
- type (VulnerabilityTypes .HEADER_INJECTION ).mark (HEADER_INJECTION_MARK ).build ();
103
+ type (VulnerabilityTypes .HEADER_INJECTION )
104
+ .mark (HEADER_INJECTION_MARK )
105
+ .excludedSources (DB_EXCLUDED )
106
+ .build ();
67
107
68
- VulnerabilityType STACKTRACE_LEAK = type (VulnerabilityTypes .STACKTRACE_LEAK ).build ();
108
+ VulnerabilityType STACKTRACE_LEAK =
109
+ type (VulnerabilityTypes .STACKTRACE_LEAK ).excludedSources (DB_EXCLUDED ).build ();
69
110
70
- VulnerabilityType VERB_TAMPERING = type (VulnerabilityTypes .VERB_TAMPERING ).build ();
111
+ VulnerabilityType VERB_TAMPERING =
112
+ type (VulnerabilityTypes .VERB_TAMPERING ).excludedSources (DB_EXCLUDED ).build ();
71
113
72
114
VulnerabilityType ADMIN_CONSOLE_ACTIVE =
73
115
type (VulnerabilityTypes .ADMIN_CONSOLE_ACTIVE )
74
116
.deduplicable (false )
75
117
.hash (VulnerabilityType ::serviceHash )
118
+ .excludedSources (DB_EXCLUDED )
76
119
.build ();
77
120
78
121
VulnerabilityType DEFAULT_HTML_ESCAPE_INVALID =
79
- type (VulnerabilityTypes .DEFAULT_HTML_ESCAPE_INVALID ).build ();
122
+ type (VulnerabilityTypes .DEFAULT_HTML_ESCAPE_INVALID ).excludedSources ( DB_EXCLUDED ). build ();
80
123
81
- VulnerabilityType SESSION_TIMEOUT = type (VulnerabilityTypes .SESSION_TIMEOUT ).build ();
124
+ VulnerabilityType SESSION_TIMEOUT =
125
+ type (VulnerabilityTypes .SESSION_TIMEOUT ).excludedSources (DB_EXCLUDED ).build ();
82
126
83
127
VulnerabilityType DIRECTORY_LISTING_LEAK =
84
- type (VulnerabilityTypes .DIRECTORY_LISTING_LEAK ).build ();
85
- VulnerabilityType INSECURE_JSP_LAYOUT = type (VulnerabilityTypes .INSECURE_JSP_LAYOUT ).build ();
128
+ type (VulnerabilityTypes .DIRECTORY_LISTING_LEAK ).excludedSources (DB_EXCLUDED ).build ();
129
+ VulnerabilityType INSECURE_JSP_LAYOUT =
130
+ type (VulnerabilityTypes .INSECURE_JSP_LAYOUT ).excludedSources (DB_EXCLUDED ).build ();
86
131
87
- VulnerabilityType HARDCODED_SECRET = type (VulnerabilityTypes .HARDCODED_SECRET ).build ();
132
+ VulnerabilityType HARDCODED_SECRET =
133
+ type (VulnerabilityTypes .HARDCODED_SECRET ).excludedSources (DB_EXCLUDED ).build ();
88
134
89
135
VulnerabilityType INSECURE_AUTH_PROTOCOL =
90
- type (VulnerabilityTypes .INSECURE_AUTH_PROTOCOL ).hash (VulnerabilityType ::evidenceHash ).build ();
136
+ type (VulnerabilityTypes .INSECURE_AUTH_PROTOCOL )
137
+ .hash (VulnerabilityType ::evidenceHash )
138
+ .excludedSources (DB_EXCLUDED )
139
+ .build ();
91
140
92
141
VulnerabilityType REFLECTION_INJECTION =
93
- type (VulnerabilityTypes .REFLECTION_INJECTION ).mark (REFLECTION_INJECTION_MARK ).build ();
142
+ type (VulnerabilityTypes .REFLECTION_INJECTION )
143
+ .mark (REFLECTION_INJECTION_MARK )
144
+ .excludedSources (DB_EXCLUDED )
145
+ .build ();
94
146
95
147
VulnerabilityType SESSION_REWRITING =
96
148
type (VulnerabilityTypes .SESSION_REWRITING )
97
149
.deduplicable (false )
98
150
.hash (VulnerabilityType ::serviceHash )
151
+ .excludedSources (DB_EXCLUDED )
99
152
.build ();
100
153
101
154
VulnerabilityType DEFAULT_APP_DEPLOYED =
102
155
type (VulnerabilityTypes .DEFAULT_APP_DEPLOYED )
103
156
.deduplicable (false )
104
157
.hash (VulnerabilityType ::serviceHash )
158
+ .excludedSources (DB_EXCLUDED )
105
159
.build ();
106
160
107
161
VulnerabilityType UNTRUSTED_DESERIALIZATION =
108
162
type (VulnerabilityTypes .UNTRUSTED_DESERIALIZATION )
109
163
.mark (UNTRUSTED_DESERIALIZATION_MARK )
164
+ .excludedSources (DB_EXCLUDED )
110
165
.build ();
111
166
112
167
/* All vulnerability types that have a mark. Should be updated if new vulnerabilityType with mark is added */
@@ -139,6 +194,8 @@ public interface VulnerabilityType {
139
194
140
195
byte type ();
141
196
197
+ BitSet excludedSources ();
198
+
142
199
static Builder type (final byte type ) {
143
200
return new Builder (type );
144
201
}
@@ -153,18 +210,22 @@ class VulnerabilityTypeImpl implements VulnerabilityType {
153
210
154
211
private final boolean deduplicable ;
155
212
213
+ private final BitSet excludedSources ;
214
+
156
215
private final BiFunction <VulnerabilityType , Vulnerability , Long > hash ;
157
216
158
217
public VulnerabilityTypeImpl (
159
218
final byte type ,
160
219
final char separator ,
161
220
final int mark ,
162
221
final boolean deduplicable ,
222
+ final BitSet excludedSources ,
163
223
final BiFunction <VulnerabilityType , Vulnerability , Long > hash ) {
164
224
this .type = type ;
165
225
this .separator = separator ;
166
226
this .mark = mark ;
167
227
this .deduplicable = deduplicable ;
228
+ this .excludedSources = excludedSources ;
168
229
this .hash = hash ;
169
230
}
170
231
@@ -198,6 +259,11 @@ public byte type() {
198
259
return type ;
199
260
}
200
261
262
+ @ Override
263
+ public BitSet excludedSources () {
264
+ return excludedSources ;
265
+ }
266
+
201
267
/** Useful for troubleshooting issues when vulns are serialized without moshi */
202
268
public String getName () {
203
269
return name ();
@@ -209,6 +275,7 @@ class Builder {
209
275
private char separator = ' ' ;
210
276
private int mark = NOT_MARKED ;
211
277
private boolean deduplicable = true ;
278
+ private BitSet excludedSources = new BitSet ();
212
279
private BiFunction <VulnerabilityType , Vulnerability , Long > hash =
213
280
VulnerabilityType ::fileAndLineHash ;
214
281
@@ -231,13 +298,18 @@ public Builder deduplicable(final boolean deduplicable) {
231
298
return this ;
232
299
}
233
300
301
+ public Builder excludedSources (final BitSet excludedSources ) {
302
+ this .excludedSources = excludedSources ;
303
+ return this ;
304
+ }
305
+
234
306
public Builder hash (final BiFunction <VulnerabilityType , Vulnerability , Long > hash ) {
235
307
this .hash = hash ;
236
308
return this ;
237
309
}
238
310
239
311
public VulnerabilityType build () {
240
- return new VulnerabilityTypeImpl (type , separator , mark , deduplicable , hash );
312
+ return new VulnerabilityTypeImpl (type , separator , mark , deduplicable , excludedSources , hash );
241
313
}
242
314
}
243
315
0 commit comments