Skip to content

Commit cbad9ca

Browse files
authored
feat(report): add fingerprint generation for vulnerabilities (#9794)
Signed-off-by: knqyf263 <[email protected]>
1 parent 612ee98 commit cbad9ca

File tree

74 files changed

+510
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+510
-12
lines changed

integration/client_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func TestClientServer(t *testing.T) {
333333
}
334334

335335
runTest(t, osArgs, tt.golden, types.FormatJSON, runOptions{
336-
override: overrideFuncs(overrideUID, tt.override),
336+
override: overrideFuncs(overrideUID, overrideFingerprint, tt.override),
337337
fakeUUID: "3ff14136-e09f-4df9-80ea-%012d",
338338
})
339339
})

integration/docker_engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func TestDockerEngine(t *testing.T) {
283283
wantErr: tt.wantErr,
284284
fakeUUID: "3ff14136-e09f-4df9-80ea-%012d",
285285
// Image config fields were removed
286-
override: overrideFuncs(overrideUID, overrideDockerRemovedFields, func(t *testing.T, want, got *types.Report) {
286+
override: overrideFuncs(overrideUID, overrideFingerprint, overrideDockerRemovedFields, func(t *testing.T, want, got *types.Report) {
287287
// Override ArtifactName to match the archive file path
288288
got.ArtifactName = tt.input
289289

integration/integration_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,25 @@ func overrideUID(t *testing.T, want, got *types.Report) {
498498
}
499499
}
500500

501+
// overrideFingerprint only checks for the presence of the fingerprint and clears it;
502+
// the fingerprint is calculated from artifactID, target, pkgID, and vulnerabilityID,
503+
// but may not match as the artifactID can vary depending on the scanning context.
504+
func overrideFingerprint(t *testing.T, want, got *types.Report) {
505+
for i, result := range got.Results {
506+
for j, vuln := range result.Vulnerabilities {
507+
assert.NotEmptyf(t, vuln.Fingerprint, "Fingerprint is empty: %s", vuln.VulnerabilityID)
508+
assert.Lenf(t, vuln.Fingerprint, 71, "Fingerprint should be 71 characters (sha256: + 64 hex chars): %s", vuln.VulnerabilityID)
509+
// Do not compare Fingerprint as the artifactID varies between tests
510+
got.Results[i].Vulnerabilities[j].Fingerprint = ""
511+
}
512+
}
513+
for i, result := range want.Results {
514+
for j := range result.Vulnerabilities {
515+
want.Results[i].Vulnerabilities[j].Fingerprint = ""
516+
}
517+
}
518+
}
519+
501520
// overrideDockerRemovedFields clears image config fields that were removed from Docker API
502521
// cf. https://github.com/moby/moby/blob/d0ad1357a141c795e1e0490e3fed00ddabcb91b9/docs/api/version-history.md
503522
func overrideDockerRemovedFields(_ *testing.T, want, got *types.Report) {

integration/registry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func TestRegistry(t *testing.T) {
250250
runTest(t, osArgs, tt.golden, types.FormatJSON, runOptions{
251251
wantErr: tt.wantErr,
252252
fakeUUID: "3ff14136-e09f-4df9-80ea-%012d",
253-
override: overrideFuncs(overrideUID, func(t *testing.T, want, got *types.Report) {
253+
override: overrideFuncs(overrideUID, overrideFingerprint, func(t *testing.T, want, got *types.Report) {
254254
// Exclude ArtifactID from comparison because registry tests use random ports
255255
// (e.g., localhost:54321/alpine:3.10), which causes RepoTags and the calculated
256256
// Artifact ID to vary on each test run.

integration/sbom_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func TestSBOMEquivalence(t *testing.T) {
243243

244244
// Run "trivy sbom"
245245
runTest(t, osArgs, tt.golden, types.Format(tt.args.format), runOptions{
246-
override: overrideFuncs(overrideSBOMReport, overrideUID, tt.override),
246+
override: overrideFuncs(overrideSBOMReport, overrideUID, overrideFingerprint, tt.override),
247247
fakeUUID: "3ff14136-e09f-4df9-80ea-%012d",
248248
})
249249
})

integration/standalone_tar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ func TestTarWithOverride(t *testing.T) {
506506
// Run Trivy
507507
runTest(t, osArgs, tt.golden, types.FormatJSON, runOptions{
508508
fakeUUID: "3ff14136-e09f-4df9-80ea-%012d",
509-
override: overrideFuncs(overrideUID, tt.override),
509+
override: overrideFuncs(overrideUID, overrideFingerprint, tt.override),
510510
})
511511
})
512512
}

integration/testdata/almalinux-8.json.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"Name": "AlmaLinux Product Errata",
8989
"URL": "https://errata.almalinux.org/"
9090
},
91+
"Fingerprint": "sha256:423564f47df066642faca6be8d949f2e201e2578173845e6ee2673ecf9229861",
9192
"Title": "openssl: Read buffer overruns processing ASN.1 strings",
9293
"Description": "ASN.1 strings are represented internally within OpenSSL as an ASN1_STRING structure which contains a buffer holding the string data and a field holding the buffer length. This contrasts with normal C strings which are represented as a buffer for the string data which is terminated with a NUL (0) byte. Although not a strict requirement, ASN.1 strings that are parsed using OpenSSL's own \"d2i\" functions (and other similar parsing functions) as well as any string whose value has been set with the ASN1_STRING_set() function will additionally NUL terminate the byte array in the ASN1_STRING structure. However, it is possible for applications to directly construct valid ASN1_STRING structures which do not NUL terminate the byte array by directly setting the \"data\" and \"length\" fields in the ASN1_STRING array. This can also happen by using the ASN1_STRING_set0() function. Numerous OpenSSL functions that print ASN.1 data have been found to assume that the ASN1_STRING byte array will be NUL terminated, even though this is not guaranteed for strings that have been directly constructed. Where an application requests an ASN.1 structure to be printed, and where that ASN.1 structure contains ASN1_STRINGs that have been directly constructed by the application without NUL terminating the \"data\" field, then a read buffer overrun can occur. The same thing can also occur during name constraints processing of certificates (for example if a certificate has been directly constructed by the application instead of loading it via the OpenSSL parsing functions, and the certificate contains non NUL terminated ASN1_STRING structures). It can also occur in the X509_get1_email(), X509_REQ_get1_email() and X509_get1_ocsp() functions. If a malicious actor can cause an application to directly construct an ASN1_STRING and then process it through one of the affected OpenSSL functions then this issue could be hit. This might result in a crash (causing a Denial of Service attack). It could also result in the disclosure of private memory contents (such as private keys, or sensitive plaintext). Fixed in OpenSSL 1.1.1l (Affected 1.1.1-1.1.1k). Fixed in OpenSSL 1.0.2za (Affected 1.0.2-1.0.2y).",
9394
"Severity": "MEDIUM",

integration/testdata/alpine-310.json.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"Name": "Alpine Secdb",
9191
"URL": "https://secdb.alpinelinux.org/"
9292
},
93+
"Fingerprint": "sha256:6843bc8bcd09d2629416906fb83f17f31dde9a2702183571f9d447c3185814ca",
9394
"Title": "openssl: information disclosure in fork()",
9495
"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).",
9596
"Severity": "MEDIUM",
@@ -163,6 +164,7 @@
163164
"Name": "Alpine Secdb",
164165
"URL": "https://secdb.alpinelinux.org/"
165166
},
167+
"Fingerprint": "sha256:692932c929e26ea1116ebcaf2ca427771924d31272883401dedb3381d825063a",
166168
"Title": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
167169
"Description": "There is an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. Fixed in OpenSSL 1.1.1e (Affected 1.1.1-1.1.1d). Fixed in OpenSSL 1.0.2u (Affected 1.0.2-1.0.2t).",
168170
"Severity": "MEDIUM",
@@ -246,6 +248,7 @@
246248
"Name": "Alpine Secdb",
247249
"URL": "https://secdb.alpinelinux.org/"
248250
},
251+
"Fingerprint": "sha256:70c608adcc518d4c4bd9a183e0181da83ba22ba8b0d3a462573a72c8e6ad7362",
249252
"Title": "openssl: information disclosure in fork()",
250253
"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).",
251254
"Severity": "MEDIUM",
@@ -319,6 +322,7 @@
319322
"Name": "Alpine Secdb",
320323
"URL": "https://secdb.alpinelinux.org/"
321324
},
325+
"Fingerprint": "sha256:7327b4ce6851d27db6528dfec9b6ea312143eb7e77e1f7ada4f567a64e567663",
322326
"Title": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
323327
"Description": "There is an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. Fixed in OpenSSL 1.1.1e (Affected 1.1.1-1.1.1d). Fixed in OpenSSL 1.0.2u (Affected 1.0.2-1.0.2t).",
324328
"Severity": "MEDIUM",

integration/testdata/alpine-39-high-critical.json.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"Name": "Alpine Secdb",
9191
"URL": "https://secdb.alpinelinux.org/"
9292
},
93+
"Fingerprint": "sha256:294b2f8c416dd7b50971286b95e1f2685d7daf3c18957237fa7dc666178b6183",
9394
"Description": "musl libc through 1.1.23 has an x87 floating-point stack adjustment imbalance, related to the math/i386/ directory. In some cases, use of this library could introduce out-of-bounds writes that are not present in an application's source code.",
9495
"Severity": "CRITICAL",
9596
"CweIDs": [
@@ -136,6 +137,7 @@
136137
"Name": "Alpine Secdb",
137138
"URL": "https://secdb.alpinelinux.org/"
138139
},
140+
"Fingerprint": "sha256:fae2ab3e458f1237c8202860ac513a204cdc999c3283eba49665d0f1b3b79856",
139141
"Description": "musl libc through 1.1.23 has an x87 floating-point stack adjustment imbalance, related to the math/i386/ directory. In some cases, use of this library could introduce out-of-bounds writes that are not present in an application's source code.",
140142
"Severity": "CRITICAL",
141143
"CweIDs": [

integration/testdata/alpine-39-ignore-cveids.json.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"Name": "Alpine Secdb",
9191
"URL": "https://secdb.alpinelinux.org/"
9292
},
93+
"Fingerprint": "sha256:3dee09788d3e7607e0f6e4be151b5588fd339556441786d03efe99d73f92ada3",
9394
"Title": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
9495
"Description": "There is an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. Fixed in OpenSSL 1.1.1e (Affected 1.1.1-1.1.1d). Fixed in OpenSSL 1.0.2u (Affected 1.0.2-1.0.2t).",
9596
"Severity": "MEDIUM",
@@ -173,6 +174,7 @@
173174
"Name": "Alpine Secdb",
174175
"URL": "https://secdb.alpinelinux.org/"
175176
},
177+
"Fingerprint": "sha256:ddf71a0dc7fcaa5777046af6e5c12587fe24223e5ef5c6b020047b5e7297c041",
176178
"Title": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
177179
"Description": "There is an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. Fixed in OpenSSL 1.1.1e (Affected 1.1.1-1.1.1d). Fixed in OpenSSL 1.0.2u (Affected 1.0.2-1.0.2t).",
178180
"Severity": "MEDIUM",

0 commit comments

Comments
 (0)