Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git source should fail if directory doesn't exists #3005

Open
rgmz opened this issue Jun 23, 2024 · 1 comment
Open

Git source should fail if directory doesn't exists #3005

rgmz opened this issue Jun 23, 2024 · 1 comment
Labels

Comments

@rgmz
Copy link
Contributor

rgmz commented Jun 23, 2024

Please review the Community Note before submitting

TruffleHog Version

HEAD

Description

When using TruffleHog with a file:// uri, the scan will complete with a 0 exit code even if the directory doesn't exist.

$ ls /tmp/fake-dir/
ls: cannot access '/tmp/fake-dir/': No such file or directory
$ ./trufflehog git file:///tmp/fake-dir/
🐷🔑🐷  TruffleHog. Unearth your secrets. 🐷🔑🐷

2024-06-23T18:12:55-04:00       info-0  trufflehog      running source  {"source_manager_worker_id": "XIh5z", "with_units": true}
2024-06-23T18:12:55-04:00       info-0  trufflehog      finished scanning       {"chunks": 0, "bytes": 0, "verified_secrets": 0, "unverified_secrets": 0, "scan_duration": "4.326315ms", "trufflehog_version": "dev"}
$ echo $?
0
@rgmz rgmz added the bug label Jun 23, 2024
@rgmz
Copy link
Contributor Author

rgmz commented Jun 23, 2024

It seems that git.scanDir returns an error (repository does not exist), however, the error seems to vanish into a void.

func (s *Source) scanDir(ctx context.Context, gitDir string, reporter sources.ChunkReporter) error {
if !s.scanOptions.Bare && strings.HasSuffix(gitDir, "git") {
// TODO: Figure out why we skip directories ending in "git".
return nil
}
// try paths instead of url
repo, err := RepoFromPath(gitDir, s.scanOptions.Bare)

func (s *Source) ChunkUnit(ctx context.Context, unit sources.SourceUnit, reporter sources.ChunkReporter) error {

if err := source.ChunkUnit(ctx, unit, chunkReporter); err != nil {
report.ReportError(Fatal{ChunkError{Unit: unit, Err: err}})
catchFirstFatal(Fatal{err})
}

Confusingly, scanDirs and scanRepos — which would log such an error — don't seem to run in any configuration I tested. They only get called runWithoutUnits.

return s.runWithoutUnits(ctx, source, report, targets...)

@rgmz rgmz changed the title Git source doesn't check if directory exists Git source should fail if directory doesn't exists Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant