Fix git scan repository field using local file path instead of upstre…#4877
Open
jamesgol wants to merge 1 commit intotrufflesecurity:mainfrom
Open
Fix git scan repository field using local file path instead of upstre…#4877jamesgol wants to merge 1 commit intotrufflesecurity:mainfrom
jamesgol wants to merge 1 commit intotrufflesecurity:mainfrom
Conversation
…am remote URL When scanning local clones via file:// URI, GetSafeRemoteURL returned the clone's local origin rather than the original repo's upstreaam remote. Resolve through local paths to find the real remote URL.
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.
Description:
Fixes the
gitscanrepositorymetadata field containing a localfile://path instead of the actual upstream remote URL when scanning pre-cloned local repositories.Problem: When running
trufflehog git file:///path/to/local/clone, TruffleHog re-clones the repo to a temp directory. The clone'soriginremote gets set to thefile://path, andGetSafeRemoteURLreturns that local path as theRepositoryin JSON output — even when the original repo has a real remote (e.g.https://dev.azure.com/org/project/_git/repo).Fix: Updated
GetSafeRemoteURLinpkg/sources/git/git.goto detect when the resolved remote URL is a local path (file://scheme or absolute filesystem path). When detected, it opens the original repository and resolves its upstream remote URL instead. This is bounded to a single level of indirection — if the resolved URL is also local, it falls back to the original behavior.Added two helper functions:
localRepoPath— identifies whether a URL refers to a local reporesolveUpstreamRemote— opens the local repo and returns its non-local remote URLTests: Added 7 test cases covering:
file://clone resolves to upstream remoteCloses #4876
Checklist:
make test-community)?make lintthis requires golangci-lint)?Note
Low Risk
Low risk: limited to git repository metadata resolution and adds guardrails to avoid recursive local-path resolution; main behavior change is the
repositoryvalue reported for locally cloned repos.Overview
Fixes git scan
repositorymetadata when scanning pre-cloned/localfile://repos by teachingGetSafeRemoteURLto detect local-path remotes and resolve the original repo’s non-local upstream remote instead (with a single-level fallback to avoid recursion).Adds
localRepoPath/resolveUpstreamRemotehelpers and a focused test suite covering local clones,file://clones, bare clones, missing remotes, and remote fallback behavior.Reviewed by Cursor Bugbot for commit 9d1996c. Bugbot is set up for automated code reviews on this repo. Configure here.