Skip to content

Find, verify, and analyze leaked credentials

[OC-101] - Prevent Gitlab detector panic (#799)

ahrav33ab1cfeb298
diff --git a/pkg/detectors/gitlab/gitlab.go b/pkg/detectors/gitlab/gitlab.go
index cd596d260..612960ffb 100644
--- a/pkg/detectors/gitlab/gitlab.go
+++ b/pkg/detectors/gitlab/gitlab.go
@@ -40,7 +40,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
resMatch := strings.TrimSpace(match[1])
if strings.Contains(match[0], "glpat") {
keyString := strings.Split(match[0], " ")
- resMatch = keyString[2]
+ resMatch = keyString[len(keyString)-1]
}
secret := detectors.Result{
diff --git a/pkg/detectors/gitlab/gitlab_test.go b/pkg/detectors/gitlab/gitlab_test.go
index a8d6ef7d6..0bf1a9b8b 100644
--- a/pkg/detectors/gitlab/gitlab_test.go
+++ b/pkg/detectors/gitlab/gitlab_test.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/kylelemons/godebug/pretty"
+
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
@@ -41,7 +42,23 @@ func TestGitlab_FromChunk(t *testing.T) {
s: Scanner{},
args: args{
ctx: context.Background(),
- data: []byte(fmt.Sprintf("You can find a gitlab secret %s within", secret)),
+ data: []byte(fmt.Sprintf("You can find a gitlab super secret %s within", secret)),
+ verify: true,
+ },
+ want: []detectors.Result{
+ {
+ DetectorType: detectorspb.DetectorType_Gitlab,
+ Verified: true,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "found only secret phrase",
+ s: Scanner{},
+ args: args{
+ ctx: context.Background(),
+ data: []byte(fmt.Sprintf("gitlab %s", secret)),
verify: true,
},
want: []detectors.Result{