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

internal/openvex: add initial support for identifying affected product #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/openvex/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"golang.org/x/vuln/internal/govulncheck"
"golang.org/x/vuln/internal/osv"
"golang.org/x/vuln/internal/semver"
)

type findingLevel int
Expand Down Expand Up @@ -131,7 +132,9 @@ func statements(h *handler) []Statement {
},
Products: []Product{
{
ID: DefaultPID,
ID: fmt.Sprintf("pkg:golang/%s@%s",
osv.Internal.AffectedPath,
semver.RemoveSemverPrefix(osv.Internal.AffectedVersion)),
},
},
}
Expand Down
3 changes: 0 additions & 3 deletions internal/openvex/vex.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const (
Impact = "Govulncheck determined that the vulnerable code isn't called"

DefaultAuthor = "Unknown Author"
DefaultPID = "Unknown Product"

// The following are defined by the VEX standard.
StatusAffected = "affected"
Expand Down Expand Up @@ -102,7 +101,5 @@ type Vulnerability struct {

// Product identifies the products associated with the given vuln.
type Product struct {
// For now, the ID will always be "Unknown product".
// This is temporary and is subject to change.
ID string `json:"@id,omitempty"`
}
12 changes: 12 additions & 0 deletions internal/osv/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ type Entry struct {
// DatabaseSpecific contains additional information about the
// vulnerability, specific to the Go vulnerability database.
DatabaseSpecific *DatabaseSpecific `json:"database_specific,omitempty"`
// Internal contains information internal only to govulncheck that is
// not present in the OSV specification.
Internal Internal
}

// Credit represents a credit for the discovery, confirmation, patch, or
Expand All @@ -238,3 +241,12 @@ type DatabaseSpecific struct {
// The review status of this report (UNREVIEWED or REVIEWED).
ReviewStatus ReviewStatus `json:"review_status,omitempty"`
}

// Internal contains information internal and specific only to govulncheck that
// is not present in the OSV specification.
type Internal struct {
// The affected path (package import) for the OpenVEX products field.
AffectedPath string
// The affected version for the OpenVEX products field.
AffectedVersion string
}
4 changes: 2 additions & 2 deletions internal/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func addSemverPrefix(s string) string {

// removeSemverPrefix removes the 'v' or 'go' prefixes from go-style
// SEMVER strings, for usage in the public vulnerability format.
func removeSemverPrefix(s string) string {
func RemoveSemverPrefix(s string) string {
s = strings.TrimPrefix(s, "v")
s = strings.TrimPrefix(s, "go")
return s
Expand All @@ -36,7 +36,7 @@ func removeSemverPrefix(s string) string {
// Input may be a bare SEMVER ("1.2.3"), Go prefixed SEMVER ("go1.2.3"),
// or already canonical SEMVER ("v1.2.3").
func canonicalizeSemverPrefix(s string) string {
return addSemverPrefix(removeSemverPrefix(s))
return addSemverPrefix(RemoveSemverPrefix(s))
}

// Less returns whether v1 < v2, where v1 and v2 are
Expand Down
8 changes: 8 additions & 0 deletions internal/vulncheck/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import (
func emitOSVs(handler govulncheck.Handler, modVulns []*ModVulns) error {
for _, mv := range modVulns {
for _, v := range mv.Vulns {
// Retrieve the affected path (package) and version for
// the OpenVEX document.
v.Internal.AffectedPath = mv.Module.Path
v.Internal.AffectedVersion = mv.Module.Version
if mv.Module.Replace != nil {
v.Internal.AffectedPath = mv.Module.Replace.Path
v.Internal.AffectedVersion = mv.Module.Replace.Version
}
if err := handler.OSV(v); err != nil {
return err
}
Expand Down