Skip to content

Commit df672a6

Browse files
committed
fix: scope (?i) to variable prefix only; move rancher to alphabetical order
- keyPat: use (?i:...) to apply case-insensitivity only to the variable name prefix (CATTLE_TOKEN etc.), leaving the token capture group [a-z0-9]{54,64} strictly lowercase as intended - defaults.go: move rancher import and Scanner{} registration to alphabetical position between ramp and rapidapi
1 parent 9bf0780 commit df672a6

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

pkg/detectors/rancher/rancher.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ var (
2121
// Use the SSRF-safe client that blocks requests to local/private IP ranges.
2222
client = detectors.DetectorHttpClientWithNoLocalAddresses
2323

24-
// Rancher API tokens: 54–64 lowercase alphanumeric chars, named with cattle/rancher prefixes.
25-
keyPat = regexp.MustCompile(`(?i)(?:CATTLE_TOKEN|RANCHER_TOKEN|CATTLE_BOOTSTRAP_PASSWORD|RANCHER_API_TOKEN)[\w]*\s*[=:]\s*["']?([a-z0-9]{54,64})["']?`)
24+
// Match variable name case-insensitively via (?i:...) scope, then require strictly
25+
// lowercase alphanumeric token to avoid false positives from the broad character set.
26+
keyPat = regexp.MustCompile(`(?i:(?:CATTLE_TOKEN|RANCHER_TOKEN|CATTLE_BOOTSTRAP_PASSWORD|RANCHER_API_TOKEN)[\w]*\s*[=:]\s*["']?)([a-z0-9]{54,64})["']?`)
2627

2728
// Server URL used for validation; must appear nearby in the same chunk.
28-
serverPat = regexp.MustCompile(`(?i)(?:CATTLE_SERVER|RANCHER_URL|RANCHER_SERVER)\s*[=:]\s*["']?(https?://[^\s"']+)["']?`)
29+
serverPat = regexp.MustCompile(`(?i:(?:CATTLE_SERVER|RANCHER_URL|RANCHER_SERVER)\s*[=:]\s*["']?)(https?://[^\s"']+)["']?`)
2930
)
3031

3132
func (s Scanner) Keywords() []string {

pkg/engine/defaults/defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ import (
609609
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/rabbitmq"
610610
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/railwayapp"
611611
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/ramp"
612+
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/rancher"
612613
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/rapidapi"
613614
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/rawg"
614615
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/razorpay"
@@ -709,7 +710,6 @@ import (
709710
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/sonarcloud"
710711
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/sourcegraph"
711712
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/sourcegraphcody"
712-
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/rancher"
713713
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/spectralops"
714714
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/speechtextai"
715715
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/splunkobservabilitytoken"
@@ -1502,6 +1502,7 @@ func buildDetectorList() []detectors.Detector {
15021502
&rabbitmq.Scanner{},
15031503
&railwayapp.Scanner{},
15041504
&ramp.Scanner{},
1505+
&rancher.Scanner{},
15051506
&rapidapi.Scanner{},
15061507
// &raven.Scanner{},
15071508
&rawg.Scanner{},
@@ -1606,7 +1607,6 @@ func buildDetectorList() []detectors.Detector {
16061607
&sourcegraph.Scanner{},
16071608
&sourcegraphcody.Scanner{},
16081609
// &sparkpost.Scanner{},
1609-
&rancher.Scanner{},
16101610
&spectralops.Scanner{},
16111611
&speechtextai.Scanner{},
16121612
&splunkobservabilitytoken.Scanner{},

0 commit comments

Comments
 (0)