Skip to content

Commit

Permalink
fix: improve node classifier version matching (#3284)
Browse files Browse the repository at this point in the history
Signed-off-by: witchcraze <witchcraze@gmail.com>
  • Loading branch information
witchcraze authored Sep 27, 2024
1 parent 1a746b2 commit 2a3d171
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
30 changes: 30 additions & 0 deletions syft/pkg/cataloger/binary/classifier_cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,36 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("go-binary"),
},
},
{
logicalFixture: "node/0.10.48/linux-amd64",
expected: pkg.Package{
Name: "node",
Version: "0.10.48",
PURL: "pkg:generic/node@0.10.48",
Locations: locations("node"),
Metadata: metadata("nodejs-binary"),
},
},
{
logicalFixture: "node/0.12.18/linux-amd64",
expected: pkg.Package{
Name: "node",
Version: "0.12.18",
PURL: "pkg:generic/node@0.12.18",
Locations: locations("node"),
Metadata: metadata("nodejs-binary"),
},
},
{
logicalFixture: "node/4.9.1/linux-amd64",
expected: pkg.Package{
Name: "node",
Version: "4.9.1",
PURL: "pkg:generic/node@4.9.1",
Locations: locations("node"),
Metadata: metadata("nodejs-binary"),
},
},
{
logicalFixture: "node/19.2.0/linux-amd64",
expected: pkg.Package{
Expand Down
10 changes: 8 additions & 2 deletions syft/pkg/cataloger/binary/classifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,14 @@ func DefaultClassifiers() []Classifier {
{
Class: "nodejs-binary",
FileGlob: "**/node",
EvidenceMatcher: FileContentsVersionMatcher(
`(?m)node\.js\/v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
EvidenceMatcher: evidenceMatchers(
// [NUL]node v0.10.48[NUL]
// [NUL]v0.12.18[NUL]
// [NUL]v4.9.1[NUL]
// node.js/v22.9.0
FileContentsVersionMatcher(`(?m)\x00(node )?v(?P<version>(0|4|5)\.[0-9]+\.[0-9]+)\x00`),
FileContentsVersionMatcher(`(?m)node\.js\/v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
),
Package: "node",
PURL: mustPURL("pkg:generic/node@version"),
CPEs: singleCPE("cpe:2.3:a:nodejs:node.js:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions syft/pkg/cataloger/binary/test-fixtures/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ from-images:
paths:
- /usr/local/openresty/nginx/sbin/nginx

- version: 0.10.48
images:
- ref: node:0.10.48@sha256:c32b4d56f05c69df6e87d06bf7d5f6a5c6a0e7bcdb8e5ffab0e7a1853a90008f
platform: linux/amd64
paths:
- /usr/local/bin/node

- version: 0.12.18
images:
- ref: node:0.12.18@sha256:02e8e9903c8d974e8874d0144413d398a41d62f54bafec4d2cf3ac2a8501dd28
platform: linux/amd64
paths:
- /usr/local/bin/node

- version: 4.9.1
images:
- ref: node:4.9.1@sha256:41d0ad2557ea2a9e57e1a458c1d659e92f601586e07dcffef74c9cef542f6f6e
platform: linux/amd64
paths:
- /usr/local/bin/node

- version: 19.2.0
images:
- ref: node:19.2.0@sha256:9bf5846b28f63acab0ccb0a39a245fbc414e6b7ecd467282f58016537c06e159
Expand Down

0 comments on commit 2a3d171

Please sign in to comment.