Open
Description
govulncheck version
govulncheck -version
Go: go1.22.4
Scanner: govulncheck@v1.1.2
DB: https://vuln.go.dev
DB updated: 2024-06-20 18:18:26 +0000 UTC
Does this issue reproduce at the latest version of golang.org/x/vuln?
Yes.
Output of go env
in your module/workspace:
> go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/gmacedo/.cache/go-build'
GOENV='/home/gmacedo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/gmacedo/go/pkg/mod'
GOOS='linux'
GOPATH='/home/gmacedo/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib64/go/1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib64/go/1.22/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/gmacedo/code/github.com/macedogm/vuln/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2885216502=/tmp/go-build -gno-record-gcc-switches'
### What did you do?
Executing `govulncheck` with `-format openvex` produces a valid OpenVEX report, but the list of the affect products lacks valid information, instead it always contains `Unknown Product`.
### What did you see happen?
Please see above.
### What did you expect to see?
I would expect to see the correct list of affected products, i.e., the Go package path and version, where the vulnerabilities was identified, in the right Purl format for Go packages - `pkg:golang/...`.
Activity
gabyhelp commentedon Jun 24, 2024
Similar Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
macedogm commentedon Jun 24, 2024
A tentative fix/improvement for this is done in golang/vuln#11.
zpavlinovic commentedon Jun 25, 2024
@maceonthompson
To summarize, the proposal here is to use (purls of) packages of detected vulnerabilities as product IDs. This would allow govulncheck openvex output to work with other tools, such as trivy and grype.
This proposal is in contrast with what we were thinking initially and that is to have the artifact under analysis as the product. That approach, however, is difficult when dealing with, say, different package patterns of a module. The proposal here does not have these issues. It also seems openvex spec allows what is proposed here.
macedogm commentedon Jun 25, 2024
Hey @maceonthompson 👋🏻
@zpavlinovic thanks for explanation above.
FYI we were having an initial discussion about a possible implementation for this in golang/vuln#11 (comment). The code is still available in my fork https://github.com/macedogm/vuln/commits/openvex-improvement/.
It's simple, but works. The biggest challenge that I saw is that govulncheck's OSV struct doesn't contain a way to track the exact affected version of the vulnerable package/path that was identified in the scanned code (see in https://github.com/golang/vuln/blob/d44b651a2e0f43966413e20b65cb619bdb621e7e/internal/vulncheck/emit.go#L21). Due to that, I added an Internal struct inside OSV to hold the needed info. Otherwise, the biggest benefit of the OpenVEX spec cannot be achieved, which is to identify the exact product (package and version) not affected, which can be removed by the downstream vulnerability scanners (Trivy, Grype etc.), although govulncheck knows about the exact version.
The product, in the OpenVEX spec, can have subcomponents. My initial implementation doesn't add this.
Where I work we are planning to use this as a way to remove hundreds of false positives flagged by vulnerability scanners. Initially we are still using my forked version.
Happy to collaborate further if needed.
zpavlinovic commentedon Jun 26, 2024
Pushing things inside OSV struct is not the way to go IMO. There should be a different way of doing this, but that is an implementation detail. Your code is useful nonetheless. We'll use the issue here to decide whether to proceed with using vulnerable packages as product IDs.
maceonthompson commentedon Jul 4, 2024
Hi @macedogm,
Thank you for the work/time you've already spent on this issue!
If the idea is to use the source of the vulnerability (i.e. the identifier of the offending dependency) in the product field, I think govulncheck’s output already contains all the information we need.
OSVs contain module and package paths for a vulnerability, and findings always contain the module path and imported version of the offending vulnerable package/path. If govulncheck emits an OSV and no findings, that means that the vulnerable package was not imported at a vulnerable version.
I really like this proposal, but I think it goes against the VEX specification (see Section 2.5.1 and 2.5.2), which state that the Product ID should be the artifact that you’re scanning, and subcomponents are where vulnerable product IDs can be filled in. If we kept the initial idea but populated the subcomponent field instead, would this work/help your use case?
macedogm commentedon Jul 5, 2024
Hey @maceonthompson.
Thanks for the update.
You are totally right, in the implementation that I did I was listing directly the affected path/package and version. Example from my forked version:
Yes, it would definitely work and be in full compliance with the spec 👍🏻
Out of curiosity, how do you plan to derive the artifact, for example, when the scan is done in
source
versusbinary
mode?Thanks for working on this, it's much appreciated.
puerco commentedon Jul 9, 2024
Hello from the @openvex project 👋
Thanks for opening this issue, I have been meaning to contribute a patch to fix this but I'm glad this discussion is already underway!
Let me add some context on the VEX product and subproduct.
@maceonthompson's reading of the spec is correct here:
Let's imagine two scenarios, source and binary.
For example, when running in source mode, to craft a statement for the source of
vexctl
(at a random commit) the main vexctl module would act as the product and the subcomponent would point to the dependency containing the vulnerability. Here is an example fixed from the output of govulncheck:Now when it comes to binaries, you don't need to specify a package URL (a purl). If you have a purl for one, its fine but the product identifier field in OpenVEX takes a URI so, in the case of binaries, the best way to specify them is to use a URI with a
file
schema but note that the real value comes from anchoring the statement to the file with its hashes. Our tooling will operate with hashes when available.This is the same output but with a linux binary built from the same build point as above. Note that the path really becomes irrelevant once we can content-address the binary with a hash:
The important part is that the vex statement operates on the triad of a vulnerability in a dependency evaluated in the context of the product (source or an artifact including the dependency).
I'm happy to contribute a patch to handle these :)
10 remaining items
knqyf263 commentedon Jul 11, 2024
Yes, that's correct. If a product has subcomponents, Trivy applies VEX to the dependency graph (the same idea is described in the OSV blog). Incorrect product ID results in nothing filtered as it doesn't match the graph.
https://aquasecurity.github.io/trivy/v0.53/docs/supply-chain/vex/#applying-vex-to-dependency-trees
If a product has no subcomponents, it works as a simple filter in Trivy, but in that case it may incorrectly filter vulnerabilities in another product.
For example, my project is not affected by GO-2021-0064 in
k8s.io/client-go
, but other projects may be affected. Ideally, the correct product and subcomponents should be filled in.That's exactly what we're doing now.
gopherbot commentedon Jul 18, 2024
Change https://go.dev/cl/598956 mentions this issue:
internal/openvex: populate product subcomponents
maceonthompson commentedon Jul 31, 2024
A follow up question on subcomponent IDs:
Right now we are planning on having the subcomponent ID be just the module path (since that seems to be most helpful based on the examples above), but govulncheck has more specific package and symbol information that we could theoretically include as well.
Would it be helpful to encode that extra information at the end of the PURL?
puerco commentedon Jul 31, 2024
I think the import path and version should be enough. What else could you encode in the purl? The more specific the purl is the harder it is to match but perhaps I'm missing another use case that may make more sense.
maceonthompson commentedon Jul 31, 2024
I agree that the matching becomes more difficult, which is why we're currently basing it just off the module path. We could, however, include the package path as well - which is technically part of the import path. But if the consensus is that the extra info isn't useful for this use case, I'm happy to leave it as is.
zpavlinovic commentedon Jul 31, 2024
FWIW, this is also what the golang/vuln#11 proposed fix does. There is also a consistency issue. If someone runs govulncheck in
-scan module
mode, then package info will be missing.macedogm commentedon Jul 31, 2024
My first answer is to agree with:
@maceonthompson could you please provide some examples of how the subcomponent ID would be regarding what you mentioned?
Asking, so we have detailed info to make a call and how different the information would be for each one of the scan mode - 'module', 'package', or 'symbol'.
maceonthompson commentedon Jul 31, 2024
@macedogm An example: Say there is a vulnerability in the module
golang.org/x/vuln
at versionv1.0.0
. More specifically, it is present in the packagegolang.org/x/vuln/scan
and has the vulnerable symbolfoo
. Given each scan mode, this is what the ID could look likeThis matches how pkgsite presents packages vs modules.
Otherwise, every scan mode would match "module" mode, not including the package path.
I was more interested in if that would be useful - it seems that the consensus is that easier matching is more important, so I'm happy to just include the module path.
macedogm commentedon Jul 31, 2024
@maceonthompson thanks for providing the examples.
It's useful, but I fully agree that
easier matching is more important
, specially because it allows removing false positives at scale. 👍🏻internal/openvex: populate product subcomponents
v
prefix rancher/vexhub#27