@@ -615,7 +615,7 @@ func getComponentSarifLocation(cmtType utils.CommandType, component formats.Comp
615615 logicalLocations = append (logicalLocations , logicalLocation )
616616 }
617617 }
618- location := sarif .NewLocation ().WithPhysicalLocation (sarif .NewPhysicalLocation ().WithArtifactLocation (sarif .NewArtifactLocation ().WithURI ("file://" + filePath )))
618+ location := sarif .NewLocation ().WithPhysicalLocation (sarif .NewPhysicalLocation ().WithArtifactLocation (sarif .NewArtifactLocation ().WithURI (filepath . ToSlash ( filePath ) )))
619619 if len (logicalLocations ) > 0 {
620620 location .WithLogicalLocations (logicalLocations )
621621 }
@@ -696,9 +696,6 @@ func patchRunsToPassIngestionRules(baseJfrogUrl string, cmdType utils.CommandTyp
696696 // Patch changes may alter the original run, so we will create a new run for each
697697 for _ , run := range runs {
698698 patched := sarifutils .CopyRun (run )
699- // Since we run in temp directories files should be relative
700- // Patch by converting the file paths to relative paths according to the invocations
701- convertPaths (cmdType , subScanType , patched )
702699 if cmdType .IsTargetBinary () && subScanType == utils .SecretsScan {
703700 // Patch the tool name in case of binary scan
704701 sarifutils .SetRunToolName (BinarySecretScannerToolName , patched )
@@ -712,20 +709,6 @@ func patchRunsToPassIngestionRules(baseJfrogUrl string, cmdType utils.CommandTyp
712709 return patchedRuns
713710}
714711
715- func convertPaths (commandType utils.CommandType , subScanType utils.SubScanType , runs ... * sarif.Run ) {
716- // Convert base on invocation for source code
717- sarifutils .ConvertRunsPathsToRelative (runs ... )
718- if ! (commandType == utils .DockerImage && subScanType == utils .SecretsScan ) {
719- return
720- }
721- for _ , run := range runs {
722- for _ , result := range run .Results {
723- // For Docker secret scan, patch the logical location if not exists
724- patchDockerSecretLocations (result )
725- }
726- }
727- }
728-
729712// Patch the URI to be the file path from sha<number>/<hash>/
730713// Extract the layer from the location URI, adds it as a logical location kind "layer"
731714func patchDockerSecretLocations (result * sarif.Result ) {
@@ -780,6 +763,10 @@ func patchResults(commandType utils.CommandType, subScanType utils.SubScanType,
780763 log .Debug (fmt .Sprintf ("[%s] Removing result [ruleId=%s] without locations: %s" , subScanType .String (), sarifutils .GetResultRuleId (result ), sarifutils .GetResultMsgText (result )))
781764 continue
782765 }
766+ if commandType == utils .DockerImage && subScanType == utils .SecretsScan {
767+ // For Docker secret scan, patch the logical location if not exists
768+ patchDockerSecretLocations (result )
769+ }
783770 patchResultMsg (result , target , commandType , subScanType , isJasViolations )
784771 if commandType .IsTargetBinary () {
785772 if patchBinaryPaths {
@@ -850,7 +837,8 @@ func getDockerfileLocationIfExists(run *sarif.Run) string {
850837 return location
851838 }
852839 }
853- if workspace := os .Getenv (utils .CurrentGithubWorkflowWorkspaceEnvVar ); workspace != "" {
840+ // Validate file path to prevent directory traversal
841+ if workspace := os .Getenv (utils .CurrentGithubWorkflowWorkspaceEnvVar ); workspace != "" && ! strings .Contains (workspace , ".." ) {
854842 if exists , err := fileutils .IsFileExists (filepath .Join (workspace , "Dockerfile" ), false ); err == nil && exists {
855843 return filepath .Join (workspace , "Dockerfile" )
856844 }
@@ -862,7 +850,8 @@ func getGithubWorkflowsDirIfExists() string {
862850 if exists , err := fileutils .IsDirExists (GithubBaseWorkflowDir , false ); err == nil && exists {
863851 return GithubBaseWorkflowDir
864852 }
865- if workspace := os .Getenv (utils .CurrentGithubWorkflowWorkspaceEnvVar ); workspace != "" {
853+ // Validate file path to prevent directory traversal
854+ if workspace := os .Getenv (utils .CurrentGithubWorkflowWorkspaceEnvVar ); workspace != "" && ! strings .Contains (workspace , ".." ) {
866855 if exists , err := fileutils .IsDirExists (filepath .Join (workspace , GithubBaseWorkflowDir ), false ); err == nil && exists {
867856 return filepath .Join (workspace , GithubBaseWorkflowDir )
868857 }
0 commit comments