@@ -110,8 +110,13 @@ func (sc *CmdResultsSarifConverter) ParseNewTargetResults(target results.ScanTar
110110func (sc * CmdResultsSarifConverter ) createScaRun (target results.ScanTarget , errorCount int ) * sarif.Run {
111111 run := sarif .NewRunWithInformationURI (ScaScannerToolName , utils .BaseDocumentationURL + "sca" )
112112 run .Tool .Driver .Version = & sc .xrayVersion
113+ wd := target .Target
114+ if sc .currentCmdType .IsTargetBinary () {
115+ // For binary, the target is a file and not a directory
116+ wd = filepath .Dir (wd )
117+ }
113118 run .Invocations = append (run .Invocations , sarif .NewInvocation ().
114- WithWorkingDirectory (sarif .NewSimpleArtifactLocation (target . Target )).
119+ WithWorkingDirectory (sarif .NewSimpleArtifactLocation (wd )).
115120 WithExecutionSuccess (errorCount == 0 ),
116121 )
117122 return run
@@ -240,7 +245,7 @@ func addSarifScaVulnerability(cmdType utils.CommandType, sarifResults *[]*sarif.
240245 if err != nil {
241246 return err
242247 }
243- currentResults , currentRule := parseScaToSarifFormat (cmdType , vulnerability .IssueId , vulnerability .Summary , markdownDescription , maxCveScore , getScaIssueSarifHeadline , cves , severity , applicabilityStatus , impactedPackagesName , impactedPackagesVersion , fixedVersions , directComponents )
248+ currentResults , currentRule := parseScaToSarifFormat (cmdType , vulnerability .IssueId , vulnerability .Summary , markdownDescription , maxCveScore , getScaVulnerabilitySarifHeadline , cves , severity , applicabilityStatus , impactedPackagesName , impactedPackagesVersion , fixedVersions , directComponents )
244249 cveImpactedComponentRuleId := results .GetScaIssueId (impactedPackagesName , impactedPackagesVersion , results .GetIssueIdentifier (cves , vulnerability .IssueId , "_" ))
245250 if _ , ok := (* rules )[cveImpactedComponentRuleId ]; ! ok {
246251 // New Rule
@@ -261,7 +266,7 @@ func addSarifScaSecurityViolation(cmdType utils.CommandType, sarifResults *[]*sa
261266 if err != nil {
262267 return err
263268 }
264- currentResults , currentRule := parseScaToSarifFormat (cmdType , violation .IssueId , violation .Summary , markdownDescription , maxCveScore , getScaIssueSarifHeadline , cves , severity , applicabilityStatus , impactedPackagesName , impactedPackagesVersion , fixedVersions , directComponents , violation .WatchName )
269+ currentResults , currentRule := parseScaToSarifFormat (cmdType , violation .IssueId , violation .Summary , markdownDescription , maxCveScore , getScaSecurityViolationSarifHeadline , cves , severity , applicabilityStatus , impactedPackagesName , impactedPackagesVersion , fixedVersions , directComponents , violation .WatchName )
265270 cveImpactedComponentRuleId := results .GetScaIssueId (impactedPackagesName , impactedPackagesVersion , results .GetIssueIdentifier (cves , violation .IssueId , "_" ))
266271 if _ , ok := (* rules )[cveImpactedComponentRuleId ]; ! ok {
267272 // New Rule
@@ -396,10 +401,14 @@ func getDirectDependenciesFormatted(directDependencies []formats.ComponentRow) (
396401 return strings .TrimSuffix (formattedDirectDependencies .String (), "<br/>" ), nil
397402}
398403
399- func getScaIssueSarifHeadline (depName , version , issueId string ) string {
404+ func getScaVulnerabilitySarifHeadline (depName , version , issueId string ) string {
400405 return fmt .Sprintf ("[%s] %s %s" , issueId , depName , version )
401406}
402407
408+ func getScaSecurityViolationSarifHeadline (depName , version , key string ) string {
409+ return fmt .Sprintf ("Security violation %s" , getScaVulnerabilitySarifHeadline (depName , version , key ))
410+ }
411+
403412func getXrayLicenseSarifHeadline (depName , version , key string ) string {
404413 return fmt .Sprintf ("License violation [%s] in %s %s" , key , depName , version )
405414}
@@ -417,21 +426,21 @@ func getScaLicenseViolationMarkdown(depName, version, key string, directDependen
417426}
418427
419428func patchRunsToPassIngestionRules (cmdType utils.CommandType , subScanType utils.SubScanType , patchBinaryPaths bool , target results.ScanTarget , runs ... * sarif.Run ) []* sarif.Run {
420- // Since we run in temp directories files should be relative
421- // Patch by converting the file paths to relative paths according to the invocations
422- convertPaths (cmdType , subScanType , runs ... )
423429 patchedRuns := []* sarif.Run {}
424430 // Patch changes may alter the original run, so we will create a new run for each
425431 for _ , run := range runs {
426- patched := sarifutils .CopyRunMetadata (run )
432+ patched := sarifutils .CopyRun (run )
433+ // Since we run in temp directories files should be relative
434+ // Patch by converting the file paths to relative paths according to the invocations
435+ convertPaths (cmdType , subScanType , patched )
427436 if cmdType .IsTargetBinary () && subScanType == utils .SecretsScan {
428437 // Patch the tool name in case of binary scan
429438 sarifutils .SetRunToolName (BinarySecretScannerToolName , patched )
430439 }
431440 if patched .Tool .Driver != nil {
432- patched .Tool .Driver .Rules = patchRules (cmdType , subScanType , run .Tool .Driver .Rules ... )
441+ patched .Tool .Driver .Rules = patchRules (cmdType , subScanType , patched .Tool .Driver .Rules ... )
433442 }
434- patched .Results = patchResults (cmdType , subScanType , patchBinaryPaths , target , run , run .Results ... )
443+ patched .Results = patchResults (cmdType , subScanType , patchBinaryPaths , target , patched , patched .Results ... )
435444 patchedRuns = append (patchedRuns , patched )
436445 }
437446 return patchedRuns
@@ -470,28 +479,20 @@ func patchDockerSecretLocations(result *sarif.Result) {
470479func patchRules (commandType utils.CommandType , subScanType utils.SubScanType , rules ... * sarif.ReportingDescriptor ) (patched []* sarif.ReportingDescriptor ) {
471480 patched = []* sarif.ReportingDescriptor {}
472481 for _ , rule := range rules {
473- cloned := sarif .NewRule (rule .ID )
474482 if rule .Name != nil && rule .ID == * rule .Name {
475483 // SARIF1001 - if both 'id' and 'name' are present, they must be different. If they are identical, the tool must omit the 'name' property.
476- cloned .Name = rule . Name
484+ rule .Name = nil
477485 }
478- cloned .ShortDescription = rule .ShortDescription
479486 if commandType .IsTargetBinary () && subScanType == utils .SecretsScan {
480487 // Patch the rule name in case of binary scan
481- sarifutils .SetRuleShortDescriptionText (fmt .Sprintf ("[Secret in Binary found] %s" , sarifutils .GetRuleShortDescriptionText (rule )), cloned )
488+ sarifutils .SetRuleShortDescriptionText (fmt .Sprintf ("[Secret in Binary found] %s" , sarifutils .GetRuleShortDescriptionText (rule )), rule )
482489 }
483- cloned .FullDescription = rule .FullDescription
484- cloned .Help = rule .Help
485- if cloned .Help == nil {
490+ if rule .Help == nil {
486491 // Github code scanning ingestion rules rejects rules without help content.
487492 // Patch by transferring the full description to the help field.
488- cloned .Help = rule .FullDescription
493+ rule .Help = rule .FullDescription
489494 }
490- cloned .HelpURI = rule .HelpURI
491- cloned .Properties = rule .Properties
492- cloned .MessageStrings = rule .MessageStrings
493-
494- patched = append (patched , cloned )
495+ patched = append (patched , rule )
495496 }
496497 return
497498}
@@ -734,7 +735,7 @@ func calculateResultFingerprints(resultType utils.CommandType, run *sarif.Run, r
734735 if ! resultType .IsTargetBinary () {
735736 return nil
736737 }
737- ids := []string {sarifutils .GetRunToolName (run ), sarifutils .GetResultRuleId (result )}
738+ ids := []string {sarifutils .GetRunToolName (run ), sarifutils .GetResultRuleId (result ), getResultWatches ( result ) }
738739 for _ , location := range sarifutils .GetResultFileLocations (result ) {
739740 ids = append (ids , strings .ReplaceAll (location , string (filepath .Separator ), "/" ))
740741 }
@@ -747,3 +748,12 @@ func calculateResultFingerprints(resultType utils.CommandType, run *sarif.Run, r
747748 sarifutils .SetResultFingerprint (jfrogFingerprintAlgorithmName , hashValue , result )
748749 return nil
749750}
751+
752+ func getResultWatches (result * sarif.Result ) (watches string ) {
753+ if watchesProperty , ok := result .Properties [WatchSarifPropertyKey ]; ok {
754+ if watchesValue , ok := watchesProperty .(string ); ok {
755+ return watchesValue
756+ }
757+ }
758+ return
759+ }
0 commit comments