Skip to content
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

Fix Sarif output driver issues and Xray Sca locations #968

Merged
merged 34 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
de990d2
Fix Sarif output driver issues and Xray Sca locations
attiasas Sep 19, 2023
53e747f
Fix Sarif output driver issues
attiasas Sep 19, 2023
2ecc294
Fix bug
attiasas Sep 19, 2023
d26ce78
rename SCA
attiasas Sep 19, 2023
f97e80c
merge dev
attiasas Sep 19, 2023
4cac214
add specific uri
attiasas Sep 20, 2023
d6632a2
merge dev
attiasas Sep 20, 2023
79037ef
reposition override
attiasas Sep 20, 2023
46ad98f
reposition override
attiasas Sep 20, 2023
954d9c9
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
attiasas Sep 26, 2023
1d97508
add test
attiasas Sep 26, 2023
f50acfb
update information uri
attiasas Sep 26, 2023
c6f29dd
split sarifutils and move test funcs
attiasas Sep 26, 2023
cb563be
fix for windows
attiasas Sep 26, 2023
6065ccf
Remove Sast support check
attiasas Sep 26, 2023
0782ab9
review changes
attiasas Sep 26, 2023
11049cb
fix tests
attiasas Sep 26, 2023
57e71bd
fix tests
attiasas Sep 26, 2023
a49e5a4
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
attiasas Sep 27, 2023
df406b2
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
attiasas Oct 1, 2023
df8398f
fix review
attiasas Oct 2, 2023
7d209d5
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
attiasas Oct 2, 2023
a2deb81
format
attiasas Oct 2, 2023
998e7ac
fix test
attiasas Oct 2, 2023
0b5f0c4
fix tests
attiasas Oct 2, 2023
7d4a59b
remove trim
attiasas Oct 2, 2023
2ebdb0c
review changes
attiasas Oct 2, 2023
9ff4e71
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
attiasas Oct 2, 2023
15ad8d2
done changes
attiasas Oct 3, 2023
5c7d21a
format
attiasas Oct 3, 2023
d2e55bc
fix tests
attiasas Oct 3, 2023
2aed015
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
attiasas Oct 3, 2023
306e9f3
cleanup
attiasas Oct 3, 2023
719a5e8
add test
attiasas Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions utils/coreutils/techutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type TechData struct {
// Whether Contextual Analysis supported in this technology.
applicabilityScannable bool
// The file that handles the project's dependencies.
attiasas marked this conversation as resolved.
Show resolved Hide resolved
packageDescriptor string
packageDescriptor []string
attiasas marked this conversation as resolved.
Show resolved Hide resolved
// Formal name of the technology
formal string
// The executable name of the technology
Expand All @@ -60,48 +60,49 @@ var technologiesData = map[Technology]TechData{
Maven: {
indicators: []string{"pom.xml"},
ciSetupSupport: true,
packageDescriptor: "pom.xml",
packageDescriptor: []string{"pom.xml"},
execCommand: "mvn",
applicabilityScannable: true,
},
Gradle: {
indicators: []string{".gradle", ".gradle.kts"},
ciSetupSupport: true,
packageDescriptor: "build.gradle, build.gradle.kts",
packageDescriptor: []string{"build.gradle", "build.gradle.kts"},
applicabilityScannable: true,
},
Npm: {
indicators: []string{"package.json", "package-lock.json", "npm-shrinkwrap.json"},
exclude: []string{".yarnrc.yml", "yarn.lock", ".yarn"},
ciSetupSupport: true,
packageDescriptor: "package.json",
packageDescriptor: []string{"package.json"},
formal: string(Npm),
packageVersionOperator: "@",
packageInstallationCommand: "install",
applicabilityScannable: true,
},
Yarn: {
indicators: []string{".yarnrc.yml", "yarn.lock", ".yarn"},
packageDescriptor: "package.json",
packageDescriptor: []string{"package.json"},
packageVersionOperator: "@",
applicabilityScannable: true,
},
Go: {
indicators: []string{"go.mod"},
packageDescriptor: "go.mod",
packageDescriptor: []string{"go.mod"},
packageVersionOperator: "@v",
packageInstallationCommand: "get",
},
Pip: {
packageType: Pypi,
indicators: []string{"setup.py", "requirements.txt"},
packageDescriptor: []string{"setup.py", "requirements.txt"},
exclude: []string{"Pipfile", "Pipfile.lock", "pyproject.toml", "poetry.lock"},
applicabilityScannable: true,
},
Pipenv: {
packageType: Pypi,
indicators: []string{"Pipfile", "Pipfile.lock"},
packageDescriptor: "Pipfile",
packageDescriptor: []string{"Pipfile"},
packageVersionOperator: "==",
packageInstallationCommand: "install",
applicabilityScannable: true,
Expand Down Expand Up @@ -153,10 +154,7 @@ func (tech Technology) GetPackageType() string {
return technologiesData[tech].packageType
}

func (tech Technology) GetPackageDescriptor() string {
if technologiesData[tech].packageDescriptor == "" {
return tech.ToFormal() + " Package Descriptor"
}
func (tech Technology) GetPackageDescriptor() []string {
return technologiesData[tech].packageDescriptor
}

Expand Down
7 changes: 4 additions & 3 deletions xray/commands/audit/jas/applicability/applicabilitymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

const (
applicabilityScanType = "analyze-applicability"
applicabilityScanCommand = "ca"
applicabilityScanType = "analyze-applicability"
applicabilityScanCommand = "ca"
applicabilityDocsUrlSuffix = "contextual-analysis"
)

type ApplicabilityScanManager struct {
Expand Down Expand Up @@ -116,7 +117,7 @@ func (asm *ApplicabilityScanManager) Run(module jfrogappsconfig.Module) (err err
if err = asm.runAnalyzerManager(); err != nil {
return
}
workingDirResults, err := jas.ReadJasScanRunsFromFile(asm.scanner.ResultsFileName, module.SourceRoot)
workingDirResults, err := jas.ReadJasScanRunsFromFile(asm.scanner.ResultsFileName, module.SourceRoot, applicabilityDocsUrlSuffix)
if err != nil {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestParseResults_EmptyResults_AllCvesShouldGetUnknown(t *testing.T) {

// Act
var err error
applicabilityManager.applicabilityScanResults, err = jas.ReadJasScanRunsFromFile(applicabilityManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
applicabilityManager.applicabilityScanResults, err = jas.ReadJasScanRunsFromFile(applicabilityManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, applicabilityDocsUrlSuffix)

if assert.NoError(t, err) {
assert.Len(t, applicabilityManager.applicabilityScanResults, 1)
Expand All @@ -299,7 +299,7 @@ func TestParseResults_ApplicableCveExist(t *testing.T) {

// Act
var err error
applicabilityManager.applicabilityScanResults, err = jas.ReadJasScanRunsFromFile(applicabilityManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
applicabilityManager.applicabilityScanResults, err = jas.ReadJasScanRunsFromFile(applicabilityManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, applicabilityDocsUrlSuffix)

if assert.NoError(t, err) && assert.NotNil(t, applicabilityManager.applicabilityScanResults) {
assert.Len(t, applicabilityManager.applicabilityScanResults, 1)
Expand All @@ -316,7 +316,7 @@ func TestParseResults_AllCvesNotApplicable(t *testing.T) {

// Act
var err error
applicabilityManager.applicabilityScanResults, err = jas.ReadJasScanRunsFromFile(applicabilityManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
applicabilityManager.applicabilityScanResults, err = jas.ReadJasScanRunsFromFile(applicabilityManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, applicabilityDocsUrlSuffix)

if assert.NoError(t, err) && assert.NotNil(t, applicabilityManager.applicabilityScanResults) {
assert.Len(t, applicabilityManager.applicabilityScanResults, 1)
Expand Down
22 changes: 21 additions & 1 deletion xray/commands/audit/jas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"testing"
"unicode"

jfrogappsconfig "github.com/jfrog/jfrog-apps-config/go"
rtutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
Expand Down Expand Up @@ -127,7 +128,7 @@ func deleteJasProcessFiles(configFile string, resultFile string) error {
return errorutils.CheckError(err)
}

func ReadJasScanRunsFromFile(fileName, wd string) (sarifRuns []*sarif.Run, err error) {
func ReadJasScanRunsFromFile(fileName, wd, informationUrlSuffix string) (sarifRuns []*sarif.Run, err error) {
if sarifRuns, err = utils.ReadScanRunsFromFile(fileName); err != nil {
return
}
Expand All @@ -137,12 +138,31 @@ func ReadJasScanRunsFromFile(fileName, wd string) (sarifRuns []*sarif.Run, err e
// Also used to calculate relative paths if needed with it
sarifRun.Invocations[0].WorkingDirectory.WithUri(wd)
// Process runs values
fillMissingRequiredDriverInformation(utils.BaseDocumentationURL+informationUrlSuffix, utils.GetAnalyzerManagerVersion(), sarifRun)
sarifRun.Results = excludeSuppressResults(sarifRun.Results)
addScoreToRunRules(sarifRun)
}
return
}

func fillMissingRequiredDriverInformation(defaultJasInformationUri, defaultVersion string, run *sarif.Run) {
driver := run.Tool.Driver
if driver.InformationURI == nil {
driver.InformationURI = &defaultJasInformationUri
}
if driver.Version == nil || !isValidVersion(*driver.Version) {
driver.Version = &defaultVersion
}
}

func isValidVersion(version string) bool {
if len(version) == 0 {
return false
}
firstChar := rune(version[0])
return unicode.IsDigit(firstChar)
}

func excludeSuppressResults(sarifResults []*sarif.Result) []*sarif.Result {
results := []*sarif.Result{}
for _, sarifResult := range sarifResults {
Expand Down
2 changes: 1 addition & 1 deletion xray/commands/audit/jas/commons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ func TestGetExcludePatterns(t *testing.T) {
assert.ElementsMatch(t, actualExcludePatterns, expectedExcludePatterns)
})
}
}
}
7 changes: 4 additions & 3 deletions xray/commands/audit/jas/iac/iacscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

const (
iacScannerType = "iac-scan-modules"
iacScanCommand = "iac"
iacScannerType = "iac-scan-modules"
iacScanCommand = "iac"
iacDocsUrlSuffix = "infrastructure-as-code-iac"
)

type IacScanManager struct {
Expand Down Expand Up @@ -60,7 +61,7 @@ func (iac *IacScanManager) Run(module jfrogappsconfig.Module) (err error) {
if err = iac.runAnalyzerManager(); err != nil {
return
}
workingDirResults, err := jas.ReadJasScanRunsFromFile(iac.scanner.ResultsFileName, module.SourceRoot)
workingDirResults, err := jas.ReadJasScanRunsFromFile(iac.scanner.ResultsFileName, module.SourceRoot, iacDocsUrlSuffix)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions xray/commands/audit/jas/iac/iacscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestIacParseResults_EmptyResults(t *testing.T) {

// Act
var err error
iacScanManager.iacScannerResults, err = jas.ReadJasScanRunsFromFile(iacScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
iacScanManager.iacScannerResults, err = jas.ReadJasScanRunsFromFile(iacScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, iacDocsUrlSuffix)
if assert.NoError(t, err) && assert.NotNil(t, iacScanManager.iacScannerResults) {
assert.Len(t, iacScanManager.iacScannerResults, 1)
assert.Empty(t, iacScanManager.iacScannerResults[0].Results)
Expand All @@ -75,7 +75,7 @@ func TestIacParseResults_ResultsContainIacViolations(t *testing.T) {

// Act
var err error
iacScanManager.iacScannerResults, err = jas.ReadJasScanRunsFromFile(iacScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
iacScanManager.iacScannerResults, err = jas.ReadJasScanRunsFromFile(iacScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, iacDocsUrlSuffix)
if assert.NoError(t, err) && assert.NotNil(t, iacScanManager.iacScannerResults) {
assert.Len(t, iacScanManager.iacScannerResults, 1)
assert.Len(t, iacScanManager.iacScannerResults[0].Results, 4)
Expand Down
7 changes: 4 additions & 3 deletions xray/commands/audit/jas/sast/sastscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

const (
sastScannerType = "sast"
sastScanCommand = "zd"
sastScannerType = "sast"
sastScanCommand = "zd"
sastDocsUrlSuffix = "sast"
)

type SastScanManager struct {
Expand Down Expand Up @@ -55,7 +56,7 @@ func (ssm *SastScanManager) Run(module jfrogappsconfig.Module) (err error) {
if err = ssm.runAnalyzerManager(filepath.Dir(ssm.scanner.AnalyzerManager.AnalyzerManagerFullPath)); err != nil {
return
}
workingDirRuns, err := jas.ReadJasScanRunsFromFile(scanner.ResultsFileName, module.SourceRoot)
workingDirRuns, err := jas.ReadJasScanRunsFromFile(scanner.ResultsFileName, module.SourceRoot, sastDocsUrlSuffix)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions xray/commands/audit/jas/sast/sastscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestSastParseResults_EmptyResults(t *testing.T) {

// Act
var err error
sastScanManager.sastScannerResults, err = jas.ReadJasScanRunsFromFile(sastScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
sastScanManager.sastScannerResults, err = jas.ReadJasScanRunsFromFile(sastScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, sastDocsUrlSuffix)

// Assert
if assert.NoError(t, err) && assert.NotNil(t, sastScanManager.sastScannerResults) {
Expand All @@ -57,7 +57,7 @@ func TestSastParseResults_ResultsContainIacViolations(t *testing.T) {

// Act
var err error
sastScanManager.sastScannerResults, err = jas.ReadJasScanRunsFromFile(sastScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
sastScanManager.sastScannerResults, err = jas.ReadJasScanRunsFromFile(sastScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, sastDocsUrlSuffix)

// Assert
if assert.NoError(t, err) && assert.NotNil(t, sastScanManager.sastScannerResults) {
Expand Down
7 changes: 4 additions & 3 deletions xray/commands/audit/jas/secrets/secretsscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

const (
secretsScanCommand = "sec"
secretsScannerType = "secrets-scan"
secretsScanCommand = "sec"
secretsScannerType = "secrets-scan"
secretsDocsUrlSuffix = "secrets"
)

type SecretScanManager struct {
Expand Down Expand Up @@ -59,7 +60,7 @@ func (ssm *SecretScanManager) Run(module jfrogappsconfig.Module) (err error) {
if err = ssm.runAnalyzerManager(); err != nil {
return
}
workingDirRuns, err := jas.ReadJasScanRunsFromFile(ssm.scanner.ResultsFileName, module.SourceRoot)
workingDirRuns, err := jas.ReadJasScanRunsFromFile(ssm.scanner.ResultsFileName, module.SourceRoot, secretsDocsUrlSuffix)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions xray/commands/audit/jas/secrets/secretsscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestParseResults_EmptyResults(t *testing.T) {

// Act
var err error
secretScanManager.secretsScannerResults, err = jas.ReadJasScanRunsFromFile(secretScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
secretScanManager.secretsScannerResults, err = jas.ReadJasScanRunsFromFile(secretScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, secretsDocsUrlSuffix)

// Assert
if assert.NoError(t, err) && assert.NotNil(t, secretScanManager.secretsScannerResults) {
Expand All @@ -89,7 +89,7 @@ func TestParseResults_ResultsContainSecrets(t *testing.T) {

// Act
var err error
secretScanManager.secretsScannerResults, err = jas.ReadJasScanRunsFromFile(secretScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot)
secretScanManager.secretsScannerResults, err = jas.ReadJasScanRunsFromFile(secretScanManager.scanner.ResultsFileName, scanner.JFrogAppsConfig.Modules[0].SourceRoot, secretsDocsUrlSuffix)

// Assert
if assert.NoError(t, err) && assert.NotNil(t, secretScanManager.secretsScannerResults) {
Expand Down
3 changes: 0 additions & 3 deletions xray/commands/audit/jasrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func runJasScannersAndSetResults(scanResults *utils.ExtendedScanResults, directD
if err != nil {
return
}
if !utils.IsSastSupported() {
return
}
if progress != nil {
progress.SetHeadlineMsg("Running SAST scanning")
}
Expand Down
6 changes: 0 additions & 6 deletions xray/utils/analyzermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"errors"
"fmt"
"github.com/jfrog/gofrog/version"
"os"
"os/exec"
"path"
Expand All @@ -24,7 +23,6 @@ const (
ApplicabilityFeatureId = "contextual_analysis"
AnalyzerManagerZipName = "analyzerManager.zip"
defaultAnalyzerManagerVersion = "1.3.2.2019257"
minAnalyzerManagerVersionForSast = "1.3"
analyzerManagerDownloadPath = "xsc-gen-exe-analyzer-manager-local/v1"
analyzerManagerDirName = "analyzerManager"
analyzerManagerExecutableName = "analyzerManager"
Expand Down Expand Up @@ -150,10 +148,6 @@ func GetAnalyzerManagerVersion() string {
return defaultAnalyzerManagerVersion
}

func IsSastSupported() bool {
return version.NewVersion(GetAnalyzerManagerVersion()).AtLeast(minAnalyzerManagerVersionForSast)
}

func GetAnalyzerManagerDirAbsolutePath() (string, error) {
jfrogDir, err := config.GetJfrogDependenciesPath()
if err != nil {
Expand Down
Loading
Loading