Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add warning if severity not from vendor (or NVD or GH) is used #6726

Merged

Conversation

DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented May 20, 2024

Description

See #6714 (comment)

Example:
изображение

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this May 20, 2024
@DmitriyLewen DmitriyLewen marked this pull request as ready for review May 20, 2024 07:20
@@ -130,6 +130,7 @@ func (c Client) getVendorSeverity(vulnID string, vuln *dbTypes.Vulnerability, so
return dbTypes.SeverityUnknown.String(), ""
}

log.Warn("Vendor and NVD don't have severity level. Severity from another vendor is used (see `VendorSeverity` in `json` format).", log.String("CVE", vulnID))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessarily CVE-ID.

Suggested change
log.Warn("Vendor and NVD don't have severity level. Severity from another vendor is used (see `VendorSeverity` in `json` format).", log.String("CVE", vulnID))
log.Warn("Vendor and NVD don't have severity level. Severity from another vendor is used (see `VendorSeverity` in `json` format).", log.String("vulnerability-id", vulnID))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vendor is unclear. We may want to show the source (dbTypes.SourceID).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this, but there is 1 problem with this.
We fill severity filed in trivy-db:
https://github.com/aquasecurity/trivy-db/blob/b8fe1376ffcdc69fe454f0a8a481ab485e47aea5/pkg/vulnsrc/vulnerability/vulnerability.go#L92-L108

Therefore, we don't have info about vendor for this severity.

We can only check vendorSeverity and detect vendor with same severity.
But if 2 vendors use this severity, we may make mistake in our choice

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we should say "Debian and NVD don't have severity" when scanning a Debian image and "Ubuntu and NVD don't have severity" when scanning an Ubuntu image. We need to consider what should be displayed with language-specific packages, though.

Copy link
Contributor Author

@DmitriyLewen DmitriyLewen May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand you now.
We can use dataSource.Name (see :
изображение

It also works for language-specific packages

@@ -130,6 +129,7 @@ func (c Client) getVendorSeverity(vulnID string, vuln *dbTypes.Vulnerability, so
return dbTypes.SeverityUnknown.String(), ""
}

log.Warn(fmt.Sprintf("%q and \"NVD\" don't have severity level. Severity from another vendor is used (see `VendorSeverity` in `json` format).", dataSource.Name), log.String("vulnerability-id", vulnID))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need sync.Once to prevent from showing the same messages many times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should show each vulnerability with non-vendor (non-nvd) severity.
It will be difficult (and possibly manual) for user to detect vulnerabilities with inappropriate severity levels if we simply say that some vulnerabilities use different severity levels.

As another way, we can save all these vulnerabilities and insert this list into one warning.
wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if there are 100 vulnerabilities, we possibly show 100 warn messages, right?

Copy link
Contributor Author

@DmitriyLewen DmitriyLewen Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. but I hope we don't get 100 vulnerabilities

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think 100 vulns are so many. I saw environments with 500 vulns or even more than 1000 vulns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's use once. We can always update this - if users require it.

Update in b23527d

// Show warning if we use severity from another vendor
// cf. https://github.com/aquasecurity/trivy/issues/6714
var onceWarn = sync.OnceFunc(func() {
log.Warn("For some vulnerabilities, severities from other vendors were used because their data sources and NVD don't contain severities. You can view severity list from vendors in `json` format in `VendorSeverity` field.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the message, I feel like it's still unclear for users. We may want to update the document and add a link in the warning message, like "For details, read https://aquasecurity.github.io/trivy/latest/docs/scanner/vulnerability/#severity-selection." What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of ideas that we can add. I will update docs and write to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ec412a3
wdyt?

@knqyf263 knqyf263 enabled auto-merge June 19, 2024 11:27
@knqyf263 knqyf263 added this pull request to the merge queue Jun 19, 2024
Merged via the queue into aquasecurity:main with commit dfe757e Jun 19, 2024
17 checks passed
@DmitriyLewen DmitriyLewen deleted the refactor/vendor-severity-missing-log branch June 20, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unexpected severity if nvd and source don't have severity for vulnerability
2 participants