Skip to content

Commit

Permalink
stop generating wildcard vendors
Browse files Browse the repository at this point in the history
Add logic for parsing javascript and ruby package vendor candidates from
url and author fields and stop generating wildcard vendor candidates

Signed-off-by: Weston Steimel <[email protected]>
  • Loading branch information
westonsteimel committed Mar 3, 2023
1 parent 47b5bb9 commit 52cebc2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
14 changes: 7 additions & 7 deletions syft/pkg/cataloger/common/cpe/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ func candidateVendors(p pkg.Package) []string {
}
}

// some ecosystems do not have enough metadata to determine the vendor accurately, in which case we selectively
// allow * as a candidate. Note: do NOT allow Java packages to have * vendors.
switch p.Language {
case pkg.Ruby, pkg.JavaScript:
vendors.addValue(wfn.Any)
}

switch p.MetadataType {
case pkg.RpmMetadataType:
vendors.union(candidateVendorsForRPM(p))
Expand All @@ -111,8 +104,15 @@ func candidateVendors(p pkg.Package) []string {
vendors.union(candidateVendorsForJava(p))
case pkg.ApkMetadataType:
vendors.union(candidateVendorsForAPK(p))
case pkg.NpmPackageJSONMetadataType:
vendors.union(candidateVendorsForJavascript(p))
}

// We should no longer be generating vendor candidates with these values ["" and "*"]
// (since CPEs will match any other value)
vendors.removeByValue("")
vendors.removeByValue("*")

// try swapping hyphens for underscores, vice versa, and removing separators altogether
addDelimiterVariations(vendors)

Expand Down
32 changes: 32 additions & 0 deletions syft/pkg/cataloger/common/cpe/javascript.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cpe

import "github.com/anchore/syft/syft/pkg"

func candidateVendorsForJavascript(p pkg.Package) fieldCandidateSet {
if p.MetadataType != pkg.NpmPackageJSONMetadataType {
return nil
}

vendors := newFieldCandidateSet()
metadata, ok := p.Metadata.(pkg.NpmPackageJSONMetadata)
if !ok {
return nil
}

if metadata.Author != "" {
vendors.add(fieldCandidate{
value: normalizePersonName(stripEmailSuffix(metadata.Author)),
disallowSubSelections: true,
})
}

if metadata.URL != "" {
vendors.union(candidateVendorsFromURL(metadata.URL))
}

if metadata.Homepage != "" {
vendors.union(candidateVendorsFromURL(metadata.Homepage))
}

return vendors
}
5 changes: 5 additions & 0 deletions syft/pkg/cataloger/common/cpe/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ func candidateVendorsForRuby(p pkg.Package) fieldCandidateSet {
disallowSubSelections: true,
})
}

if metadata.Homepage != "" {
vendors.union(candidateVendorsFromURL(metadata.Homepage))
}

return vendors
}

0 comments on commit 52cebc2

Please sign in to comment.