Skip to content

Commit 0b40032

Browse files
committed
Add "Status" field to Vulnerability in the scan report
This commit is part of fix of the issue in Harbor: goharbor/harbor#21445 It addes the "Status" field into vulnerabilities of a scan report, so that this information can be passed to "harbor-core" Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com>
1 parent d02c7d8 commit 0b40032

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

pkg/harbor/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type VulnerabilityItem struct {
154154
ID string `json:"id"`
155155
Pkg string `json:"package"`
156156
Version string `json:"version"`
157+
Status string `json:"status,omitempty"`
157158
FixVersion string `json:"fix_version,omitempty"`
158159
Severity Severity `json:"severity"`
159160
Description string `json:"description"`

pkg/scan/transformer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (t *transformer) transformVulnerabilities(source []trivy.Vulnerability) []h
7070
ID: v.VulnerabilityID,
7171
Pkg: v.PkgName,
7272
Version: v.InstalledVersion,
73+
Status: v.Status,
7374
FixVersion: v.FixedVersion,
7475
Severity: t.toHarborSeverity(v.Severity),
7576
Description: v.Description,

pkg/scan/transformer_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestTransformer_Transform(t *testing.T) {
4545
PkgName: "PKG-01",
4646
InstalledVersion: "PKG-01-VER",
4747
FixedVersion: "PKG-01-FIX-VER",
48+
Status: "fixed",
4849
Severity: "CRITICAL",
4950
Description: "CVE-0000-0001.DESC",
5051
References: []string{
@@ -72,6 +73,7 @@ func TestTransformer_Transform(t *testing.T) {
7273
PkgName: "PKG-02",
7374
InstalledVersion: "PKG-02-VER",
7475
FixedVersion: "",
76+
Status: "won't fix",
7577
Severity: "HIGH",
7678
Description: "CVE-0000-0002.DESC",
7779
References: []string{
@@ -85,6 +87,7 @@ func TestTransformer_Transform(t *testing.T) {
8587
VulnerabilityID: "CVE-0000-0003",
8688
PkgName: "PKG-03",
8789
InstalledVersion: "PKG-03-VER",
90+
Status: "fixed",
8891
FixedVersion: "PKG-03-FIX-VER",
8992
Severity: "MEDIUM",
9093
Description: "CVE-0000-0003.DESC",
@@ -101,6 +104,7 @@ func TestTransformer_Transform(t *testing.T) {
101104
PkgName: "PKG-04",
102105
InstalledVersion: "PKG-04-VER",
103106
FixedVersion: "PKG-04-FIX-VER",
107+
Status: "fixed",
104108
Severity: "LOW",
105109
Description: "CVE-0000-0004.DESC",
106110
References: []string{
@@ -144,6 +148,7 @@ func TestTransformer_Transform(t *testing.T) {
144148
ID: "CVE-0000-0001",
145149
Pkg: "PKG-01",
146150
Version: "PKG-01-VER",
151+
Status: "fixed",
147152
FixVersion: "PKG-01-FIX-VER",
148153
Severity: harbor.SevCritical,
149154
Description: "CVE-0000-0001.DESC",
@@ -173,6 +178,7 @@ func TestTransformer_Transform(t *testing.T) {
173178
ID: "CVE-0000-0002",
174179
Pkg: "PKG-02",
175180
Version: "PKG-02-VER",
181+
Status: "won't fix",
176182
FixVersion: "",
177183
Severity: harbor.SevHigh,
178184
Description: "CVE-0000-0002.DESC",
@@ -188,6 +194,7 @@ func TestTransformer_Transform(t *testing.T) {
188194
ID: "CVE-0000-0003",
189195
Pkg: "PKG-03",
190196
Version: "PKG-03-VER",
197+
Status: "fixed",
191198
FixVersion: "PKG-03-FIX-VER",
192199
Severity: harbor.SevMedium,
193200
Description: "CVE-0000-0003.DESC",
@@ -203,6 +210,7 @@ func TestTransformer_Transform(t *testing.T) {
203210
ID: "CVE-0000-0004",
204211
Pkg: "PKG-04",
205212
Version: "PKG-04-VER",
213+
Status: "fixed",
206214
FixVersion: "PKG-04-FIX-VER",
207215
Severity: harbor.SevLow,
208216
Description: "CVE-0000-0004.DESC",

pkg/trivy/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Vulnerability struct {
4848
VulnerabilityID string `json:"VulnerabilityID"`
4949
PkgName string `json:"PkgName"`
5050
InstalledVersion string `json:"InstalledVersion"`
51+
Status string `json:"Status"`
5152
FixedVersion string `json:"FixedVersion"`
5253
Title string `json:"Title"`
5354
Description string `json:"Description"`

test/integration/api/rest_api_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func TestRestAPI(t *testing.T) {
146146
Pkg: "musl",
147147
Version: "1.1.22-r4",
148148
FixVersion: "1.1.22-r5",
149+
Status: "fixed",
149150
Severity: harbor.SevMedium,
150151
Description: "In musl libc through 1.2.1, wcsnrtombs mishandles particular combinations of destination buffer size and source character limit, as demonstrated by an invalid write access (buffer overflow).",
151152
Links: []string{
@@ -161,6 +162,7 @@ func TestRestAPI(t *testing.T) {
161162
Pkg: "musl-utils",
162163
Version: "1.1.22-r4",
163164
FixVersion: "1.1.22-r5",
165+
Status: "fixed",
164166
Severity: harbor.SevMedium,
165167
Description: "In musl libc through 1.2.1, wcsnrtombs mishandles particular combinations of destination buffer size and source character limit, as demonstrated by an invalid write access (buffer overflow).",
166168
Links: []string{
@@ -335,6 +337,7 @@ func TestRestAPI(t *testing.T) {
335337
Pkg: "libssl1.1",
336338
Version: "1.1.1c-r0",
337339
FixVersion: "1.1.1d-r0",
340+
Status: "fixed",
338341
Severity: harbor.SevMedium,
339342
Description: "OpenSSL 1.1.1 introduced a rewritten random number generator (RNG). This was intended to include protection in the event of a fork() system call in order to ensure that the parent and child processes did not share the same RNG state. However this protection was not being used in the default case. A partial mitigation for this issue is that the output from a high precision timer is mixed into the RNG state so the likelihood of a parent and child process sharing state is significantly reduced. If an application already calls OPENSSL_init_crypto() explicitly using OPENSSL_INIT_ATFORK then this problem does not occur at all. Fixed in OpenSSL 1.1.1d (Affected 1.1.1-1.1.1c).",
340343
Links: []string{

0 commit comments

Comments
 (0)