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

Show only requested scanners in SARIF format #185

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
32 changes: 19 additions & 13 deletions utils/resultwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (rw *ResultsWriter) PrintScanResults() error {
case format.Json:
return PrintJson(rw.results.GetScaScansXrayResults())
case format.Sarif:
return PrintSarif(rw.results, rw.isMultipleRoots, rw.includeLicenses)
return PrintSarif(rw.results, rw.isMultipleRoots, rw.includeLicenses, rw.subScansPreformed, rw.results.ResultType)
}
return nil
}
Expand All @@ -157,7 +157,7 @@ func (rw *ResultsWriter) printScanResultsTables() (err error) {
printMessage(coreutils.PrintTitle("The full scan results are available here: ") + coreutils.PrintLink(resultsPath))
}
log.Output()
if shouldPrintTable(rw.subScansPreformed, ScaScan, rw.results.ResultType) {
if shouldScannerBeCalled(rw.subScansPreformed, ScaScan, rw.results.ResultType) {
if rw.hasViolationContext {
if err = PrintViolationsTable(violations, rw.results, rw.isMultipleRoots, rw.printExtended); err != nil {
return
Expand All @@ -174,23 +174,23 @@ func (rw *ResultsWriter) printScanResultsTables() (err error) {
}
}
}
if shouldPrintTable(rw.subScansPreformed, SecretsScan, rw.results.ResultType) {
if shouldScannerBeCalled(rw.subScansPreformed, SecretsScan, rw.results.ResultType) {
if err = PrintSecretsTable(rw.results.ExtendedScanResults.SecretsScanResults, rw.results.ExtendedScanResults.EntitledForJas, rw.results.ExtendedScanResults.SecretValidation); err != nil {
return
}
}
if shouldPrintTable(rw.subScansPreformed, IacScan, rw.results.ResultType) {
if shouldScannerBeCalled(rw.subScansPreformed, IacScan, rw.results.ResultType) {
if err = PrintIacTable(rw.results.ExtendedScanResults.IacScanResults, rw.results.ExtendedScanResults.EntitledForJas); err != nil {
return
}
}
if !shouldPrintTable(rw.subScansPreformed, SastScan, rw.results.ResultType) {
if !shouldScannerBeCalled(rw.subScansPreformed, SastScan, rw.results.ResultType) {
return nil
}
return PrintSastTable(rw.results.ExtendedScanResults.SastScanResults, rw.results.ExtendedScanResults.EntitledForJas)
}

func shouldPrintTable(requestedScans []SubScanType, subScan SubScanType, scanType CommandType) bool {
func shouldScannerBeCalled(requestedScans []SubScanType, subScan SubScanType, scanType CommandType) bool {
if scanType.IsTargetBinary() && (subScan == IacScan || subScan == SastScan) {
return false
}
Expand All @@ -210,7 +210,13 @@ func printMessage(message string) {
log.Output("💬" + message)
}

func GenerateSarifReportFromResults(results *Results, isMultipleRoots, includeLicenses bool, allowedLicenses []string) (report *sarif.Report, err error) {
func appendRunsIfRequired(requestedScans []SubScanType, subScan SubScanType, scanType CommandType, results *Results, scanResults []*sarif.Run, report *sarif.Report) {
if shouldScannerBeCalled(requestedScans, subScan, scanType) {
report.Runs = append(report.Runs, patchRunsToPassIngestionRules(subScan, results, scanResults...)...)
}
}
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved

func GenerateSarifReportFromResults(results *Results, isMultipleRoots, includeLicenses bool, allowedLicenses []string, requestedScans []SubScanType, scanType CommandType) (report *sarif.Report, err error) {
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved
report, err = sarifutils.NewReport()
if err != nil {
return
Expand All @@ -220,10 +226,10 @@ func GenerateSarifReportFromResults(results *Results, isMultipleRoots, includeLi
return
}

report.Runs = append(report.Runs, patchRunsToPassIngestionRules(ScaScan, results, xrayRun)...)
report.Runs = append(report.Runs, patchRunsToPassIngestionRules(IacScan, results, results.ExtendedScanResults.IacScanResults...)...)
report.Runs = append(report.Runs, patchRunsToPassIngestionRules(SecretsScan, results, results.ExtendedScanResults.SecretsScanResults...)...)
report.Runs = append(report.Runs, patchRunsToPassIngestionRules(SastScan, results, results.ExtendedScanResults.SastScanResults...)...)
appendRunsIfRequired(requestedScans, ScaScan, scanType, results, []*sarif.Run{xrayRun}, report)
appendRunsIfRequired(requestedScans, IacScan, scanType, results, results.ExtendedScanResults.IacScanResults, report)
appendRunsIfRequired(requestedScans, SecretsScan, scanType, results, results.ExtendedScanResults.SecretsScanResults, report)
appendRunsIfRequired(requestedScans, SastScan, scanType, results, results.ExtendedScanResults.SastScanResults, report)

return
}
Expand Down Expand Up @@ -927,8 +933,8 @@ func PrintJson(output interface{}) error {
return nil
}

func PrintSarif(results *Results, isMultipleRoots, includeLicenses bool) error {
sarifReport, err := GenerateSarifReportFromResults(results, isMultipleRoots, includeLicenses, nil)
func PrintSarif(results *Results, isMultipleRoots, includeLicenses bool, subScans []SubScanType, commandType CommandType) error {
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved
sarifReport, err := GenerateSarifReportFromResults(results, isMultipleRoots, includeLicenses, nil, subScans, commandType)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion utils/securityJobSummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func RecordSarifOutput(cmdResults *Results) (err error) {
log.Info("Results can be uploaded to Github security tab automatically by upgrading your JFrog subscription.")
return
}
sarifReport, err := GenerateSarifReportFromResults(cmdResults, true, false, nil)
sarifReport, err := GenerateSarifReportFromResults(cmdResults, true, false, nil, GetAllSupportedScans(), cmdResults.ResultType)
eyalk007 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
Loading