Skip to content

Find, verify, and analyze leaked credentials

make empty slice delcration consistent (#2144)

ahravc34efc3cf957
diff --git a/pkg/detectors/aws/aws.go b/pkg/detectors/aws/aws.go
index 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) (result
if 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.Result
for _, r := range idResults {
out = append(out, r)
}
diff --git a/pkg/detectors/awssessionkeys/awssessionkey.go b/pkg/detectors/awssessionkeys/awssessionkey.go
index 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.Result
for _, r := range idResults {
out = append(out, r)
}
diff --git a/pkg/detectors/falsepositives.go b/pkg/detectors/falsepositives.go
index 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 []Result
for _, 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.go
index 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.Regexp
for _, pat := range excludePatterns {
excludeMatchers = append(excludeMatchers, regexp.MustCompile(pat))
}
diff --git a/pkg/detectors/jdbc/jdbc.go b/pkg/detectors/jdbc/jdbc.go
index 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.Regexp
for _, ignoreString := range ignoreStrings {
ignorePattern, err := regexp.Compile(ignoreString)
if err != nil {
diff --git a/pkg/detectors/privatekey/privatekey.go b/pkg/detectors/privatekey/privatekey.go
index 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.Result
dataStr := 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 []string
data, 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.go
index 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")