Skip to content

Commit

Permalink
fix(report): update Gitlab template (#5721)
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Dec 7, 2023
1 parent be1c554 commit eb97419
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 41 deletions.
34 changes: 25 additions & 9 deletions contrib/gitlab.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
{{- /* Template based on https://docs.gitlab.com/ee/user/application_security/container_scanning/#reports-json-format */ -}}
{
"version": "14.0.6",
"version": "15.0.7",
"scan": {
"analyzer": {
"id": "trivy",
"name": "Trivy",
"vendor": {
"name": "Aqua Security"
},
"version": "{{ appVersion }}"
},
"end_time": "{{ now | date "2006-01-02T15:04:05" }}",
"scanner": {
"id": "trivy",
"name": "Trivy",
"url": "https://github.com/aquasecurity/trivy/",
"vendor": {
"name": "Aqua Security"
},
"version": "{{ appVersion }}"
},
"start_time": "{{ now | date "2006-01-02T15:04:05" }}",
"status": "success",
"type": "container_scanning"
},
"vulnerabilities": [
{{- $t_first := true }}
{{- range . }}
Expand All @@ -14,11 +37,8 @@
{{- end }}
{
"id": "{{ .VulnerabilityID }}",
"category": "container_scanning",
"message": {{ .Title | printf "%q" }},
"name": {{ .Title | printf "%q" }},
"description": {{ .Description | printf "%q" }},
{{- /* cve is a deprecated key, use id instead */}}
"cve": "{{ .VulnerabilityID }}",
"severity": {{ if eq .Severity "UNKNOWN" -}}
"Unknown"
{{- else if eq .Severity "LOW" -}}
Expand All @@ -37,10 +57,6 @@
{{- else -}}
"No solution provided"
{{- end }},
"scanner": {
"id": "trivy",
"name": "trivy"
},
"location": {
"dependency": {
"package": {
Expand Down
57 changes: 28 additions & 29 deletions integration/testdata/alpine-310.gitlab.golden
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
{
"version": "14.0.6",
"version": "15.0.7",
"scan": {
"analyzer": {
"id": "trivy",
"name": "Trivy",
"vendor": {
"name": "Aqua Security"
},
"version": "dev"
},
"end_time": "2021-08-25T12:20:30",
"scanner": {
"id": "trivy",
"name": "Trivy",
"url": "https://github.com/aquasecurity/trivy/",
"vendor": {
"name": "Aqua Security"
},
"version": "dev"
},
"start_time": "2021-08-25T12:20:30",
"status": "success",
"type": "container_scanning"
},
"vulnerabilities": [
{
"id": "CVE-2019-1549",
"category": "container_scanning",
"message": "openssl: information disclosure in fork()",
"name": "openssl: information disclosure in fork()",
"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).",
"cve": "CVE-2019-1549",
"severity": "Medium",
"solution": "Upgrade libcrypto1.1 to 1.1.1d-r0",
"scanner": {
"id": "trivy",
"name": "trivy"
},
"location": {
"dependency": {
"package": {
Expand Down Expand Up @@ -76,16 +93,10 @@
},
{
"id": "CVE-2019-1551",
"category": "container_scanning",
"message": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
"name": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
"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).",
"cve": "CVE-2019-1551",
"severity": "Medium",
"solution": "Upgrade libcrypto1.1 to 1.1.1d-r2",
"scanner": {
"id": "trivy",
"name": "trivy"
},
"location": {
"dependency": {
"package": {
Expand Down Expand Up @@ -169,16 +180,10 @@
},
{
"id": "CVE-2019-1549",
"category": "container_scanning",
"message": "openssl: information disclosure in fork()",
"name": "openssl: information disclosure in fork()",
"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).",
"cve": "CVE-2019-1549",
"severity": "Medium",
"solution": "Upgrade libssl1.1 to 1.1.1d-r0",
"scanner": {
"id": "trivy",
"name": "trivy"
},
"location": {
"dependency": {
"package": {
Expand Down Expand Up @@ -242,16 +247,10 @@
},
{
"id": "CVE-2019-1551",
"category": "container_scanning",
"message": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
"name": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64",
"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).",
"cve": "CVE-2019-1551",
"severity": "Medium",
"solution": "Upgrade libssl1.1 to 1.1.1d-r2",
"scanner": {
"id": "trivy",
"name": "trivy"
},
"location": {
"dependency": {
"package": {
Expand Down
5 changes: 4 additions & 1 deletion pkg/report/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TemplateWriter struct {
}

// NewTemplateWriter is the factory method to return TemplateWriter object
func NewTemplateWriter(output io.Writer, outputTemplate string) (*TemplateWriter, error) {
func NewTemplateWriter(output io.Writer, outputTemplate, appVersion string) (*TemplateWriter, error) {
if strings.HasPrefix(outputTemplate, "@") {
buf, err := os.ReadFile(strings.TrimPrefix(outputTemplate, "@"))
if err != nil {
Expand All @@ -54,6 +54,9 @@ func NewTemplateWriter(output io.Writer, outputTemplate string) (*TemplateWriter
templateFuncMap["sourceID"] = func(input string) dbTypes.SourceID {
return dbTypes.SourceID(input)
}
templateFuncMap["appVersion"] = func() string {
return appVersion
}

// Overwrite functions
for k, v := range CustomTemplateFuncMap {
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestReportWriter_Template(t *testing.T) {
},
}

w, err := report.NewTemplateWriter(&got, tc.template)
w, err := report.NewTemplateWriter(&got, tc.template, "dev")
require.NoError(t, err)
err = w.Write(inputReport)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Write(ctx context.Context, report types.Report, option flag.Options) (err e
break
}
var err error
if writer, err = NewTemplateWriter(output, option.Template); err != nil {
if writer, err = NewTemplateWriter(output, option.Template, option.AppVersion); err != nil {
return xerrors.Errorf("failed to initialize template writer: %w", err)
}
case types.FormatSarif:
Expand Down

0 comments on commit eb97419

Please sign in to comment.