@@ -174,8 +174,10 @@ func shouldIncludeVulnerabilities(includeVulnerabilities bool, watches []string,
174174
175175func shouldIncludeSnippetDetection (params * AuditParams ) bool {
176176 if profile := params .GetConfigProfile (); profile != nil && len (profile .Modules ) > 0 {
177- if profile .Modules [0 ].ScanConfig .ScaScannerConfig .EnableSnippetDetection {
178- return true
177+ for _ , module := range profile .Modules {
178+ if module .ScanConfig .ScaScannerConfig .EnableSnippetDetection {
179+ return true
180+ }
179181 }
180182 }
181183 if params .resultsContext .IncludeSnippetDetection {
@@ -282,14 +284,14 @@ func (auditCmd *AuditCommand) Run() (err error) {
282284
283285func (auditCmd * AuditCommand ) getResultWriter (cmdResults * results.SecurityCommandResults ) * output.ResultsWriter {
284286 var messages []string
285- if ! cmdResults .EntitledForJas {
287+ if ! cmdResults .Entitlements . Jas {
286288 messages = []string {coreutils .PrintTitle ("In addition to SCA, the ‘jf audit’ command supports the following Advanced Security scans: 'Contextual Analysis', 'Secrets Detection', 'IaC', and ‘SAST’.\n These scans are available within Advanced Security license. Read more - " ) + coreutils .PrintLink (utils .JasInfoURL )}
287289 }
288290 if cmdResults .ResultsPlatformUrl != "" && auditCmd .gitContext != nil {
289291 messages = append (messages , output .GetCommandResultsPlatformUrlMessage (cmdResults , true ))
290292 }
291293 var tableNotes []string
292- if cmdResults .EntitledForJas && cmdResults .HasViolationContext () && len (cmdResults .ResultContext .GitRepoHttpsCloneUrl ) == 0 {
294+ if cmdResults .Entitlements . Jas && cmdResults .HasViolationContext () && len (cmdResults .ResultContext .GitRepoHttpsCloneUrl ) == 0 {
293295 tableNotes = []string {"Note: The following vulnerability violations are NOT supported by this audit:\n - Secrets\n - Infrastructure as Code (IaC)\n - Static Application Security Testing (SAST)" }
294296 }
295297 return output .NewResultsWriter (cmdResults ).
@@ -377,7 +379,6 @@ func getScanLogicOptions(params *AuditParams) (bomGenOptions []bom.SbomGenerator
377379 xrayplugin .WithBinaryPath (params .CustomBomGenBinaryPath ()),
378380 xrayplugin .WithIgnorePatterns (params .Exclusions ()),
379381 xrayplugin .WithSpecificTechnologies (params .Technologies ()),
380- xrayplugin .WithSnippetDetection (shouldIncludeSnippetDetection (params )),
381382 }
382383 // Scan Strategies Options
383384 scanGraphParams , err := params .ToXrayScanGraphParams ()
@@ -418,17 +419,29 @@ func initAuditCmdResults(params *AuditParams) (cmdResults *results.SecurityComma
418419 entitledForJas , err := isEntitledForJas (xrayManager , params )
419420 if err != nil {
420421 return cmdResults .AddGeneralError (err , false )
421- } else {
422- cmdResults .SetEntitledForJas (entitledForJas )
423422 }
423+ cmdResults .SetEntitledForJas (entitledForJas )
424424 if entitledForJas {
425+ // Validate required installed software
425426 if utils .IsJASRequested (cmdResults .CmdType , params .ScansToPerform ()... ) {
426427 if err = jas .ValidateRequiredInstalledSoftware (); err != nil {
427428 return cmdResults .AddGeneralError (err , false )
428429 }
429430 }
431+ // Validate secret validation entitlement
430432 cmdResults .SetSecretValidation (jas .CheckForSecretValidation (xrayManager , params .GetXrayVersion (), slices .Contains (params .ScansToPerform (), utils .SecretTokenValidationScan )))
431433 }
434+ // Snippet detection requires JAS entitlement and also the Snippet Detection feature is enabled in Xray.
435+ if shouldIncludeSnippetDetection (params ) {
436+ entitledForSnippetDetection , err := isEntitledForSnippetDetection (entitledForJas , xrayManager , params )
437+ if err != nil {
438+ return cmdResults .AddGeneralError (err , false )
439+ }
440+ if ! entitledForSnippetDetection {
441+ return cmdResults .AddGeneralError (fmt .Errorf ("snippet detection is requested but the JFrog instance is not entitled for it" ), false )
442+ }
443+ cmdResults .SetEntitledForSnippetDetection (entitledForSnippetDetection )
444+ }
432445 return
433446}
434447
@@ -440,6 +453,14 @@ func isEntitledForJas(xrayManager *xray.XrayServicesManager, auditParams *AuditP
440453 return jas .IsEntitledForJas (xrayManager , auditParams .GetXrayVersion ())
441454}
442455
456+ func isEntitledForSnippetDetection (isEntitledForJas bool , xrayManager * xray.XrayServicesManager , auditParams * AuditParams ) (entitled bool , err error ) {
457+ if ! isEntitledForJas {
458+ return false , nil
459+ }
460+ // Snippet detection requires JAS entitlement and also the Snippet Detection feature is enabled in Xray.
461+ return xrayutils .IsEntitled (xrayManager , auditParams .GetXrayVersion (), xrayplugin .SnippetDetectionFeatureId )
462+ }
463+
443464func populateScanTargets (cmdResults * results.SecurityCommandResults , params * AuditParams ) {
444465 // Populate the scan targets based on the provided parameters.
445466 detectScanTargets (cmdResults , params )
@@ -458,7 +479,10 @@ func populateScanTargets(cmdResults *results.SecurityCommandResults, params *Aud
458479 // No need to generate the SBOM if we are not going to use it.
459480 continue
460481 }
461- bom .GenerateSbomForTarget (params .BomGenerator ().WithOptions (buildinfo .WithDescriptors (targetResult .GetDescriptors ())),
482+ bom .GenerateSbomForTarget (params .BomGenerator ().WithOptions (
483+ buildinfo .WithDescriptors (targetResult .GetDescriptors ()),
484+ xrayplugin .WithSnippetDetection (shouldIncludeSnippetDetection (params )),
485+ ),
462486 bom.SbomGeneratorParams {
463487 Target : targetResult ,
464488 AllowPartialResults : params .AllowPartialResults (),
@@ -616,7 +640,7 @@ func addScaScansToRunner(auditParallelRunner *utils.SecurityParallelRunner, audi
616640}
617641
618642func addJasScansToRunner (auditParallelRunner * utils.SecurityParallelRunner , auditParams * AuditParams , scanResults * results.SecurityCommandResults , isNewFlow bool ) (jasScanner * jas.JasScanner , generalError error ) {
619- if ! scanResults .EntitledForJas {
643+ if ! scanResults .Entitlements . Jas {
620644 log .Info ("Advanced Security is not enabled on this system, so Advanced Security scans were skipped..." )
621645 return
622646 }
0 commit comments