Skip to content

Commit 1fe6809

Browse files
authored
Merge branch 'main' into mal-code-scanner
2 parents 9da5f8c + 30c2fe0 commit 1fe6809

File tree

17 files changed

+387
-240
lines changed

17 files changed

+387
-240
lines changed

cli/docs/flags.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ const (
5858
Secrets = "secrets"
5959
WithoutCA = "without-contextual-analysis"
6060

61+
auditSca = auditPrefix + Sca
62+
auditIac = auditPrefix + Iac
63+
auditSast = auditPrefix + Sast
64+
auditSecrets = auditPrefix + Secrets
65+
auditWithoutCA = auditPrefix + WithoutCA
66+
binarySca = scanPrefix + Sca
67+
binarySecrets = scanPrefix + Secrets
68+
binaryWithoutCA = scanPrefix + WithoutCA
69+
6170
// Sast related flags
6271
AddSastRules = "add-sast-rules"
6372
)
@@ -162,6 +171,7 @@ var commandFlags = map[string][]string{
162171
XrScan: {
163172
Url, user, password, accessToken, ServerId, SpecFlag, Threads, scanRecursive, scanRegexp, scanAnt,
164173
scanProjectKey, Watches, RepoPath, Licenses, Sbom, OutputFormat, Fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, ScanVuln, InsecureTls,
174+
binarySca, binarySecrets, binaryWithoutCA, SecretValidation,
165175
},
166176
Enrich: {
167177
Url, user, password, accessToken, ServerId, Threads, InsecureTls,
@@ -173,13 +183,14 @@ var commandFlags = map[string][]string{
173183
Url, user, password, accessToken, ServerId, scanProjectKey, BuildVuln, OutputFormat, Fail, ExtendedTable, Rescan, InsecureTls, TriggerScanRetries,
174184
},
175185
DockerScan: {
176-
Url, XrayUrl, user, password, accessToken, ServerId, scanProjectKey, Watches, RepoPath, Licenses, Sbom, OutputFormat, Fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, ScanVuln, SecretValidation, InsecureTls,
186+
Url, XrayUrl, user, password, accessToken, ServerId, scanProjectKey, Watches, RepoPath, Licenses, Sbom, OutputFormat, Fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, ScanVuln, InsecureTls,
187+
binarySca, binarySecrets, binaryWithoutCA, SecretValidation,
177188
},
178189
Audit: {
179190
Url, XrayUrl, user, password, accessToken, ServerId, InsecureTls, scanProjectKey, Watches, RepoPath, Sbom, Licenses, OutputFormat, ExcludeTestDeps,
180191
useWrapperAudit, DepType, RequirementsFile, Fail, ExtendedTable, WorkingDirs, ExclusionsAudit, Mvn, Gradle, Npm,
181192
Pnpm, Yarn, Go, Swift, Cocoapods, Nuget, Pip, Pipenv, Poetry, MinSeverity, FixableOnly, ThirdPartyContextualAnalysis, Threads,
182-
Sca, Iac, Sast, Secrets, WithoutCA, ScanVuln, SecretValidation, OutputDir, SkipAutoInstall, AllowPartialResults, MaxTreeDepth,
193+
auditSca, auditIac, auditSast, auditSecrets, auditWithoutCA, SecretValidation, ScanVuln, OutputDir, SkipAutoInstall, AllowPartialResults, MaxTreeDepth,
183194
StaticSca, XrayLibPluginBinaryCustomPath, AnalyzerManagerCustomPath, UploadRtRepoPath,
184195
},
185196
UploadCdx: {
@@ -192,7 +203,7 @@ var commandFlags = map[string][]string{
192203
scanProjectKey, Watches, ScanVuln, Fail,
193204
// Scan params
194205
Threads, ExclusionsAudit,
195-
Sca, Iac, Sast, Secrets, WithoutCA, SecretValidation, Sbom,
206+
auditSca, auditIac, auditSast, auditSecrets, auditWithoutCA, SecretValidation, Sbom,
196207
// Output params
197208
Licenses, OutputFormat, ExtendedTable, OutputDir, UploadRtRepoPath,
198209
// Scan Logic params
@@ -311,11 +322,14 @@ var flagsMap = map[string]components.Flag{
311322
StaticSca: components.NewBoolFlag(StaticSca, "Set to true to use the new SCA engine which is based on lock files.", components.SetHiddenBoolFlag()),
312323
CurationOutput: components.NewStringFlag(OutputFormat, "Defines the output format of the command. Acceptable values are: table, json.", components.WithStrDefaultValue("table")),
313324
SolutionPath: components.NewStringFlag(SolutionPath, "Path to the .NET solution file (.sln) to use when multiple solution files are present in the directory."),
314-
Sca: components.NewBoolFlag(Sca, fmt.Sprintf("Selective scanners mode: Execute SCA (Software Composition Analysis) sub-scan. Use --%s to run both SCA and Contextual Analysis. Use --%s --%s to to run SCA. Can be combined with --%s, --%s, --%s.", Sca, Sca, WithoutCA, Secrets, Sast, Iac)),
315-
Iac: components.NewBoolFlag(Iac, fmt.Sprintf("Selective scanners mode: Execute IaC sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Sast)),
316-
Sast: components.NewBoolFlag(Sast, fmt.Sprintf("Selective scanners mode: Execute SAST sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Iac)),
317-
Secrets: components.NewBoolFlag(Secrets, fmt.Sprintf("Selective scanners mode: Execute Secrets sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Sast, Iac)),
318-
WithoutCA: components.NewBoolFlag(WithoutCA, fmt.Sprintf("Selective scanners mode: Disable Contextual Analysis scanner after SCA. Relevant only with --%s flag.", Sca)),
325+
binarySca: components.NewBoolFlag(Sca, fmt.Sprintf("Selective scanners mode: Execute SCA (Software Composition Analysis) sub-scan. Use --%s to run both SCA and Contextual Analysis. Use --%s --%s to to run SCA. Can be combined with --%s.", Sca, Sca, WithoutCA, Secrets)),
326+
binarySecrets: components.NewBoolFlag(Secrets, fmt.Sprintf("Selective scanners mode: Execute Secrets sub-scan. Can be combined with --%s.", Sca)),
327+
binaryWithoutCA: components.NewBoolFlag(WithoutCA, fmt.Sprintf("Selective scanners mode: Disable Contextual Analysis scanner after SCA. Relevant only with --%s flag.", Sca)),
328+
auditSca: components.NewBoolFlag(Sca, fmt.Sprintf("Selective scanners mode: Execute SCA (Software Composition Analysis) sub-scan. Use --%s to run both SCA and Contextual Analysis. Use --%s --%s to to run SCA. Can be combined with --%s, --%s, --%s.", Sca, Sca, WithoutCA, Secrets, Sast, Iac)),
329+
auditIac: components.NewBoolFlag(Iac, fmt.Sprintf("Selective scanners mode: Execute IaC sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Sast)),
330+
auditSast: components.NewBoolFlag(Sast, fmt.Sprintf("Selective scanners mode: Execute SAST sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Iac)),
331+
auditSecrets: components.NewBoolFlag(Secrets, fmt.Sprintf("Selective scanners mode: Execute Secrets sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Sast, Iac)),
332+
auditWithoutCA: components.NewBoolFlag(WithoutCA, fmt.Sprintf("Selective scanners mode: Disable Contextual Analysis scanner after SCA. Relevant only with --%s flag.", Sca)),
319333
SecretValidation: components.NewBoolFlag(SecretValidation, fmt.Sprintf("Selective scanners mode: Triggers token validation on found secrets. Relevant only with --%s flag.", Secrets)),
320334

321335
AddSastRules: components.NewStringFlag(AddSastRules, "Incorporate any additional SAST rules (in JSON format, with absolute path) into this local scan."),

cli/scancommands.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ func ScanCmd(c *components.Context) error {
342342
if c.IsFlagSet(flags.Watches) {
343343
scanCmd.SetWatches(splitByCommaAndTrim(c.GetStringFlagValue(flags.Watches)))
344344
}
345+
// Check sub-scans to perform
346+
if subScans, err := getSubScansToPreform(c); err != nil {
347+
return err
348+
} else if len(subScans) > 0 {
349+
scanCmd.SetScansToPerform(subScans)
350+
}
345351
return commandsCommon.Exec(scanCmd)
346352
}
347353

@@ -752,6 +758,12 @@ func DockerScan(c *components.Context, image string) error {
752758
return err
753759
}
754760
containerScanCommand := scan.NewDockerScanCommand()
761+
// Check sub-scans to perform
762+
if subScans, err := getSubScansToPreform(c); err != nil {
763+
return err
764+
} else if len(subScans) > 0 {
765+
containerScanCommand.SetScansToPerform(subScans)
766+
}
755767
containerScanCommand.
756768
SetImageTag(image).
757769
SetBomGenerator(indexer.NewIndexerBomGenerator()).

commands/audit/audit.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,11 @@ func prepareToScan(params *AuditParams) (cmdResults *results.SecurityCommandResu
315315
if err != nil {
316316
return cmdResults.AddGeneralError(fmt.Errorf("failed to get scan logic options: %s", err.Error()), params.AllowPartialResults())
317317
}
318-
// Initialize the BOM generator
319-
if err = params.bomGenerator.WithOptions(bomGenOptions...).PrepareGenerator(); err != nil {
320-
return cmdResults.AddGeneralError(fmt.Errorf("failed to prepare the BOM generator: %s", err.Error()), params.AllowPartialResults())
318+
// Initialize the BOM generator if needed
319+
if params.resultsContext.IncludeSbom || utils.IsScanRequested(cmdResults.CmdType, utils.ScaScan, params.scansToPerform...) {
320+
if err = params.bomGenerator.WithOptions(bomGenOptions...).PrepareGenerator(); err != nil {
321+
return cmdResults.AddGeneralError(fmt.Errorf("failed to prepare the BOM generator: %s", err.Error()), params.AllowPartialResults())
322+
}
321323
}
322324
populateScanTargets(cmdResults, params)
323325
// Initialize the SCA scan strategy

commands/audit/audit_test.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,7 @@ func TestAuditWithConfigProfile(t *testing.T) {
326326
}},
327327
IsDefault: false,
328328
},
329-
expectedCaApplicable: 3,
330-
expectedCaUndetermined: 6,
331-
expectedCaNotCovered: 4,
332-
expectedCaNotApplicable: 2,
329+
expectedCaNotCovered: 15,
333330
},
334331
// TODO Add testcase for Sca and Applicability with exclusions after resolving the Glob patterns issues
335332
{
@@ -550,13 +547,10 @@ func TestAuditWithConfigProfile(t *testing.T) {
550547
}},
551548
IsDefault: false,
552549
},
553-
expectedSastIssues: 4,
554-
expectedSecretsIssues: 16,
555-
expectedIacIssues: 9,
556-
expectedCaApplicable: 3,
557-
expectedCaUndetermined: 6,
558-
expectedCaNotCovered: 4,
559-
expectedCaNotApplicable: 2,
550+
expectedSastIssues: 4,
551+
expectedSecretsIssues: 16,
552+
expectedIacIssues: 9,
553+
expectedCaNotCovered: 15,
560554
},
561555
{
562556
name: "All scanners enabled but some with exclude patterns",
@@ -589,13 +583,10 @@ func TestAuditWithConfigProfile(t *testing.T) {
589583
}},
590584
IsDefault: false,
591585
},
592-
expectedSastIssues: 0,
593-
expectedSecretsIssues: 7,
594-
expectedIacIssues: 9,
595-
expectedCaApplicable: 3,
596-
expectedCaUndetermined: 6,
597-
expectedCaNotCovered: 4,
598-
expectedCaNotApplicable: 2,
586+
expectedSastIssues: 0,
587+
expectedSecretsIssues: 7,
588+
expectedIacIssues: 9,
589+
expectedCaNotCovered: 15,
599590
},
600591
}
601592
assert.NoError(t, securityTestUtils.PrepareAnalyzerManagerResource())

0 commit comments

Comments
 (0)