-
Notifications
You must be signed in to change notification settings - Fork 92
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
Go detector overreports dependencies, sometimes causing false vuln claims that are unusually difficult to "upgrade anyway" #1333
Comments
@dagood - We have seen multiple approaches Go experts have suggested over the years, but none seems to have checked all boxes. Mind introducing a new Go detector that we can experiment with using this new strategy? We can leverage the experiments framework to capture deltas between new / current detector and analyze the deltas. Questions:
|
I wouldn't say I have a strategy here, so far this is just a bug report with a few tools and args that I suggest avoiding, with other commands to contrast against the bad info being reported by those tools/args. Getting this repro case into the test suite and figuring out what to do from there was how I was thinking this could be approached.
|
@dagood - I am having an offline thread with another dev reporting these false positives and it seems like
It appears that it is possible to retrieve the complete list of dependencies in a Go module after pruning. Running |
If I'm understanding this right, you're saying that it looks like parsing a valid (buildable) >=1.17 I suppose there's a chance that someone has an unused dependency in the Actually, reading https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md again, it seems like the fallback strategy already covers a lot of this... it's not clear to me why it's the fallback rather than the main strategy. (The benefit of having the full graph isn't clear to me, if that's the reason.) The doc does mention "The fallback detections trategy is known to overreport", but it seems that this might just be an old sentence from when there was only the <1.17 fallback strategy and not the >=1.17 strategy.
Was that meant to be "as opposed to I do wonder if there's a |
Your understanding is correct. Originally the Go documentation wasn't very clear on what was included in Go.mod file vs what wasn't and it that included MVS was part of go.mod or not (it is).
If a vulnerability comes from a transitive dependency, you can easily pinpoint which was the root dependency to blame. If you don't have the graph you need to go hunting for the roots (which isn't a dealbreaker but slightly more work for devs).
You are correct, we will update docs to match the latest behavior. overreporting only happens on Go <1.17 since we parse both go.mod and go.sum files.
The only one that we know of as of today is |
I'm helping work on a project that needs to build https://github.com/konveyor/kantra/tree/215adcbbdfc337b5dee439404dc280d78e3e62f6 in Microsoft systems. This means component-detection is used to detect its dependencies, and the dependencies are associated with known vulnerabilities.
Behavior
CG claimed recently that that commit depends on golang.org/x/crypto v0.23.0, and the alert says:
We think this is a false positive: the project doesn't depend on x/crypto. But, it wouldn't hurt to upgrade anyway, and we might as well, to be sure. So, we run
go get -v -u golang.org/x/crypto@v0.31.0
. That adds the dependency to go.mod and go.sum.Then we run
go mod tidy
to clean up and prepare to submit the PR. It removes the dependency from go.mod and go.sum!This puts us in a bad state, where there are a few workarounds:
go mod tidy
again (and adjust CI to not require tidiness). This is a bad continuous state to be in.tools
build tag, this has no side effects other than clutter. But you need to be familiar with Go and with the specific project's infrastructure to apply this workaround consistently.I think component-detection needs to fix this type of false positive. It's particularly disruptive, compared with other types of false positive where we can simply upgrade the dependency whether or not it's strictly necessary.
Repro example and
go list
I put together a simplified example of this false positive. https://github.com/dagood/repro/tree/repro/go-cg-unupgradeable-component/myapp is an example app
myapp
that depends on a modulesomelibrary
that uses x/crypto v0.23.0, but only one of its two library packages uses a package from x/crypto.The detector currently uses
go list -mod=readonly -m -json all
to discover dependencies. The-m
means it's in "module mode", which doesn't match whatgo list
,go mod tidy
, and the rest of the Go ecosystem normally cares about, which are packages.go mod graph
would overreport in a similar way if it were used for initial component detection.If you use e.g.
go list -mod=readonly -deps -f '{{.ImportPath}} ---- {{.Module}}' ./...
, it doesn't include x/crypto because at a package level, x/crypto is totally unused.(You can also add logic to the command itself to filter down to packages that are associated with a module:
go list -mod=readonly -deps -f '{{if .Module}}{{.ImportPath}} ---- {{.Module}}{{end}}' ./...
.)I also wrote a test app that does use the part of
somelibrary
that uses x/crypto, and you can see x/crypto 0.23.0 show up in the right places to be detected: https://github.com/dagood/repro/tree/repro/go-cg-unupgradeable-component/myappcrypto.govulncheck
I'm not proposing to use
govulncheck
for Component Governance. It would be good, but not necessary to fix the most disruptive false positives. It looks even deeper at the dependencies. For example:(The vulnerability is specifically in golang.org/x/crypto/ssh, which isn't used here.)
The text was updated successfully, but these errors were encountered: