Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
make empty slice delcration consistent (#2144)
ahravc34efc3cf957
diff --git a/pkg/detectors/aws/aws.go b/pkg/detectors/aws/aws.goindex ca67ddec0..c74f60609 100644--- a/pkg/detectors/aws/aws.go+++ b/pkg/detectors/aws/aws.go@@ -139,11 +139,11 @@ func (s scanner) FromData(ctx context.Context, verify bool, data []byte) (resultif verify {verified, extraData, verificationErr := s.verifyMatch(ctx, resIDMatch, resSecretMatch, true)s1.Verified = verified- //It'd be good to log when calculated account value does not match- //the account value from verification. Should only be edge cases at most.- //if extraData["account"] != s1.ExtraData["account"] && extraData["account"] != "" {//log here}+ // It'd be good to log when calculated account value does not match+ // the account value from verification. Should only be edge cases at most.+ // if extraData["account"] != s1.ExtraData["account"] && extraData["account"] != "" {//log here}- //Append the extraData to the existing ExtraData map.+ // Append the extraData to the existing ExtraData map.// This will overwrite with the new verified values.for k, v := range extraData {s1.ExtraData[k] = v@@ -319,7 +319,7 @@ func awsCustomCleanResults(results []detectors.Result) []detectors.Result {}}- out := []detectors.Result{}+ var out []detectors.Resultfor _, r := range idResults {out = append(out, r)}diff --git a/pkg/detectors/awssessionkeys/awssessionkey.go b/pkg/detectors/awssessionkeys/awssessionkey.goindex aee31402b..ba60843a8 100644--- a/pkg/detectors/awssessionkeys/awssessionkey.go+++ b/pkg/detectors/awssessionkeys/awssessionkey.go@@ -305,7 +305,7 @@ func awsCustomCleanResults(results []detectors.Result) []detectors.Result {}}- out := []detectors.Result{}+ var out []detectors.Resultfor _, r := range idResults {out = append(out, r)}diff --git a/pkg/detectors/falsepositives.go b/pkg/detectors/falsepositives.goindex d77a65b40..2a0b37f7b 100644--- a/pkg/detectors/falsepositives.go+++ b/pkg/detectors/falsepositives.go@@ -105,7 +105,7 @@ func StringShannonEntropy(input string) float64 {// FilterResultsWithEntropy filters out determinately unverified results that have a shannon entropy below the given value.func FilterResultsWithEntropy(results []Result, entropy float64) []Result {- filteredResults := []Result{}+ var filteredResults []Resultfor _, result := range results {if !result.Verified && result.VerificationError == nil {if result.RawV2 != nil {diff --git a/pkg/detectors/generic/generic.go b/pkg/detectors/generic/generic.goindex 22c77cdf6..371e17878 100644--- a/pkg/detectors/generic/generic.go+++ b/pkg/detectors/generic/generic.go@@ -24,14 +24,14 @@ func New() Scanner {`\b([/]{0,1}([\w]+[/])+[\w\.]*)\b`, // filepath`([0-9A-F]{2}[:-]){5}([0-9A-F]{2})`, // MAC addr`\d{4}[-/]{1}([0]\d|1[0-2])[-/]{1}([0-2]\d|3[01])`, // date- `[v|\-]\d\.\d`, //version- `\d\.\d\.\d-`, //version+ `[v|\-]\d\.\d`, // version+ `\d\.\d\.\d-`, // version`[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}`, // IPs and OIDs`[A-Fa-f0-9x]{2}:[A-Fa-f0-9x]{2}:[A-Fa-f0-9x]{2}`, // hex encoding- `[\w]+\([\w, ]+\)`, // function+ `[\w]+\([\w, ]+\)`, // function}- excludeMatchers := []*regexp.Regexp{}+ var excludeMatchers []*regexp.Regexpfor _, pat := range excludePatterns {excludeMatchers = append(excludeMatchers, regexp.MustCompile(pat))}diff --git a/pkg/detectors/jdbc/jdbc.go b/pkg/detectors/jdbc/jdbc.goindex 32fb96055..88b1e07f7 100644--- a/pkg/detectors/jdbc/jdbc.go+++ b/pkg/detectors/jdbc/jdbc.go@@ -30,7 +30,7 @@ func New(opts ...func(*Scanner)) *Scanner {func WithIgnorePattern(ignoreStrings []string) func(*Scanner) {return func(s *Scanner) {- ignorePatterns := []regexp.Regexp{}+ var ignorePatterns []regexp.Regexpfor _, ignoreString := range ignoreStrings {ignorePattern, err := regexp.Compile(ignoreString)if err != nil {diff --git a/pkg/detectors/privatekey/privatekey.go b/pkg/detectors/privatekey/privatekey.goindex eb4fe6dfa..860a66452 100644--- a/pkg/detectors/privatekey/privatekey.go+++ b/pkg/detectors/privatekey/privatekey.go@@ -10,10 +10,11 @@ import ("time""github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"+ "golang.org/x/crypto/ssh"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"- "golang.org/x/crypto/ssh")type Scanner struct {@@ -37,7 +38,7 @@ func (s Scanner) Keywords() []string {// FromData will find and optionally verify Privatekey secrets in a given set of bytes.func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]detectors.Result, error) {- results := []detectors.Result{}+ var results []detectors.ResultdataStr := string(data)matches := keyPat.FindAllString(dataStr, -1)@@ -81,7 +82,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]dete}if verify {- verificationErrors := []string{}+ var verificationErrors []stringdata, err := lookupFingerprint(fingerprint, s.IncludeExpired)if err == nil {if data != nil {diff --git a/pkg/detectors/tailscale/tailscale_test.go b/pkg/detectors/tailscale/tailscale_test.goindex 7a93e95fa..28ee3ba5d 100644--- a/pkg/detectors/tailscale/tailscale_test.go+++ b/pkg/detectors/tailscale/tailscale_test.go@@ -21,7 +21,7 @@ func TestTailscaleapi_FromChunk(t *testing.T) {ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)defer cancel()testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors4")- if err != nil && false {+ if err != nil {t.Fatalf("could not get test secrets from GCP: %s", err)}secret := testSecrets.MustGetField("TAILSCALEAPI")