News for hackers. Stuff that matters.
Re:Vulnerability Management for Go by psanford on Tuesday September 06, 2022 @11:34AM (#32738555)
> Govulncheck analyzes your codebase and only surfaces vulnerabilities that actually affect you, based on which functions in your code are transitively calling vulnerable functions.

This is huge! Every existing vulnerability scanner that I've worked with have just looked at go.sum, which ends up reporting a lot of vulnerabilities that you don't actually care about because your code isn't actually linking to the optional transitive dependency that has the vulnerability in it.

Thank you, Go team!

Re:Vulnerability Management for Go by freeqaz on Tuesday September 06, 2022 @01:08PM (#32739997)
This is really cool to see because this is the #1 problem with current tools (as you said). I call it "alert fatigue" in my head because it's meaningless when you have 100+ vulns to fix but they're 99% unexploitable.

I have a bit of a bone to pick with this space: I've been working on this problem for a few months now (link to repo[0] and blog[1]).

My background is Application Security and, as is often the case with devs, rage fuels me in my desire to fix this space. Well, Log4Shell helped too.

As another comment said, doing this in a language agnostic way is a big PITA and we haven't fully built it yet. We are using SemGrep to do very basic static analysis (see if vulnerable function is ever imported + called). But we're not doing fancy Inter-process taint analysis like CodeQL can.

(We have a big Merkle tree that represents the dependency tree and that's how we are able to make the CI/CD check take only a few seconds because we can pre-compute.)

Anyway, if you have a second to help, we have a GitHub App[2] that you can install to test this out + help us find bugs. It's best at NPM now but we have basic support for other languages (no dep tree analysis yet).

There are so many edge cases with the ways that repos are setup so just have more scans coming in helps a ton. (Well, it breaks stuff, but we already determined that rage sustains me.)

Thank you. climbs off of soap box

0: https://github.com/lunasec-io/lunasec

1: https://www.lunasec.io/docs/blog/the-issue-with-vuln-scanner...

2: https://github.com/marketplace/lunatrace-by-lunasec

Re:Vulnerability Management for Go by salmo on Tuesday September 06, 2022 @03:54PM (#32742388)
Oh my goodness I hate that so much. Every time I have to explain that go.sum lists every compatible version, not the version baked in.

But this is even an improvement over any other language I've seen. All just flag CVEs in dependent libraries when 99% of the time it's like "to be vulnerable you have to do [really stupid thing]".

Let's hope that vulnerability scanning vendors adopt using this. For my own stuff or minor work things, it's great. When I fall under the specter of officialness, I'll still get popped by the Enterprise Security Scanning Standard Tool.

Re:Vulnerability Management for Go by Thaxll on Tuesday September 06, 2022 @04:43PM (#32742950)
Why would some people even care or look at go.sum where go.mod is clean and self explanatory?
Re:Vulnerability Management for Go by preseinger on Tuesday September 06, 2022 @07:16PM (#32744395)
Prior to 1.17, go.mod was not a complete representation of the dep graph. More broadly, the problem is that programmers expect dependency management tooling to have a lock file, see go.sum, and assume it's a lock file. This isn't a problem with those programmers, it's a problem with Go modules.
Re:Vulnerability Management for Go by remus on Wednesday September 07, 2022 @03:20AM (#32747522)
> This isn't a problem with those programmers, it's a problem with Go modules.

That seems like a bit of a jump! Maybe there's a better way of building dependency management tooling that doesn't use lock files, it seems strange to tie yourself to this approach just because it's how other tools work.

Re:Vulnerability Management for Go by Thaxll on Wednesday September 07, 2022 @09:38AM (#32750439)
go.mod is the lock file.
Re:Vulnerability Management for Go by preseinger on Thursday September 08, 2022 @03:43PM (#32770997)
It isn't in the traditional sense. There isn't anything in its specification that guarantees the things that most people expect lock files to guarantee.
Re:Vulnerability Management for Go by salmo on Tuesday September 06, 2022 @06:29PM (#32744042)
Well, I do understand that the actual version used there is ambiguous.

Probably the best would be to take the newest from go.sum. That’s what some scanners are doing now.

Filed bugs with 2 vendors over this though.

Re:Vulnerability Management for Go by preseinger on Tuesday September 06, 2022 @07:17PM (#32744398)
The newest from go.sum isn't reliably the version used in the dep graph. The only way to get that information reliably is via go list. Unfortunately.
Re:Vulnerability Management for Go by salmo on Tuesday September 06, 2022 @07:31PM (#32744520)
Oh, you are totally right. I read that in the GitLab issue tracking their version of the problem and totally forgot that’s where they landed.
Re:Vulnerability Management for Go by smoyer on Wednesday September 07, 2022 @09:15AM (#32750130)
Also don't forget that more than one version of a dependency might be compiled into your application!
Re:Vulnerability Management for Go by preseinger on Thursday September 08, 2022 @03:42PM (#32770985)
Only one major version. And go considers different major versions to be different dependencies.
Re:Vulnerability Management for Go by arccy on Wednesday September 07, 2022 @11:02AM (#32751554)
not true for go
Re:Vulnerability Management for Go by kubanczyk on Wednesday September 07, 2022 @05:42AM (#32748517)
For the curious it's:

    go list -m all
Re:Vulnerability Management for Go by codelion on Tuesday September 06, 2022 @12:04PM (#32739032)
Good to see Govulncheck doing a vulnerable methods analysis for surfacing only the relevant issues. Many app sec vendors do it now for languages like Java and .NET. I originally created the vulnerable methods analysis back in 2015 - https://www.veracode.com/blog/managing-appsec/vulnerable-met... the same idea has been now implemented by WhiteSource (Mend), Snyk etc.
Re:Vulnerability Management for Go by seth123456 on Tuesday September 06, 2022 @01:49PM (#32740534)
The great thing is that when it becomes part of the toolchain it will also be available for the latest version of go as it is released.

Right now veracode is stuck at go 1.17 support - maybe this will also help being up to date for such vendors more easily

Re:Vulnerability Management for Go by biomcgary on Tuesday September 06, 2022 @02:51PM (#32741493)
This seems like a lot of work to identify the vulnerable functions that are called transitively. Could this work be reused to perform tree-shaking, so that Go only compiles the code you actually need? (Or, does Go already do this at compilation?)
Re:Vulnerability Management for Go by adonovan on Tuesday September 06, 2022 @04:58PM (#32743119)
govulncheck builds a static approximation of the call graph using Variable Type Analysis (VTA), which dynamically tabulates the set of interface method calls and the set of concrete types that each interface value may hold, to discover the set of functions potentially reachable from main. (VTA is a refinement of Rapid Type Analysis (RTA), which holds only one set of concrete types for all interface values in the whole program.) The result should be more precise than the linker.

See:

- https://pkg.go.dev/golang.org/x/tools/go/callgraph/vta

- https://pkg.go.dev/golang.org/x/tools/go/callgraph/rta

Re:Vulnerability Management for Go by lukax on Tuesday September 06, 2022 @03:24PM (#32742004)
Go is a compiled language that uses a linker which means that only the functions that are called end up in the final binary. So yes, go does "tree-shaking".
Re:Vulnerability Management for Go by jrockway on Tuesday September 06, 2022 @04:33PM (#32742836)
It's important to read the caveats: https://github.com/golang/go/blob/master/src/cmd/link/intern..., the most important of which is:

  // The third case is handled by looking to see if any of:
  //   - reflect.Value.Method or MethodByName is reachable
  //   - reflect.Type.Method or MethodByName is called (through the
  //     REFLECTMETHOD attribute marked by the compiler).
  //
  // If any of these happen, all bets are off and all exported methods
  // of reachable types are marked reachable.
Basically, if you do certain kinds of reflection, then more code is theoretically reachable and will be included in your binary. In practice, you end up with a large binary in anything that calls into autogenerated APIs.
Re:Vulnerability Management for Go by biomcgary on Thursday September 08, 2022 @01:35PM (#32768870)
That is a useful clarification. It seems to explain why the use of the fmt Go's std lib formatting and printing package, seems to pull in so much. Surely, it is performing a fair amount of reflection under the hood.
Re:Vulnerability Management for Go by barsonme on Thursday September 08, 2022 @02:38PM (#32770011)
The fmt package should not put the compiler into conservative mode. If it does, file a bug report.
Re:Vulnerability Management for Go by tucnak on Wednesday September 07, 2022 @12:44AM (#32746400)
The autogenerated APIs aren't something as prevalent as one may think.
[dead]
Re:Vulnerability Management for Go by psanford on Tuesday September 06, 2022 @11:47AM (#32738743)
What? How does a piece of code that isn't compiled into your binary make you vulnerable?
Re:Vulnerability Management for Go by auspex on Wednesday September 07, 2022 @12:19PM (#32752623)
I should have been more clear that I was referring to external dependencies that are included. I did some research and there’s so much extra stuff included in the go.sum. You’re right that would result in a lot of false positives.
Re:Vulnerability Management for Go by masklinn on Tuesday September 06, 2022 @12:09PM (#32739122)
> Just because you don’t link to or call it… if you include vulnerable code you’re still vulnerable.

That makes no sense. If you never use the vulnerable code, how would an attacker access the vulnerability through your system? Especially with DCE, the vulnerability might not even be in the binary.

Re:Vulnerability Management for Go by tptacek on Tuesday September 06, 2022 @12:03PM (#32739013)
No, this is not at all a valid argument.
Re:Vulnerability Management for Go by freeqaz on Tuesday September 06, 2022 @01:15PM (#32740080)
The only argument I can think of here is with NPM post install hooks. But for Golang, unless you import the code, I'm pretty certain that there is no way to exploit or backdoor an app.

Or is there something I'm missing?

Re:Vulnerability Management for Go by ikiris on Tuesday September 06, 2022 @02:00PM (#32740692)
I guess I just found an interview question. Thanks!
Re:Vulnerability Management for Go by sunbum on Wednesday September 07, 2022 @09:19AM (#32750173)
Good way to weed out good developers!
Re:Vulnerability Management for Go by ikiris on Wednesday September 07, 2022 @09:30PM (#32759856)
No, I meant anyone who believes this is weeded out.
Re:Vulnerability Management for Go by umvi on Tuesday September 06, 2022 @11:48AM (#32738772)
Well if RCE is possible, then why is it going to matter if you have uncalled vulnerable functions or not? Attacker can execute anything they want.
Re:Vulnerability Management for Go by Someone on Tuesday September 06, 2022 @11:59AM (#32738954)
Not necessarily. RCE may start with being able to run ‘something’ that has restrictions such as “can’t inject code that has zero bytes in it” or “injected code can only be X bytes long”.

In such cases, having another vulnerability available may be the easiest way to get rid of those restrictions.

Also, the second vulnerability may be complementary. For example, the first may get you onto the machine, but not out of the sandbox, while the second won’t get you on the machine, but will get you out of the sandbox.

In this case, I think the go linker won’t include the never-called vulnerable function in the executable (it only would if the vulnerability checker were smarter than the linker in detecting never-called code. That’s theoretically possible, but highly unlikely)

Re:Vulnerability Management for Go by goodpoint on Tuesday September 06, 2022 @12:26PM (#32739396)
If only it was language-independent I would consider it.

Reinventing supply chain and vulnerability management for each language... not a good use of our time.

Re:Vulnerability Management for Go by psanford on Tuesday September 06, 2022 @12:52PM (#32739784)
Strong disagree.

Every "generic" vulnerability scanner still needs some language specific knowledge for how to determine what is an included dependency. The better you want to suppress false positives, the more in-depth knowledge the tool will need about each language/runtime.

The end result of this is that all the existing generic scanners just use least common denominator heuristics for determining vulnerable dependencies (i.e. just look at the lock file).

For large teams, this can be a huge waste of time patching vulnerabilities that don't actually apply to your code just because the scanning tool is too stupid to know better.

I'll take Govulncheck (and similar tools for other languages) any day over the mediocre generic tools.

Re:Vulnerability Management for Go by goodpoint on Wednesday September 07, 2022 @10:01AM (#32750760)
> The end result of this is that all the existing generic scanners just use least common denominator heuristics

Wrong. You can have specialized backends and language-agnostic everything-else.

Re:Vulnerability Management for Go by klysm on Tuesday September 06, 2022 @12:46PM (#32739694)
It doesn't seem possible to implement that in a language agnostic way. How do you propose doing such a thing?
Re:Vulnerability Management for Go by goodpoint on Wednesday September 07, 2022 @09:58AM (#32750729)
Very simple: implement language-specific static analysis backends and a general frontend and vuln management.

Just like every Linux distribution does distributes packages and manages security in a language-agnostic way. Nothing new.

Amazing how people here dismissed my point by downvoting and providing no reasoning.

Re:Vulnerability Management for Go by klysm on Wednesday September 07, 2022 @10:57AM (#32751497)
> language-specific static backends

I guess it sounded like you meant a general solution that wasn’t language specific. I’m still not sure if there’s an abstraction you could use to make language aspects marked as vulnerable - the semantics between languages are just so varied.

Anyway we need the language specific ones first.

Re:Vulnerability Management for Go by goodpoint on Thursday September 08, 2022 @09:22AM (#32765125)
> Anyway we need the language specific ones first.

No, we have language-agnostic vuln management since decades and a good tool could use a fall back to the traditional method when a language-specific backend is not available.

Re:Vulnerability Management for Go by klysm on Thursday September 08, 2022 @03:44PM (#32771015)
I mean language agnostic vuln management that’s capable of marking a particular subset of functionality as vulnerable like this is.
Re:Vulnerability Management for Go by teraflop on Tuesday September 06, 2022 @01:36PM (#32740359)
Let's train a neural network to take source code in an arbitrary language as input, and produce a call graph as output. What could go wrong?
Re:Vulnerability Management for Go by klysm on Tuesday September 06, 2022 @03:59PM (#32742448)
Side-note: how do you make a nn output a graph topology? I'm having a hard time imagining how to make a matrix represent that.
Re:Vulnerability Management for Go by haneefmubarak on Tuesday September 06, 2022 @04:20PM (#32742696)
Graph Neural Networks! https://distill.pub/2021/gnn-intro/

In a nutshell, you perform NN operations on the nodes and edges of the graph and then send updates across the graph

Re:Vulnerability Management for Go by tgv on Tuesday September 06, 2022 @02:12PM (#32740861)
And then clamp the output to generate vulnerabilities? Could be worth a shot.
Re:Vulnerability Management for Go by throwaway894345 on Tuesday September 06, 2022 @01:10PM (#32740022)
Until we can figure out how to translate semantics across languages, we have to reinvent almost everything for each language. We can abstract out some things, but not others. As far as "a good use of our time", the alternative is "no vulnerability scanning" or "package level vulnerability scanning" which probably waste more time or expose more risk for most organizations.
Re:Vulnerability Management for Go by politician on Tuesday September 06, 2022 @12:43PM (#32739653)
Is it even technically possible to do (edit: useful) vulnerability analysis in a pure black box configuration?
Re:Vulnerability Management for Go by a1369209993 on Tuesday September 06, 2022 @11:18PM (#32745977)
Sure: it's called "fuzz testing".