Skip to content

Commit

Permalink
Detector-Fix: Reintroduce Cloudflareglobalapikey (#2101)
Browse files Browse the repository at this point in the history
* fixed cloudflare code

* readd email check

---------

Co-authored-by: Zachary Rice <zachary.rice@trufflesec.com>
  • Loading branch information
ankushgoel27 and zricethezav committed Apr 30, 2024
1 parent 2f7029b commit 770459e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ var _ detectors.Detector = (*Scanner)(nil)
var (
client = common.SaneHttpClient()

apiKeyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"cloudflare"}) + `([A-Za-z0-9_-]{37})`)
apiKeyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"cloudflare"}) + `\b([A-Za-z0-9_-]{37})\b`)

// email pattern thanks https://golangcode.com/validate-an-email-address/
// emailPat = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
// the emailPat regex will also match emails ending in .co.uk and .engineering

emailPat = regexp.MustCompile(`\b([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)\b`)
emailPat = regexp.MustCompile(`\b([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}(\.[A-Za-z]{2})?)\b`)
)

// Keywords are used for efficiently pre-filtering chunks.
Expand Down
3 changes: 2 additions & 1 deletion pkg/engine/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudelements"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudflareapitoken"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudflarecakey"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudflareglobalapikey"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudimage"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudmersive"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/cloudplan"
Expand Down Expand Up @@ -825,7 +826,7 @@ func DefaultDetectors() []detectors.Detector {
&clarifai.Scanner{},
&cloudflareapitoken.Scanner{},
&cloudflarecakey.Scanner{},
// &cloudflareglobalapikey.Scanner{},
&cloudflareglobalapikey.Scanner{},
&terraformcloudpersonaltoken.Scanner{},
&asanapersonalaccesstoken.Scanner{},
&trelloapikey.Scanner{},
Expand Down

0 comments on commit 770459e

Please sign in to comment.