anchore / grype

A vulnerability scanner for container images and filesystems
Apache License 2.0
8.58k stars 559 forks source link

fix: update ignored vulnerability count in tui #1837

Closed kzantow closed 5 months ago

kzantow commented 5 months ago

The number of ignored matches was not being updated in the TUI, causing confusing numbers to be displayed. For example, scanning the golang:latest resulted in:

$ grype golang:latest -o json | jq '.matches | length'
 ✔ Scanned for vulnerabilities     [454 vulnerability matches]  
   ├── by severity: 1 critical, 35 high, 82 medium, 8 low, 231 negligible (97 unknown)
   └── by status:   0 fixed, 454 not-fixed, 0 ignored 
297

With this fix, it now reads:

$ grype golang:latest -o json | jq '.matches | length'
 ✔ Scanned for vulnerabilities     [297 vulnerability matches]  
   ├── by severity: 1 critical, 35 high, 82 medium, 8 low, 231 negligible (97 unknown)
   └── by status:   0 fixed, 454 not-fixed, 157 ignored 
297

Additionally, when using --by-cve, ignored matches were not being reported properly due to applying the ignore rules twice. This PR also corrects that issue, which results in correct counts being reported in the TUI when using that option and correct ignored matches being reported in the JSON. Before:

$ grype golang:latest -o json --by-cve | jq '.matches | length'
 ✔ Scanned for vulnerabilities     [454 vulnerability matches]  
   ├── by severity: 1 critical, 35 high, 82 medium, 8 low, 231 negligible (97 unknown)
   └── by status:   0 fixed, 454 not-fixed, 0 ignored 
297

$ grype golang:latest -o json --by-cve | jq '.ignoredMatches | length'
0

After:

grype golang:latest -o json --by-cve | jq '.matches | length'
 ✔ Scanned for vulnerabilities     [297 vulnerability matches]  
   ├── by severity: 1 critical, 35 high, 82 medium, 8 low, 231 negligible (97 unknown)
   └── by status:   0 fixed, 454 not-fixed, 157 ignored 
297

grype golang:latest -o json --by-cve | jq '.ignoredMatches | length'
157

TODO:

luhring commented 5 months ago

Thanks for this! 🎉