Skip to content

Find, verify, and analyze leaked credentials

Added Shannon Entropy Check in Gitlab v1 detector (#4260)

Kashif Khan60dd91e60e94
diff --git a/pkg/detectors/gitlab/v1/gitlab.go b/pkg/detectors/gitlab/v1/gitlab.go
index 7eb5e525e..c3f6f41e6 100644
--- a/pkg/detectors/gitlab/v1/gitlab.go
+++ b/pkg/detectors/gitlab/v1/gitlab.go
@@ -56,6 +56,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
resMatch := strings.TrimSpace(match[1])
+ // to avoid false positives
+ if detectors.StringShannonEntropy(resMatch) < 3.6 {
+ continue
+ }
+
s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_Gitlab,
Raw: []byte(resMatch),
diff --git a/pkg/detectors/gitlab/v1/gitlab_v1_test.go b/pkg/detectors/gitlab/v1/gitlab_v1_test.go
index 148642ac0..b093f22d8 100644
--- a/pkg/detectors/gitlab/v1/gitlab_v1_test.go
+++ b/pkg/detectors/gitlab/v1/gitlab_v1_test.go
@@ -21,6 +21,7 @@ var (
"test_secrets": {
"gitlab_secret": "oXCt4JT2wf1_WlZl2OVG"
},
+ "docs":"https://docs.gitlab.com/test/api/example.json#get-drone-test-example-settings", // this matches the pattern but fail in entropy check
"expected_response": "200",
"method": "GET",
"deprecated": false