Skip to content
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

Let some people know they can try out newer versions, if we know they aren't bad! #225

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

DarthHater
Copy link
Member

@DarthHater DarthHater commented Apr 13, 2021

It dawned on me that because go list -m -json -u all let's us know the newest version of something, we can run that version past OSS Index and see if it's vulnerable or not. If it's not, let's suggest someone update to it!

This pull request makes the following changes:

  • way too many to count right now, putting this up to start getting feedback!

Of note, this is slower, but it's because go list -m -json -u all is making requests to I assume pkg.go.dev to see what the newest version of a package is

TODO:

  • go through and fix busted tests, add good new ones
  • modify how we pass things around such that we know if someone used dep or go mod, so we can give them the right instructions on how to fix things
  • suggest a go get -u command to users if the dependency is in the go.mod file, and then the replace if the dependency is not in their go.mod file?

This builds the path towards a nancy solve command where we can go ok, you want us to take care of this? We will give it a shot! That command can work with both ossindex and iq, because we should get similar data from IQ, knowing what the recommended version of something is.

Screen Shot 2021-04-12 at 10 50 25 PM

cc @bhamail / @DarthHater

@DarthHater DarthHater requested review from bhamail and zendern April 13, 2021 06:30
@DarthHater DarthHater added enhancement New feature or request reduce-friction labels Apr 13, 2021
@DarthHater DarthHater modified the milestone: v.1.0.0 Apr 13, 2021
Comment on lines +40 to +41
// // fix vulnerability: CVE-2020-15114 in etcd v3.3.13+incompatible
// replace github.com/coreos/etcd => github.com/coreos/etcd v3.3.24+incompatible
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have these commented out for easy local testing of vulnerable dependencies

Comment on lines +43 to +44
// // fix vulnerability: CVE-2021-3121 in github.com/gogo/protobuf v1.2.1
// replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have these commented out for easy local testing of vulnerable dependencies


for _, c := range coordinates {
c.ExcludeVulnerabilities(exclusions)
if exclusions == nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this further up because it seemed odd it would make this AFTER we try using exclusions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the only reason it was down there was b/c if you log it it would not work correctly i believe. So if you passed in nil we wanted it to present to the user as []. Its used in the ExcludeVulnerabilites but range over nil is noop ¯_(ツ)_/¯

https://github.com/sonatype-nexus-community/go-sona-types/blob/b469b94b5ebb013125d69c3524ba5d6f759eede0/ossindex/types/types.go#L103-L107

So really we only do it for presentation. If we can find a better way im cool with it. But moving it up or down doesn't mean much just has to be before the log statement at line 46 hits.

Comment on lines -190 to -199
func splitPackages(entries []types.Coordinate) (nonVulnerable []types.Coordinate, vulnerable []types.Coordinate) {
for _, v := range entries {
if v.IsVulnerable() {
vulnerable = append(vulnerable, v)
} else {
nonVulnerable = append(nonVulnerable, v)
}
}
return
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't even being used, or rather it was, but we already had two lists of data. I removed it because LOL

packages/packages.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bhamail bhamail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems mostly sane to me. Project=Dep and Coordinate stuff gets confusing, but I don't see a clearer path. "Naming" (pronounce like Seinfeld "Newman").

For later discussion (version 2?): When we find a "clean" newer version, is a "replace" directive the best solution to suggest? If we could determine if the dependency is non-transitive (is direct - not indirect), then maybe suggesting a go get -u mydep@v command is better? Probably a lot more trouble, but wanted to ask. In my mind, the problem with adding replace directives is they are a form of technical debt - ideally, you always prefer upgrading to new versions of deps instead. With replace directives, you need to go back "someday" and determine if the directive can be removed in favor of a newer dependency version.

@@ -76,19 +77,19 @@ func logInvalidSemVerWarning(sb *strings.Builder, noColor bool, quiet bool, inva
}
}

func logVulnerablePackage(sb *strings.Builder, noColor bool, coordinate types.Coordinate) {
func logVulnerablePackage(sb *strings.Builder, noColor bool, coordinate types.Projects) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was struggling with the change to types.Projects. Made more sense once I saw how the term is used in the dep code, e.g.: dep.Project - oh yeah, a coordinate really refers to a given "project" that we depend on...Oh the joys of Naming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not attached to this name TBH. The changes in this PR would merit a new major version of Nancy, so if we want to clean up some naming, let's do it!

if err != nil {
return
}

// Wittle down list of audited to vulnerable stuff, so we can work faster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Whittle ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOOD YOU GIVE ME A BREAK!?!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DarthHater
Copy link
Member Author

Seems mostly sane to me. Project=Dep and Coordinate stuff gets confusing, but I don't see a clearer path. "Naming" (pronounce like Seinfeld "Newman").

For later discussion (version 2?): When we find a "clean" newer version, is a "replace" directive the best solution to suggest? If we could determine if the dependency is non-transitive (is direct - not indirect), then maybe suggesting a go get -u mydep@v command is better? Probably a lot more trouble, but wanted to ask. In my mind, the problem with adding replace directives is they are a form of technical debt - ideally, you always prefer upgrading to new versions of deps instead. With replace directives, you need to go back "someday" and determine if the directive can be removed in favor of a newer dependency version.

I absolutely agree with you. What I was THINKING is we can parse go.mod to see if the dependency is in there, and if it is, we can suggest go get -u <dependency>, and if not, suggest the replace. It'd be nice if the go API had the ability to let us see what brought something in (which is slightly possible with go mod graph but it's not maybe the cleanest way of getting things)

What do you think about changing Project to Dependency because that might be clearer?

@bhamail
Copy link
Contributor

bhamail commented Apr 13, 2021

What do you think about changing Project to Dependency because that might be clearer?

Yes, I think that change might ease the cognitive load.

buildVersion := entry.Data["version"].(string)
numVulnerable := len(vulnerableEntries.(map[string]interface{}))
numPackages := len(auditedEntries)

var summaryHeader = []string{"Audited Count", "Vulnerable Count", "Build Version"}
var invalidHeader = []string{"Count", "Package", "Reason"}
var auditedHeader = []string{"Count", "Package", "Is Vulnerable", "Num Vulnerabilities", "Vulnerabilities"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also maybe add these "can be updated" packages to the csv output too?? Maybe a column of "Latest non-vulnerable version" or something like that??

Comment on lines +53 to +54
version = strings.Replace(version, "v", "", -1)
version = strings.Replace(version, "+incompatible", "", -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to strip more here?? +meta, -pre, etc etc.

https://golang.org/ref/mod#versions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I THINK I stripped that version part out for OSS Index, IIRC. I'd have to look further into it.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request reduce-friction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants