-
Notifications
You must be signed in to change notification settings - Fork 884
added electron cataloger & bin classifier #4679
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -913,6 +913,52 @@ func DefaultClassifiers() []binutils.Classifier { | |
| PURL: mustPURL("pkg:generic/chrome@version"), | ||
| CPEs: singleCPE("cpe:2.3:a:google:chrome:*:*:*:*:*:*:*:*"), | ||
| }, | ||
| { | ||
| Class: "electron-binary-macos", | ||
| FileGlob: "**/Electron Framework", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are electron apps frequently named |
||
| EvidenceMatcher: m.FileContentsVersionMatcher( | ||
| // Electron/28.0.0 pattern found in Electron framework binaries | ||
| `Electron/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`), | ||
| Package: "electron", | ||
| PURL: mustPURL("pkg:generic/electron@version"), | ||
| CPEs: singleCPE("cpe:2.3:a:electronjs:electron:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource), | ||
| }, | ||
| { | ||
| Class: "electron-binary", | ||
| FileGlob: "**/electron", | ||
| EvidenceMatcher: binutils.MatchAll( | ||
| // Match both Electron and Chrome version patterns to confirm it's Electron | ||
| m.FileContentsVersionMatcher(`Electron/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`), | ||
| m.FileContentsVersionMatcher(`Chrome/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+`), | ||
| ), | ||
| Package: "electron", | ||
| PURL: mustPURL("pkg:generic/electron@version"), | ||
| CPEs: singleCPE("cpe:2.3:a:electronjs:electron:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource), | ||
| }, | ||
| { | ||
| // VS Code and other Electron apps on Linux that rename the binary to "code" | ||
| Class: "electron-binary-renamed-linux", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably be called something like |
||
| FileGlob: "**/code", | ||
| EvidenceMatcher: binutils.MatchAll( | ||
| m.FileContentsVersionMatcher(`Electron/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`), | ||
| m.FileContentsVersionMatcher(`Chrome/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+`), | ||
| ), | ||
| Package: "electron", | ||
| PURL: mustPURL("pkg:generic/electron@version"), | ||
| CPEs: singleCPE("cpe:2.3:a:electronjs:electron:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource), | ||
| }, | ||
| { | ||
| // VS Code and other Electron apps on Windows (Code.exe) | ||
| Class: "electron-binary-renamed-windows", | ||
| FileGlob: "**/Code.exe", | ||
| EvidenceMatcher: binutils.MatchAll( | ||
| m.FileContentsVersionMatcher(`Electron/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`), | ||
| m.FileContentsVersionMatcher(`Chrome/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+`), | ||
| ), | ||
| Package: "electron", | ||
| PURL: mustPURL("pkg:generic/electron@version"), | ||
| CPEs: singleCPE("cpe:2.3:a:electronjs:electron:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource), | ||
| }, | ||
| { | ||
| Class: "ffmpeg-binary", | ||
| FileGlob: "**/ffmpeg", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Cataloger capabilities. See ../README.md for documentation. | ||
|
|
||
| catalogers: | ||
| - ecosystem: javascript # MANUAL | ||
| name: electron-cataloger # AUTO-GENERATED | ||
| type: generic # AUTO-GENERATED | ||
| source: # AUTO-GENERATED | ||
| file: syft/pkg/cataloger/electron/cataloger.go | ||
| function: NewCataloger | ||
| selectors: # AUTO-GENERATED | ||
| - asar | ||
| - directory | ||
| - electron | ||
| - image | ||
| - javascript | ||
| - language | ||
| - package | ||
| parsers: # AUTO-GENERATED structure | ||
| - function: parsePackageJSON | ||
| detector: # AUTO-GENERATED | ||
| method: glob # AUTO-GENERATED | ||
| criteria: # AUTO-GENERATED | ||
| - '**/Contents/Resources/app/node_modules/*/package.json' | ||
| - '**/Contents/Resources/app/node_modules/*/*/package.json' | ||
| - '**/Contents/Resources/app/node_modules/*/*/*/package.json' | ||
| - '**/resources/app/node_modules/*/package.json' | ||
| - '**/resources/app/node_modules/*/*/package.json' | ||
| - '**/resources/app/node_modules/*/*/*/package.json' | ||
| capabilities: # MANUAL - preserved across regeneration | ||
| - name: license | ||
| default: true | ||
| - name: dependency.depth | ||
| default: | ||
| - direct | ||
| - indirect | ||
| - name: dependency.edges | ||
| default: "" | ||
| - name: dependency.kinds | ||
| default: | ||
| - runtime | ||
| - name: package_manager.files.listing | ||
| default: false | ||
| - name: package_manager.files.digests | ||
| default: false | ||
| - name: package_manager.package_integrity_hash | ||
| default: false | ||
| - function: parseAsarArchive | ||
| detector: # AUTO-GENERATED | ||
| method: glob # AUTO-GENERATED | ||
| criteria: # AUTO-GENERATED | ||
| - '**/app.asar' | ||
| - '**/Contents/Resources/app.asar' | ||
| - '**/Contents/Resources/electron.asar' | ||
| - '**/Contents/Resources/app/node_modules.asar' | ||
| - '**/resources/app.asar' | ||
| - '**/resources/electron.asar' | ||
| - '**/resources/app/node_modules.asar' | ||
| metadata_types: # AUTO-GENERATED | ||
| - pkg.NpmPackage | ||
| package_types: # AUTO-GENERATED | ||
| - npm | ||
| purl_types: # AUTO-GENERATED | ||
| - npm | ||
| json_schema_types: # AUTO-GENERATED | ||
| - JavascriptNpmPackage | ||
| capabilities: # MANUAL - preserved across regeneration | ||
| - name: license | ||
| default: true | ||
| - name: dependency.depth | ||
| default: | ||
| - direct | ||
| - indirect | ||
| - name: dependency.edges | ||
| default: "" | ||
| - name: dependency.kinds | ||
| default: | ||
| - runtime | ||
| - name: package_manager.files.listing | ||
| default: false | ||
| - name: package_manager.files.digests | ||
| default: false | ||
| - name: package_manager.package_integrity_hash | ||
| default: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package electron | ||
|
|
||
| import ( | ||
| "github.com/anchore/syft/syft/pkg" | ||
| "github.com/anchore/syft/syft/pkg/cataloger/generic" | ||
| ) | ||
|
|
||
| const catalogerName = "electron-cataloger" | ||
|
|
||
| // NewCataloger returns a cataloger for packaged Electron apps. | ||
| func NewCataloger() pkg.Cataloger { | ||
| return generic.NewCataloger(catalogerName). | ||
| WithParserByGlobs(parseAsarArchive, | ||
| "**/app.asar", | ||
| "**/Contents/Resources/app.asar", // macOS | ||
| "**/Contents/Resources/electron.asar", // macOS alt | ||
| "**/Contents/Resources/app/node_modules.asar", // macOS VS Code style | ||
| "**/resources/app.asar", // Linux/Win | ||
| "**/resources/electron.asar", // Linux/Win alt | ||
| "**/resources/app/node_modules.asar", // Linux/Win VS Code style | ||
| ). | ||
| WithParserByGlobs(parsePackageJSON, | ||
| "**/Contents/Resources/app/node_modules/*/package.json", // macOS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these paths would be covered by the package json cataloger, which is not enabled by default for directory scans (I think there is a desire to identify "full OS" scans and use the same catalogers as images, so that could change at some point). But if the package json cataloger is enabled, does this result in duplicate results and we're just deduplicating later? |
||
| "**/Contents/Resources/app/node_modules/*/*/package.json", // macOS scoped | ||
| "**/Contents/Resources/app/node_modules/*/*/*/package.json", // macOS nested | ||
| "**/resources/app/node_modules/*/package.json", // Linux/Win | ||
| "**/resources/app/node_modules/*/*/package.json", // Linux/Win scoped | ||
| "**/resources/app/node_modules/*/*/*/package.json", // Linux/Win nested | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is this change necessary? there's an unfortunate inconsistency here now