-
Notifications
You must be signed in to change notification settings - Fork 106
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
Golang mod parser reports version that are not used in application #75
Comments
@knqyf263 Please help assign this to the person on rotation, let me know if you want me to look into this. |
It would be appreciated if you look into it. |
I have tried to change the implementation to |
@rahul2393 @knqyf263 any chance you can take a look at the PR? This is causing a lot of false positives for us. |
@rahul2393 @knqyf263 ping |
@rahul2393 @knqyf263 ping |
1 similar comment
@rahul2393 @knqyf263 ping |
Hi, we're sorry for the delay.
AFAIK, it is supported from Go 1.17. We couldn't know the dependencies that are actually used in 1.16 or less. So, I think we should keep the existing go.sum parser and add go.mod parser in addition. |
Yeah, you're right, the transitively are added automatically starting with Go 1.17. However, we can't rely on go.sum for everything below 1.17, since the last version in there isn't necessarily the version that is being imported. My proposal would be:
That way we can have the least amount of false positives, and they would only happen in transitive dependencies. |
@knqyf263 I tried to make a start with this, but the dep-parser is really focused on only reading 1 file, so it's hard to access both the go.mod and go.sum at the same time when it reaches the |
Could you elaborate on it? According to the reference, the newer version is preferred.
Do you mean specified versions in direct dependencies are prioritized? In the above example, even if E1.1 imports A1.3, A1.2 is preferred? In that case, go.sum contains A1.2 and A1.3, but A1.2 will be selected, right? |
We're trying to allow fanal to process multiple files at the same time, but as a workaround until then, we can let go-dep-parser parse both files respectively, then merge go.mod and go.sum in hook. |
Yeah, that's what I was thinking. So let's say I import |
Thanks for investigating! So, can we simply skip go.mod in Go 1.16 or less and take the latest versions in go.sum? |
I'd say it would still be good to use the
That sounds doable. I think there is one problem though. |
OK, it makes sense.
What if we add Here is PoC: 76e54d4 If it looks good, I'll open another PR adding |
Yeah, sounds/looks good to me :) |
Thanks for confirming. We'll add it. |
I'm currently looking into why the parser reports versions being used that are not even in my application.
I noticed it's because the issues were being reported in dependencies of dependencies (sometimes even further down the tree), the code was not reachable at all, so the code is not included in the application, yet it reports it as a vulnerability.
Now I do get this, it's impossible for the parser to see if a dependency is actually being used. The good thing is that Go automatically does this for you already. It does this by adding all dependencies into the go.mod file, even the transitive dependencies (marked with
//indirect
), as long as there is an import somewhere, it will be added to the go.mod file.The Go blog says this about the go.sum file:
So I don't really see why go.sum is used here, and not go.mod. Can we change the parser to use go.mod?
When you execute
go mod edit -json
you will get a JSON representation of thego.mod
file that's very clean and easy to parse.CC @rahul2393, since you have implemented this dep parser in #21
The text was updated successfully, but these errors were encountered: