Skip to content

Commit

Permalink
chore(detectors): remove match len check
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz committed Nov 21, 2024
1 parent 5f23665 commit e054c80
Show file tree
Hide file tree
Showing 750 changed files with 74 additions and 2,818 deletions.
3 changes: 0 additions & 3 deletions pkg/detectors/abbysale/abbysale.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/abstract/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/abuseipdb/abuseipdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/accuweather/accuweather.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/adafruitio/adafruitio.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
9 changes: 2 additions & 7 deletions pkg/detectors/adobeio/adobeio.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package adobeio

import (
"context"
regexp "github.com/wasilibs/go-re2"
"net/http"
"strings"

regexp "github.com/wasilibs/go-re2"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
Expand Down Expand Up @@ -40,14 +41,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
idMatches := idPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])
for _, idMatch := range idMatches {
if len(idMatch) != 2 {
continue
}
resIdMatch := strings.TrimSpace(idMatch[1])

s1 := detectors.Result{
Expand Down
9 changes: 2 additions & 7 deletions pkg/detectors/adzuna/adzuna.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package adzuna
import (
"context"
"fmt"
regexp "github.com/wasilibs/go-re2"
"net/http"
"strings"

regexp "github.com/wasilibs/go-re2"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
Expand Down Expand Up @@ -50,15 +51,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
idMatches := idPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

for _, idMatch := range idMatches {
if len(idMatch) != 2 {
continue
}
resIdMatch := strings.TrimSpace(idMatch[1])

s1 := detectors.Result{
Expand Down
6 changes: 0 additions & 6 deletions pkg/detectors/aeroworkflow/aeroworkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
idmatches := idPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

for _, idmatch := range idmatches {
if len(idmatch) != 2 {
continue
}
resIdMatch := strings.TrimSpace(idmatch[1])

s1 := detectors.Result{
Expand Down
19 changes: 5 additions & 14 deletions pkg/detectors/agora/agora.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,14 @@ func (s Scanner) getClient() *http.Client {
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
dataStr := string(data)

keyMatches := keyPat.FindAllStringSubmatch(dataStr, -1)
matches := keyPat.FindAllStringSubmatch(dataStr, -1)
secretMatches := secretPat.FindAllStringSubmatch(dataStr, -1)

for _, keyMatch := range keyMatches {
if len(keyMatch) != 2 {
continue
}

resMatch := strings.TrimSpace(keyMatch[1])

for _, secretMatch := range secretMatches {
if len(secretMatch) != 2 {
continue
}

resSecret := strings.TrimSpace(secretMatch[1])
for _, match := range matches {
resMatch := strings.TrimSpace(match[1])

for _, secret := range secretMatches {
resSecret := strings.TrimSpace(secret[1])
/*
as both agora key and secretMatch has same regex, the set of strings keyMatch for both probably me same.
we need to avoid the scenario where key is same as secretMatch. This will reduce the number of matches we process.
Expand Down
6 changes: 0 additions & 6 deletions pkg/detectors/aha/aha.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result

resURLMatch := "aha.io"
for _, URLmatch := range URLmatches {
if len(URLmatch) != 2 {
continue
}
resURLMatch = strings.TrimSpace(URLmatch[1])
}

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
6 changes: 0 additions & 6 deletions pkg/detectors/airbrakeprojectkey/airbrakeprojectkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
idMatches := idPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

for _, idMatch := range idMatches {
if len(idMatch) != 2 {
continue
}

resIdMatch := strings.TrimSpace(idMatch[1])

Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/airbrakeuserkey/airbrakeuserkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/airship/airship.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/airvisual/airvisual.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/aiven/aiven.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/alconost/alconost.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/aletheiaapi/aletheiaapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
6 changes: 0 additions & 6 deletions pkg/detectors/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
idMatches := idPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

for _, idMatch := range idMatches {
if len(idMatch) != 2 {
continue
}

resIdMatch := strings.TrimSpace(idMatch[1])

Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/alienvault/alienvault.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/allsports/allsports.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
9 changes: 2 additions & 7 deletions pkg/detectors/amadeus/amadeus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package amadeus

import (
"context"
regexp "github.com/wasilibs/go-re2"
"io"
"net/http"
"strings"

regexp "github.com/wasilibs/go-re2"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
Expand Down Expand Up @@ -41,14 +42,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
secretMatches := secretPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])
for _, secretMatch := range secretMatches {
if len(secretMatch) != 2 {
continue
}
resSecret := strings.TrimSpace(secretMatch[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/ambee/ambee.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
6 changes: 0 additions & 6 deletions pkg/detectors/amplitudeapikey/amplitudeapikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
secretMatches := secretPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

for _, secretMatch := range secretMatches {
if len(secretMatch) != 2 {
continue
}
resSecretMatch := strings.TrimSpace(secretMatch[1])

// regex for both key and secret are same so the set of strings could possibly be same as well
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/anthropic/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
6 changes: 0 additions & 6 deletions pkg/detectors/anypoint/anypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
orgMatches := orgPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])
for _, orgMatch := range orgMatches {
if len(orgMatch) != 2 {
continue
}
orgRes := strings.TrimSpace(orgMatch[1])

// regex for both key and org are same, so to avoid same string processing
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/apacta/apacta.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/api2cart/api2cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])

s1 := detectors.Result{
Expand Down
Loading

0 comments on commit e054c80

Please sign in to comment.