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

Gist Scanning Errors #2640

Closed
joeleonjr opened this issue Mar 28, 2024 · 4 comments · Fixed by #2653
Closed

Gist Scanning Errors #2640

joeleonjr opened this issue Mar 28, 2024 · 4 comments · Fixed by #2653
Labels

Comments

@joeleonjr
Copy link
Contributor

TruffleHog Version

trufflehog 3.71.1

Trace Output

Trace back

Expected Behavior

Gists should be scanned just like any other repository on GitHub.

Actual Behavior

Depending on the Gist URL structure, one of two different errors spits out:

URLs with the username (https://gist.github.com/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb.git)

Failed to fetch repository	{"source_manager_worker_id": "Xwjd7", "repo": "https://gist.github.com/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb.git", "error": "GET https://api.github.com/repos/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb: 404 Not Found []"}

URLs without the username (https://gist.github.com/274463.git)

Unable to cache repository info	{"source_manager_worker_id": "ATqG1", "repo": "https://gist.github.com/274463.git", "error": "missing cached info for gist: https://gist.github.com/274463.git"}

Steps to Reproduce

Run the following commands:

trufflehog github --repo https://gist.github.com/274463.git
trufflehog github --repo https://gist.github.com/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb.git

Environment

  • OS: OSX
  • Version 14.2.1

Additional Context

I believe this was introduced in PR #2379 .

@rgmz
Copy link
Contributor

rgmz commented Mar 28, 2024

This is caused by two faulty assumptions:

  1. that Gist URLs only contain one path segment
  2. that Gists wouldn't be scanned directly via the --repo flag
    // Ignore any gists in |s.filteredRepoCache|.
    // (Repos have three parts: [github.com, owner, name], gists have two.)
    if len(urlParts) != 3 {
    // Gists _should_ be cached elsewhere.
    err = fmt.Errorf("missing cached info for gist: %s", r)
    repoCtx.Logger().Error(err, "Unable to cache repository info")
    continue RepoLoop
    }

An obvious hot-fix would be to check whether the host is "gist.github.com", similar to what the existing code does elsewhere (prior code to #2379). However, this is a bad long-term solution as it won't work on GitHub Enterprise Server.
https://github.com/rgmz/trufflehog/blob/283d83f113ff8762c8c301d1f3de7767c67f02e2/pkg/sources/github/github.go#L1074-L1075

@joeleonjr
Copy link
Contributor Author

Would it be reasonable to add a CLI flag just for gists?

@rgmz
Copy link
Contributor

rgmz commented Mar 29, 2024

I think they are different enough that it would make sense. There's a lot of awkward code around mingling repositories and gists.

@rgmz rgmz mentioned this issue Apr 2, 2024
2 tasks
@JefriReynaldi
Copy link

TruffleHog Version

trufflehog 3.71.1

Trace Output

Trace back

Expected Behavior

Gists should be scanned just like any other repository on GitHub.

Actual Behavior

Depending on the Gist URL structure, one of two different errors spits out:

URLs with the username (https://gist.github.com/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb.git)

Failed to fetch repository	{"source_manager_worker_id": "Xwjd7", "repo": "https://gist.github.com/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb.git", "error": "GET https://api.github.com/repos/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb: 404 Not Found []"}

URLs without the username (https://gist.github.com/274463.git)

Unable to cache repository info	{"source_manager_worker_id": "ATqG1", "repo": "https://gist.github.com/274463.git", "error": "missing cached info for gist: https://gist.github.com/274463.git"}

Steps to Reproduce

Run the following commands:

trufflehog github --repo https://gist.github.com/274463.git trufflehog github --repo https://gist.github.com/raccoons-bot/627e15a45a596068ce8bfef3fd05ccdb.git

Environment

  • OS: OSX
  • Version 14.2.1

Additional Context

I believe this was introduced in PR #2379 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants