Skip to content

Find, verify, and analyze leaked credentials

Fixed Gist URL Detection (#4284)

Kashif Khanb630944eeab6
diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.go
index e45722d8f..b0e343256 100644
--- a/pkg/sources/github/github.go
+++ b/pkg/sources/github/github.go
@@ -9,6 +9,7 @@ import (
"net/url"
"os"
"regexp"
+ "slices"
"sort"
"strings"
"sync"
@@ -1165,8 +1166,26 @@ func extractGistID(urlParts []string) string {
return urlParts[len(urlParts)-1]
}
+// isGistUrl returns true if the URL path is of a gist
func isGistUrl(urlParts []string) bool {
- return strings.EqualFold(urlParts[0], "gist.github.com") || (len(urlParts) == 4 && strings.EqualFold(urlParts[1], "gist"))
+ if len(urlParts) == 0 {
+ return false
+ }
+
+ // standard github gists: gist.github.com/user/abc123
+ if strings.EqualFold(urlParts[0], "gist.github.com") {
+ return true
+ }
+
+ // github enterprise: any 3 or 4 parts url with 'gist'
+ if (len(urlParts) == 3 || len(urlParts) == 4) && slices.Contains(urlParts, "gist") {
+ // enterprise.company.com/gist/gist-id
+ // gist.company.com/gist/gist-id
+ // gist.company.com/path/gist/gist-id
+ return true
+ }
+
+ return false
}
func (s *Source) chunkGistComments(ctx context.Context, gistURL string, gistInfo repoInfo, comments []*github.GistComment, reporter sources.ChunkReporter, cutoffTime *time.Time) error {