Fix git scan repository field using local file path instead of upstre…#4877
Open
jamesgol wants to merge 2 commits intotrufflesecurity:mainfrom
Open
Fix git scan repository field using local file path instead of upstre…#4877jamesgol wants to merge 2 commits intotrufflesecurity:mainfrom
jamesgol wants to merge 2 commits 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.
shahzadhaider1
approved these changes
Apr 13, 2026
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
Medium Risk
Changes how
GetSafeRemoteURLresolves repository URLs, including opening local repositories and potentially altering reported metadata for file/absolute-path remotes; edge cases in path/URL handling could affect output correctness.Overview
Fixes git scan
Repositorymetadata when scanning pre-cloned local repos by resolvingfile:///absolute-path remotes to their upstream non-local remote instead of reporting the local path.GetSafeRemoteURLnow detects local remotes, opens the referenced repo, and returns its remote URL (bounded to one hop to avoid recursive local-path chains). Adds focused tests covering local clones,file://clones, bare clones, missing remotes, and fallback remote selection.Reviewed by Cursor Bugbot for commit 5253358. Bugbot is set up for automated code reviews on this repo. Configure here.