fix: improve node classifier version matching (#3284)

Signed-off-by: witchcraze <witchcraze@gmail.com>
This commit is contained in:
witchcraze 2024-09-27 21:53:35 +09:00 committed by GitHub
parent 1a746b2c05
commit 2a3d171c10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 59 additions and 2 deletions

View File

@ -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{

View File

@ -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),

View File

@ -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