Skip to content

Find, verify, and analyze leaked credentials

Detectors that fail verification should still report the unverified secret (#440)

trufflesteeeveb5743277a3c1
diff --git a/pkg/detectors/dropbox/dropbox.go b/pkg/detectors/dropbox/dropbox.go
index b6bc32423..0c036da09 100644
--- a/pkg/detectors/dropbox/dropbox.go
+++ b/pkg/detectors/dropbox/dropbox.go
@@ -6,10 +6,9 @@ import (
"net/http"
"regexp"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -53,23 +52,20 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", match[1]))
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
-
- // 200 means good key for get current user
- // 400 is bad (malformed)
- // 403 bad scope
- if res.StatusCode == http.StatusOK {
- s.Verified = true
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ // 200 means good key for get current user
+ // 400 is bad (malformed)
+ // 403 bad scope
+ if res.StatusCode == http.StatusOK {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/elasticemail/elasticemail.go b/pkg/detectors/elasticemail/elasticemail.go
index e895a288c..3f1a73968 100644
--- a/pkg/detectors/elasticemail/elasticemail.go
+++ b/pkg/detectors/elasticemail/elasticemail.go
@@ -2,14 +2,11 @@ package elasticemail
import (
"context"
- // "log"
- "regexp"
- "strings"
-
- // "fmt"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
+ "regexp"
+ "strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -56,37 +53,26 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
continue
}
res, err := client.Do(req)
- if err != nil {
- continue
- }
- defer res.Body.Close()
- var byteData []byte
- _, err = res.Body.Read(byteData)
- if err != nil {
- continue
- }
-
- defer res.Body.Close()
- data, readErr := ioutil.ReadAll(res.Body)
- if readErr != nil {
- continue
- }
- var ResVar struct {
- Success bool `json:"success"`
- }
- if err := json.Unmarshal(data, &ResVar); err != nil {
- continue
- }
- if ResVar.Success {
- s1.Verified = true
- } else {
-
- if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
- continue
+ if err == nil {
+ data, readErr := io.ReadAll(res.Body)
+ res.Body.Close()
+ if readErr == nil {
+ var ResVar struct {
+ Success bool `json:"success"`
+ }
+ if err := json.Unmarshal(data, &ResVar); err == nil {
+ if ResVar.Success {
+ s1.Verified = true
+ }
+ }
}
}
}
+ if !s1.Verified && detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
+ continue
+ }
+
results = append(results, s1)
}
return detectors.CleanResults(results), nil
diff --git a/pkg/detectors/github/github.go b/pkg/detectors/github/github.go
index f033dfc7f..37f68d3ce 100644
--- a/pkg/detectors/github/github.go
+++ b/pkg/detectors/github/github.go
@@ -73,23 +73,18 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Content-Type", "application/json; charset=utf-8")
req.Header.Add("Authorization", fmt.Sprintf("token %s", token))
res, err := client.Do(req)
- if err != nil {
- break
- }
- defer res.Body.Close()
- if res.StatusCode >= 200 && res.StatusCode < 300 {
+ if err == nil {
var userResponse userRes
err = json.NewDecoder(res.Body).Decode(&userResponse)
+ res.Body.Close()
if err == nil {
s.Verified = true
}
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/github_old/github_old.go b/pkg/detectors/github_old/github_old.go
index f3ec34bc7..64b95df03 100644
--- a/pkg/detectors/github_old/github_old.go
+++ b/pkg/detectors/github_old/github_old.go
@@ -75,21 +75,24 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Content-Type", "application/json; charset=utf-8")
req.Header.Add("Authorization", fmt.Sprintf("token %s", token))
res, err := client.Do(req)
- if err != nil {
- break
- }
- defer res.Body.Close()
- if res.StatusCode >= 200 && res.StatusCode < 300 {
- var userResponse userRes
- err = json.NewDecoder(res.Body).Decode(&userResponse)
- if err == nil {
- s.Verified = true
+ if err == nil {
+ if res.StatusCode >= 200 && res.StatusCode < 300 {
+ var userResponse userRes
+ err = json.NewDecoder(res.Body).Decode(&userResponse)
+ res.Body.Close()
+ if err == nil {
+ s.Verified = true
+ }
}
}
}
+ if !s.Verified && detectors.IsKnownFalsePositive(token, detectors.DefaultFalsePositives, true) {
+ continue
+ }
+
results = append(results, s)
}
- return
+ return detectors.CleanResults(results), nil
}
diff --git a/pkg/detectors/gitlab/gitlab.go b/pkg/detectors/gitlab/gitlab.go
index 3e3cb75d6..3221b831c 100644
--- a/pkg/detectors/gitlab/gitlab.go
+++ b/pkg/detectors/gitlab/gitlab.go
@@ -6,10 +6,9 @@ import (
"net/http"
"regexp"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -59,27 +58,24 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", match[1]))
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
-
- // 200 means good key and has `read_user` scope
- // 403 means good key but not the right scope
- // 401 is bad key
- if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
- secret.Verified = true
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ // 200 means good key and has `read_user` scope
+ // 403 means good key but not the right scope
+ // 401 is bad key
+ if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
+ secret.Verified = true
+ }
}
}
- if !secret.Verified {
- if detectors.IsKnownFalsePositive(string(secret.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !secret.Verified && detectors.IsKnownFalsePositive(string(secret.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, secret)
}
- return
+ return detectors.CleanResults(results), nil
}
diff --git a/pkg/detectors/gitlabv2/gitlab.go b/pkg/detectors/gitlabv2/gitlab.go
index 2549ad6df..2e811fa96 100644
--- a/pkg/detectors/gitlabv2/gitlab.go
+++ b/pkg/detectors/gitlabv2/gitlab.go
@@ -6,10 +6,9 @@ import (
"net/http"
"regexp"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -59,23 +58,20 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", match[1]))
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
-
- // 200 means good key and has `read_user` scope
- // 403 means good key but not the right scope
- // 401 is bad key
- if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
- secret.Verified = true
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ // 200 means good key and has `read_user` scope
+ // 403 means good key but not the right scope
+ // 401 is bad key
+ if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
+ secret.Verified = true
+ }
}
}
- if !secret.Verified {
- if detectors.IsKnownFalsePositive(string(secret.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !secret.Verified && detectors.IsKnownFalsePositive(string(secret.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, secret)
diff --git a/pkg/detectors/jdbc/jdbc.go b/pkg/detectors/jdbc/jdbc.go
index d76d93a25..529f27d01 100644
--- a/pkg/detectors/jdbc/jdbc.go
+++ b/pkg/detectors/jdbc/jdbc.go
@@ -45,29 +45,26 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
Redacted: redact,
}
- if verify {
- //TODO can this be verified? Possibly. Could triage verification to other DBMS strings
- s.Verified = false
- // client := common.SaneHttpClient()
- // req, err := http.NewRequestWithContext(ctx, "GET", "https://jdbcci.com/api/v2/me", nil)
- if err != nil {
- continue
- }
- // req.Header.Add("Accept", "application/json;")
- // req.Header.Add("Jdbc-Token", token)
- // res, err := client.Do(req)
- // if err != nil {
- // break
- // }
- // if res.StatusCode >= 200 && res.StatusCode < 300 {
- // s.Verified = true
- // }
- }
+ //if verify {
+ // // TODO: can this be verified? Possibly. Could triage verification to other DBMS strings
+ // s.Verified = false
+ // client := common.SaneHttpClient()
+ // req, err := http.NewRequestWithContext(ctx, "GET", "https://jdbcci.com/api/v2/me", nil)
+ // if err != nil {
+ // continue
+ // }
+ // req.Header.Add("Accept", "application/json;")
+ // req.Header.Add("Jdbc-Token", token)
+ // res, err := client.Do(req)
+ // if err == nil {
+ // if res.StatusCode >= 200 && res.StatusCode < 300 {
+ // s.Verified = true
+ // }
+ // }
+ //}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, false) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, false) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/mailchimp/mailchimp.go b/pkg/detectors/mailchimp/mailchimp.go
index d3aff94f6..f344cd4f0 100644
--- a/pkg/detectors/mailchimp/mailchimp.go
+++ b/pkg/detectors/mailchimp/mailchimp.go
@@ -54,22 +54,17 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.SetBasicAuth("anystring", match)
res, err := client.Do(req)
- if err != nil {
- break
- }
- defer res.Body.Close()
- if res.StatusCode == 200 {
- s.Verified = true
- } else {
- s.Verified = false
- }
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+ if res.StatusCode == 200 {
+ s.Verified = true
+ }
+ }
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go b/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go
index 675258f4a..0eb91a9be 100644
--- a/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go
+++ b/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go
@@ -2,7 +2,7 @@ package microsoftteamswebhook
import (
"context"
- "io/ioutil"
+ "io"
"net/http"
"regexp"
"strings"
@@ -27,7 +27,7 @@ var (
// Keywords are used for efficiently pre-filtering chunks.
// Use identifiers in the secret preferably, or the provider name.
func (s Scanner) Keywords() []string {
- return []string{"microsoft"}
+ return []string{"webhook.office.com"}
}
// FromData will find and optionally verify MicrosoftTeamsWebhook secrets in a given set of bytes.
@@ -54,26 +54,21 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
- if err != nil {
- continue
- }
- defer res.Body.Close()
-
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- continue
- }
-
- if res.StatusCode >= 200 && string(body) == "1" {
- s1.Verified = true
- } else {
- //This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key
- if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, false) {
- continue
+ if err == nil {
+ body, err := io.ReadAll(res.Body)
+ res.Body.Close()
+ if err == nil {
+ if res.StatusCode >= 200 && string(body) == "1" {
+ s1.Verified = true
+ }
}
}
}
+ if !s1.Verified && detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, false) {
+ continue
+ }
+
results = append(results, s1)
}
diff --git a/pkg/detectors/midise/midise.go b/pkg/detectors/midise/midise.go
index a4cc7516a..9a0f3c98f 100644
--- a/pkg/detectors/midise/midise.go
+++ b/pkg/detectors/midise/midise.go
@@ -6,10 +6,9 @@ import (
"net/http"
"regexp"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -54,20 +53,17 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", match))
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
+ if err == nil {
+ res.Body.Close() // The request body is unused.
- if res.StatusCode == http.StatusOK {
- s.Verified = true
+ if res.StatusCode == http.StatusOK {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/onelogin/onelogin.go b/pkg/detectors/onelogin/onelogin.go
index df0df4fff..00490d745 100644
--- a/pkg/detectors/onelogin/onelogin.go
+++ b/pkg/detectors/onelogin/onelogin.go
@@ -63,26 +63,23 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Authorization", fmt.Sprintf("client_id:%s, client_secret:%s", clientID[1], clientSecret[1]))
req.Header.Add("Content-Type", "application/json; charset=utf-8")
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
- if res.StatusCode >= 200 && res.StatusCode < 300 {
- s.Verified = true
- break
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ if res.StatusCode >= 200 && res.StatusCode < 300 {
+ s.Verified = true
+ }
}
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
}
}
- return
+ return detectors.CleanResults(results), nil
}
diff --git a/pkg/detectors/pivotaltracker/pivotaltracker.go b/pkg/detectors/pivotaltracker/pivotaltracker.go
index a13663c84..c7d0a609c 100644
--- a/pkg/detectors/pivotaltracker/pivotaltracker.go
+++ b/pkg/detectors/pivotaltracker/pivotaltracker.go
@@ -5,10 +5,9 @@ import (
"net/http"
"regexp"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -57,24 +56,21 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Content-Type", "application/json; charset=utf-8")
req.Header.Add("X-TrackerToken", token)
res, err := client.Do(req)
- if err != nil {
- break
- }
- defer res.Body.Close()
- if res.StatusCode >= 200 && res.StatusCode < 300 {
- s.Verified = true
- }
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+ if res.StatusCode >= 200 && res.StatusCode < 300 {
+ s.Verified = true
+ }
+ }
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
}
- return
+ return detectors.CleanResults(results), nil
}
diff --git a/pkg/detectors/privatekey/privatekey.go b/pkg/detectors/privatekey/privatekey.go
index beebdf613..50b06b54a 100644
--- a/pkg/detectors/privatekey/privatekey.go
+++ b/pkg/detectors/privatekey/privatekey.go
@@ -9,10 +9,9 @@ import (
"time"
log "github.com/sirupsen/logrus"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct {
@@ -62,13 +61,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]dete
if verify {
data, err := lookupFingerprint(fingerprint, s.IncludeExpired)
- if err != nil {
+ if err == nil {
+ secret.StructuredData = data
+ if data != nil {
+ secret.Verified = true
+ }
+ } else {
log.Warn(err)
- return nil, err
- }
- secret.StructuredData = data
- if data != nil {
- secret.Verified = true
}
}
diff --git a/pkg/detectors/rechargepayments/rechargepayments.go b/pkg/detectors/rechargepayments/rechargepayments.go
index 49273ae9f..36ce9c9ff 100644
--- a/pkg/detectors/rechargepayments/rechargepayments.go
+++ b/pkg/detectors/rechargepayments/rechargepayments.go
@@ -54,25 +54,22 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-Recharge-Access-Token", token)
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
-
- defer res.Body.Close()
+ if err == nil {
+ res.Body.Close() // The request body is unused.
- if res.StatusCode == http.StatusOK {
- s.Verified = true
+ if res.StatusCode == http.StatusOK {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
}
}
- return
+ return detectors.CleanResults(results), nil
}
diff --git a/pkg/detectors/sendgrid/sendgrid.go b/pkg/detectors/sendgrid/sendgrid.go
index 49d7bd2e8..7d5ac4ef5 100644
--- a/pkg/detectors/sendgrid/sendgrid.go
+++ b/pkg/detectors/sendgrid/sendgrid.go
@@ -60,23 +60,20 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", res))
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
-
- // 200 means good key and has `templates` scope
- // 403 means good key but not the right scope
- // 401 is bad key
- if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
- s.Verified = true
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ // 200 means good key and has `templates` scope
+ // 403 means good key but not the right scope
+ // 401 is bad key
+ if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/square/square.go b/pkg/detectors/square/square.go
index 6aea2c3f7..d35d887c6 100644
--- a/pkg/detectors/square/square.go
+++ b/pkg/detectors/square/square.go
@@ -67,22 +67,19 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
// unclear if this version needs to be set or matters, seems to work without, but docs want it
//req.Header.Add("Square-Version", "2020-08-12")
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
-
- // 200 means good key and has `merchants` scope - default allowed by square
- // 401 is bad key
- if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
- s.Verified = true
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ // 200 means good key and has `merchants` scope - default allowed by square
+ // 401 is bad key
+ if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/squareapp/squareapp.go b/pkg/detectors/squareapp/squareapp.go
index 0740c0223..90b5a79ee 100644
--- a/pkg/detectors/squareapp/squareapp.go
+++ b/pkg/detectors/squareapp/squareapp.go
@@ -9,10 +9,9 @@ import (
"regexp"
"strings"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -75,21 +74,18 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
// unclear if this version needs to be set or matters, seems to work without, but docs want it
//req.Header.Add("Square-Version", "2020-08-12")
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
+ if err == nil {
+ res.Body.Close() // The request body is unused.
- // 404 = Correct crentials. The fake access token should not be found
- if res.StatusCode == http.StatusNotFound {
- s.Verified = true
+ // 404 = Correct credentials. The fake access token should not be found.
+ if res.StatusCode == http.StatusNotFound {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/stripe/stripe.go b/pkg/detectors/stripe/stripe.go
index b93d3347e..c1353ecf5 100644
--- a/pkg/detectors/stripe/stripe.go
+++ b/pkg/detectors/stripe/stripe.go
@@ -6,10 +6,9 @@ import (
"net/http"
"regexp"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -56,20 +55,17 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", match))
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
- if err != nil {
- return results, err
- }
- defer res.Body.Close()
+ if err == nil {
+ res.Body.Close() // The request body is unused.
- if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
- s.Verified = true
+ if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden {
+ s.Verified = true
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s)
diff --git a/pkg/detectors/twilio/twilio.go b/pkg/detectors/twilio/twilio.go
index 617474493..da7b8b2ff 100644
--- a/pkg/detectors/twilio/twilio.go
+++ b/pkg/detectors/twilio/twilio.go
@@ -7,10 +7,9 @@ import (
"regexp"
"strings"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct{}
@@ -69,20 +68,18 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Accept", "*/*")
req.SetBasicAuth(sid, key)
res, err := client.Do(req)
- if err != nil {
- break
- }
- defer res.Body.Close()
- if res.StatusCode >= 200 && res.StatusCode < 300 {
- s.Verified = true
+ if err == nil {
+ res.Body.Close() // The request body is unused.
+
+ if res.StatusCode >= 200 && res.StatusCode < 300 {
+ s.Verified = true
+ }
}
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
+ continue
}
if len(keyMatches) > 0 {
diff --git a/pkg/detectors/uri/uri.go b/pkg/detectors/uri/uri.go
index 3d0156cb3..600990d99 100644
--- a/pkg/detectors/uri/uri.go
+++ b/pkg/detectors/uri/uri.go
@@ -4,16 +4,15 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"regexp"
"strings"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
-
- "github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type Scanner struct {
@@ -109,34 +108,25 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
- if err != nil {
- // log.WithError(err).Warn("Error in http post to SSRF proxy")
- continue
- }
- defer res.Body.Close()
- result := proxyRes{}
- body, err := ioutil.ReadAll(res.Body)
- if len(body) == 0 || err != nil {
- continue
- }
- err = json.Unmarshal(body, &result)
- if err != nil {
- // log.WithField("body", string(body)).WithError(err).Debug("Error decoding SSRF proxy response")
- continue
- }
- if result.Verified {
- s.Verified = true
+ if err == nil {
+ result := proxyRes{}
+ body, err := io.ReadAll(res.Body)
+ res.Body.Close()
+ if len(body) != 0 && err == nil {
+ err = json.Unmarshal(body, &result)
+ if err == nil && result.Verified {
+ s.Verified = true
+ }
+ }
}
}
- if !s.Verified {
- if detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, false) {
- continue
- }
+ if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, false) {
+ continue
}
results = append(results, s)
}
- return
+ return detectors.CleanResults(results), nil
}
diff --git a/pkg/detectors/webex/webex.go b/pkg/detectors/webex/webex.go
index 3d57a6582..c985044fc 100644
--- a/pkg/detectors/webex/webex.go
+++ b/pkg/detectors/webex/webex.go
@@ -2,10 +2,8 @@ package webex
import (
"context"
- // "fmt"
- // "log"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"regexp"
"strings"
@@ -21,8 +19,6 @@ type Scanner struct{}
var _ detectors.Detector = (*Scanner)(nil)
var (
- client = common.SaneHttpClient()
-
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"webex"}) + `\b([A-Za-z0-9_-]{64})\b`)
idPat = regexp.MustCompile(detectors.PrefixRegex([]string{"webex"}) + `\b([A-Za-z0-9_-]{65})\b`)
)
@@ -64,39 +60,32 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
continue
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
+ client := common.SaneHttpClient()
res, err := client.Do(req)
- if err != nil {
- continue
- }
-
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- continue
- }
-
- var message struct {
- Message string `json:"message"`
- }
- if err := json.Unmarshal(body, &message); err != nil {
- continue
- }
-
- var getError = regexp.MustCompile(detectors.PrefixRegex([]string{"error"}) + `(redirect_uri_mismatch)`)
- result := getError.FindAllStringSubmatch(message.Message, -1)
- if len(result) > 0 {
- s1.Verified = true
- } else {
- if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
- continue
+ if err == nil {
+ body, err := io.ReadAll(res.Body)
+ res.Body.Close()
+ if err == nil {
+ var message struct {
+ Message string `json:"message"`
+ }
+ if err := json.Unmarshal(body, &message); err == nil {
+ var getError = regexp.MustCompile(detectors.PrefixRegex([]string{"error"}) + `(redirect_uri_mismatch)`)
+ result := getError.FindAllStringSubmatch(message.Message, -1)
+ if len(result) > 0 {
+ s1.Verified = true
+ }
+ }
}
}
+ }
+ if !s1.Verified && detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
+ continue
}
results = append(results, s1)
}
-
}
return detectors.CleanResults(results), nil