Skip to content

Commit

Permalink
fix(fs): assign the absolute path to be inspected to ROOTPATH when fi…
Browse files Browse the repository at this point in the history
…lesystem (#5158)
  • Loading branch information
int-tt authored Sep 10, 2023
1 parent 1953972 commit ed49609
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/report/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"html"
"io"
"path/filepath"
"regexp"
"strings"

Expand Down Expand Up @@ -46,6 +47,7 @@ type SarifWriter struct {
Version string
run *sarif.Run
locationCache map[string][]location
Target string
}

type sarifData struct {
Expand Down Expand Up @@ -135,6 +137,10 @@ func (sw *SarifWriter) Write(report types.Report) error {
"repoDigests": report.Metadata.RepoDigests,
}
}
if sw.Target != "" {
absPath, _ := filepath.Abs(sw.Target)
rootPath = fmt.Sprintf("file://%s/", absPath)
}

ruleIndexes := map[string]int{}
for _, res := range report.Results {
Expand Down
7 changes: 7 additions & 0 deletions pkg/report/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/aquasecurity/trivy/pkg/report/spdx"
"github.com/aquasecurity/trivy/pkg/report/table"
"github.com/aquasecurity/trivy/pkg/types"

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
)

const (
Expand Down Expand Up @@ -75,9 +77,14 @@ func Write(report types.Report, option flag.Options) error {
return xerrors.Errorf("failed to initialize template writer: %w", err)
}
case types.FormatSarif:
target := ""
if report.ArtifactType == ftypes.ArtifactFilesystem {
target = option.Target
}
writer = &SarifWriter{
Output: output,
Version: option.AppVersion,
Target: target,
}
case types.FormatCosignVuln:
writer = predicate.NewVulnWriter(output, option.AppVersion)
Expand Down

0 comments on commit ed49609

Please sign in to comment.