Adding CPE support for different Jetbrains IDEA and PyCharm app names. (#14806)

Adding vulnerability data support for JetBrains applications (like IDEA,
PyCharm, etc.) that have similar names.
- For example: IntelliJ IDEA.app and IntelliJ IDEA Ultimate.app

Resolves #13889 

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Victor Lyuboslavsky 2023-10-31 16:18:24 -05:00 committed by GitHub
parent 19f897984d
commit 160755ad1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,2 @@
Adding vulnerability data support for JetBrains applications (like IDEA, PyCharm, etc.) that have similar names.
- For example: IntelliJ IDEA.app and IntelliJ IDEA Ultimate.app

View File

@ -114,6 +114,9 @@ func DownloadCPEDBFromGithub(vulnPath string, cpeDBURL string) error {
return nil
}
// cpeGeneralSearchQuery puts together several search statements to find the correct row in the CPE datastore.
// Each statement has a custom weight column, where 1 is the highest priority (most likely to be correct).
// The SQL statements are combined into a master statements with UNION.
func cpeGeneralSearchQuery(software *fleet.Software) (string, []interface{}, error) {
dialect := goqu.Dialect("sqlite")
@ -147,6 +150,17 @@ func cpeGeneralSearchQuery(software *fleet.Software) (string, []interface{}, err
datasets := []*goqu.SelectDataset{search1, search2, search3}
// 4 - Try vendor/product from bundle identifier, like tld.vendor.product
bundleParts := strings.Split(software.BundleIdentifier, ".")
if len(bundleParts) >= 3 {
search4 := dialect.From(goqu.I("cpe_2").As("c")).
Select("c.rowid", "c.product", "c.vendor", "c.deprecated", goqu.L("4 as weight")).
Where(
goqu.Or(goqu.L("c.vendor = ?", strings.ToLower(bundleParts[1]))), goqu.L("c.product = ?", strings.ToLower(bundleParts[2])),
)
datasets = append(datasets, search4)
}
var sqlParts []string
var args []interface{}
var stm string

View File

@ -1290,6 +1290,46 @@ func TestCPEFromSoftwareIntegration(t *testing.T) {
Version: "6.0.1",
}, cpe: "",
},
{
software: fleet.Software{
Name: "IntelliJ IDEA.app",
Source: "apps",
Version: "2022.3.3",
Vendor: "",
BundleIdentifier: "com.jetbrains.intellij",
},
cpe: "cpe:2.3:a:jetbrains:intellij_idea:2022.3.3:*:*:*:*:macos:*:*",
},
{
software: fleet.Software{
Name: "IntelliJ IDEA CE.app",
Source: "apps",
Version: "2022.3.3",
Vendor: "",
BundleIdentifier: "com.jetbrains.intellij.ce",
},
cpe: "cpe:2.3:a:jetbrains:intellij_idea:2022.3.3:*:*:*:*:macos:*:*",
},
{
software: fleet.Software{
Name: "User PyCharm Custom Name.app", // 2023/10/31: The actual product name must be part of the app name per our code in CPEFromSoftware
Source: "apps",
Version: "2019.2",
Vendor: "",
BundleIdentifier: "com.jetbrains.pycharm",
},
cpe: "cpe:2.3:a:jetbrains:pycharm:2019.2:*:*:*:*:macos:*:*",
},
{
software: fleet.Software{
Name: "PyCharm Community Edition.app",
Source: "apps",
Version: "2022.1",
Vendor: "",
BundleIdentifier: "com.jetbrains.pycharm.ce",
},
cpe: "cpe:2.3:a:jetbrains:pycharm:2022.1:*:*:*:*:macos:*:*",
},
}
tempDir := t.TempDir()

View File

@ -119,5 +119,15 @@
"product": ["flock"],
"vendor": ["flock"]
}
},
{
"software": {
"bundle_identifier": ["/^com\\.jetbrains\\.intellij/"],
"source": ["apps"]
},
"filter": {
"product": ["intellij_idea"],
"vendor": ["jetbrains"]
}
}
]