-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathVulnerability.java
More file actions
506 lines (399 loc) · 13.1 KB
/
Vulnerability.java
File metadata and controls
506 lines (399 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
/*
* This file is part of Dependency-Track.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.persistence.model;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import org.dependencytrack.common.cwe.Cwe;
import org.dependencytrack.common.model.Severity;
import org.dependencytrack.commonutil.VulnerabilityUtil;
import org.dependencytrack.persistence.converter.CollectionIntegerConverter;
import org.hibernate.annotations.JdbcType;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* Model for tracking vulnerabilities.
*
* @author Steve Springett
* @since 3.0.0
*/
@Entity
@RegisterForReflection
@Table(name = "VULNERABILITY")
public class Vulnerability extends PanacheEntityBase {
/**
* Defines the sources of vulnerability data supported by Dependency-Track.
*/
public enum Source {
NVD, // National Vulnerability Database
NPM, // NPM Public Advisories - NEED TO KEEP FOR LEGACY PURPOSES
GITHUB, // GitHub Security Advisories
VULNDB, // VulnDB from Risk Based Security
OSSINDEX, // Sonatype OSS Index
RETIREJS, // Retire.js
INTERNAL, // Internally-managed (and manually entered) vulnerability
SNYK, // Snyk Purl Vulnerability
OSV // Google OSV Advisories
}
@Id
@Column(name = "ID")
private long id;
@Column(name = "VULNID", nullable = false)
private String vulnId;
@Column(name = "SOURCE", nullable = false)
private String source;
@Column(name = "FRIENDLYVULNID")
private String friendlyVulnId;
@Column(name = "TITLE")
private String title;
@Column(name = "SUBTITLE")
private String subTitle;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "DETAIL")
private String detail;
@Column(name = "RECOMMENDATION")
private String recommendation;
@Column(name = "\"REFERENCES\"")
private String references;
@Column(name = "CREDITS")
private String credits;
@Column(name = "CREATED")
private Date created;
@Column(name = "PUBLISHED")
private Date published;
@Column(name = "UPDATED")
private Date updated;
@Column(name = "CWES")
@Convert(converter = CollectionIntegerConverter.class)
private List<Integer> cwes;
@Column(name = "CVSSV2BASESCORE", scale = 1)
private BigDecimal cvssV2BaseScore;
@Column(name = "CVSSV2IMPACTSCORE", scale = 1)
private BigDecimal cvssV2ImpactSubScore;
@Column(name = "CVSSV2EXPLOITSCORE", scale = 1)
private BigDecimal cvssV2ExploitabilitySubScore;
@Column(name = "CVSSV2VECTOR")
private String cvssV2Vector;
@Column(name = "CVSSV3BASESCORE", scale = 1)
private BigDecimal cvssV3BaseScore;
@Column(name = "CVSSV3IMPACTSCORE", scale = 1)
private BigDecimal cvssV3ImpactSubScore;
@Column(name = "CVSSV3EXPLOITSCORE", scale = 1)
private BigDecimal cvssV3ExploitabilitySubScore;
@Column(name = "CVSSV3VECTOR")
private String cvssV3Vector;
@Enumerated(EnumType.STRING)
@Column(name = "SEVERITY")
private Severity severity;
@Column(name = "VULNERABLEVERSIONS")
private String vulnerableVersions;
@Column(name = "PATCHEDVERSIONS")
private String patchedVersions;
@ManyToMany(mappedBy = "vulnerabilities")
private List<VulnerableSoftware> vulnerableSoftware;
@OrderBy("name ASC")
@ManyToMany
@JoinTable(
name = "COMPONENTS_VULNERABILITIES",
joinColumns = @JoinColumn(name = "VULNERABILITY_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "COMPONENT_ID", referencedColumnName = "ID")
)
private List<Component> components;
@Column(name = "UUID", nullable = false)
@JdbcType(UUIDJdbcType.class)
private UUID uuid;
@OneToMany
@JoinTable(
name = "VULNERABILITIES_TAGS",
joinColumns = @JoinColumn(name = "VULNERABILITY_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "TAG_ID", referencedColumnName = "ID")
)
@OrderBy("name ASC")
private List<Tag> tags;
private transient int affectedProjectCount;
private transient List<VulnerabilityAlias> aliases;
public long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* Returns the value of the severity field (if specified), otherwise, will
* return the severity based on the numerical CVSS score. CVSSv2 and CVSSv3 have
* slightly different ranges with CVSSv3 introducing critical severity whereas
* CVSSv2 only has high, medium, and low.
* <p>
* This method properly accounts for vulnerabilities that may have only a CVSSv2
* score. If both scores are available, it will return the CVSSv3 severity.
*
* @return the severity of the vulnerability
* @see VulnerabilityUtil#getSeverity(BigDecimal, BigDecimal)
*/
public Severity getSeverity() {
return (this.severity != null) ? severity : VulnerabilityUtil.getSeverity(cvssV2BaseScore, cvssV3BaseScore);
}
/**
* Sets the severity. This should only be set if CVSSv2 or CVSSv3 scores
* are not used.
*
* @param severity the severity of the vulnerability
*/
public void setSeverity(Severity severity) {
cvssV2BaseScore = null;
cvssV2ImpactSubScore = null;
cvssV2ExploitabilitySubScore = null;
cvssV2Vector = null;
cvssV3BaseScore = null;
cvssV3ImpactSubScore = null;
cvssV3ExploitabilitySubScore = null;
cvssV3Vector = null;
this.severity = severity;
}
public String getVulnId() {
return vulnId;
}
public void setVulnId(String vulnId) {
this.vulnId = vulnId;
}
public String getFriendlyVulnId() {
return friendlyVulnId;
}
public void setFriendlyVulnId(String friendlyVulnId) {
this.friendlyVulnId = friendlyVulnId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRecommendation() {
return recommendation;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public void setRecommendation(String recommendation) {
this.recommendation = recommendation;
}
public String getReferences() {
return references;
}
public void setReferences(String references) {
this.references = references;
}
public String getCredits() {
return credits;
}
public void setCredits(String credits) {
this.credits = credits;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getPublished() {
return published;
}
public void setPublished(Date published) {
this.published = published;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
public String getVulnerableVersions() {
return vulnerableVersions;
}
public void setVulnerableVersions(String vulnerableVersions) {
this.vulnerableVersions = vulnerableVersions;
}
public String getPatchedVersions() {
return patchedVersions;
}
public void setPatchedVersions(String patchedVersions) {
this.patchedVersions = patchedVersions;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public void setSource(Source source) {
this.source = source.name();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubTitle() {
return subTitle;
}
public void setSubTitle(String subTitle) {
this.subTitle = subTitle;
}
public List<Integer> getCwes() {
return cwes;
}
public void setCwes(List<Integer> cwes) {
if (cwes == null) {
this.cwes = null;
} else {
this.cwes = new ArrayList<>();
for (final Integer integer : cwes) {
if (integer != null) {
this.cwes.add(integer);
}
}
}
}
public void addCwe(Integer cweId) {
if (cweId == null) {
return;
}
if (this.cwes == null) {
this.cwes = new ArrayList<>();
}
this.cwes.add(cweId);
}
public void addCwe(Cwe cwe) {
if (cwe == null) {
return;
}
if (this.cwes == null) {
this.cwes = new ArrayList<>();
this.cwes.add(cwe.getCweId());
} else {
if (!this.cwes.contains(cwe.getCweId())) {
this.cwes.add(cwe.getCweId());
}
}
}
public BigDecimal getCvssV2BaseScore() {
return cvssV2BaseScore;
}
public void setCvssV2BaseScore(BigDecimal cvssV2BaseScore) {
this.cvssV2BaseScore = cvssV2BaseScore;
}
public BigDecimal getCvssV2ImpactSubScore() {
return cvssV2ImpactSubScore;
}
public void setCvssV2ImpactSubScore(BigDecimal cvssV2ImpactSubScore) {
this.cvssV2ImpactSubScore = cvssV2ImpactSubScore;
}
public BigDecimal getCvssV2ExploitabilitySubScore() {
return cvssV2ExploitabilitySubScore;
}
public void setCvssV2ExploitabilitySubScore(BigDecimal cvssV2ExploitabilitySubScore) {
this.cvssV2ExploitabilitySubScore = cvssV2ExploitabilitySubScore;
}
public String getCvssV2Vector() {
return cvssV2Vector;
}
public void setCvssV2Vector(String cvssV2Vector) {
this.cvssV2Vector = cvssV2Vector;
}
public BigDecimal getCvssV3BaseScore() {
return cvssV3BaseScore;
}
public void setCvssV3BaseScore(BigDecimal cvssV3BaseScore) {
this.cvssV3BaseScore = cvssV3BaseScore;
}
public BigDecimal getCvssV3ImpactSubScore() {
return cvssV3ImpactSubScore;
}
public void setCvssV3ImpactSubScore(BigDecimal cvssV3ImpactSubScore) {
this.cvssV3ImpactSubScore = cvssV3ImpactSubScore;
}
public BigDecimal getCvssV3ExploitabilitySubScore() {
return cvssV3ExploitabilitySubScore;
}
public void setCvssV3ExploitabilitySubScore(BigDecimal cvssV3ExploitabilitySubScore) {
this.cvssV3ExploitabilitySubScore = cvssV3ExploitabilitySubScore;
}
public String getCvssV3Vector() {
return cvssV3Vector;
}
public void setCvssV3Vector(String cvssV3Vector) {
this.cvssV3Vector = cvssV3Vector;
}
public List<VulnerableSoftware> getVulnerableSoftware() {
return vulnerableSoftware;
}
public void setVulnerableSoftware(List<VulnerableSoftware> vulnerableSoftware) {
this.vulnerableSoftware = vulnerableSoftware;
}
public List<Component> getComponents() {
return components;
}
public void setComponents(List<Component> components) {
this.components = components;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public int getAffectedProjectCount() {
return affectedProjectCount;
}
public void setAffectedProjectCount(int affectedProjectCount) {
this.affectedProjectCount = affectedProjectCount;
}
public List<VulnerabilityAlias> getAliases() {
return aliases;
}
public void setAliases(List<VulnerabilityAlias> aliases) {
this.aliases = aliases;
}
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
}