-
Notifications
You must be signed in to change notification settings - Fork 75
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
Suggested go list -m json all
vulnerability checks swathes of dependencies that never end up in a binary
#228
Comments
Related issues around |
@dnwe this is super helpful, thanks for filing this. I think @bhamail is taking a look, and likely @zendern . We originally used |
However, what do you mean by not end up in the binary, in regards to a |
@DarthHater the viper --> jwt-go dependecy (famously unmaintained and vulnerable) is a good example Whilst there might be reachable areas of viper as a library that will reach out to etcd+jwt-go, I believe the go build command will walk the tree of import paths at the package level and will only compile-in what is reachable from your As an example, say you just have a bare-bones main.go that looks like this: package main
import (
"github.com/spf13/viper"
)
func main() {
_ = viper.Viper{}
} The
Yet
Similarly for
And if you verbosely compile you can see all the import paths the compiler navigates, and that doesn't include etcd or jwt-go:
Now if you follow Viper's documentation and decide you want to enable Remote Key/Value Store Support then you might add the import like so: package main
import (
"github.com/spf13/viper"
_ "github.com/spf13/viper/remote"
)
func main() {
_ = viper.Viper{}
} Then the etcd client will start showing up as a true dependency:
You'll notice however that we still haven't been compiling in jwt-go even now we've pulled in the etcd dependency. The reason for that is that jwt-go is actually a test-only dependency of the etcd client package. So your CI process would only ever actually be touching the jwt-go code if you running
Notice the So in this case, I don't think it would be correct for nancy to flag up the jwt-go vulnerability as a problem for my parent package/module because it is unreachable for me. Only if we ended up importing etcd/auth or jwt-go (either directly or indirectly) would it be a valid vulnerability to flag in this case |
@DarthHater (regarding your question on |
@dnwe this is great information, we super appreciate it! A few of us are talking about it, it may be a week or two before we get much done (PR's are welcome, if you have interest too), but this is neat in that we'd always wondered if there was a good way to exclude the deps that aren't making it into your project. You've done a lot of detective work (just like good ole |
May not be relevant for this particular issue... |
@jdbranham I THINK I sidestepped that in my implementation, but I did see those in |
When checking for vulnerabilities in Golang dependencies using Sonatype's OSS Index via
nancy sleuth
, the README advises to rungo list -json -m all | nancy sleuth [flags]
. However, this will frequently flag up vulnerabilities for test dependencies and dependencies of dependencies that never actually end up in any resulting binary, but are simply tracked by the go.mod/go.sum. These don't show up ingo list -deps
orgo version -m <binary>
and the only way to satisfy the scanner for them is to put arbritraryreplace { ... }
directives to bump their versions even though it has no effect on the binary.Parsing the json output of
go list -deps -json ./...
should give a more accurate picture of the dependencies that are actually used to make up the project binaries. Currently it is possible to mux that into ago list -m all
style format by doing something like:But I think it would be helpful if the sleuth command itself could understand the
go list -deps -json
format itself and directly parse it.cc @bhamail / @DarthHater
The text was updated successfully, but these errors were encountered: