Fix SCA descriptor paths losing subdirectory prefix in SARIF output - #861
Open
orto17 wants to merge 1 commit into
Open
Fix SCA descriptor paths losing subdirectory prefix in SARIF output#861orto17 wants to merge 1 commit into
orto17 wants to merge 1 commit into
Conversation
TargetResults.GetDescriptors() computed each descriptor's path relative to the scan target's own working directory instead of the repo root, so a manifest like Server/package.json collapsed to just package.json in the generated SARIF and, by extension, in GitHub's code scanning alerts. SAST findings were unaffected since they already anchor to the audit root directory. Pass the audit root directory into GetDescriptors() so descriptor paths stay relative to the repo root, falling back to the target's own directory when no root is provided. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
devbranch.go vet ./....go fmt ./....When a project's descriptor lives in a subdirectory (e.g. Server/package.json), Frogbot's SARIF output — and consequently GitHub's Security → Code scanning alerts dashboard — shows the location as just "package.json", dropping the subfolder. The path is correct in the Xray UI, confirming the bug is in SARIF generation, not the underlying scan.
Root cause: TargetResults.GetDescriptors() computed each descriptor's path relative to the scan target's own working directory (sr.Target, e.g. /repo/Server) instead of the repo root. Since the working directory already includes the subfolder, filepath.Rel cancels it out, leaving only the filename. SAST/JAS findings don't have this bug because they're already anchored to the audit root directory.
Fix: GetDescriptors() now takes a rootDir parameter and resolves descriptor paths relative to it, falling back to sr.Target when empty (preserving existing behavior for any caller that doesn't have a root dir). Its one call site (commands/audit/audit.go) now passes params.RootDir(), which is already populated by Frogbot for every scan.
Concretely, a repo with both Server/package.json and Client/package.json today shows two GitHub code-scanning alerts that both just say package.json — indistinguishable. After the fix, each alert shows its full path and is unambiguous.