diff --git a/pkg/detectors/privacy/privacy.go b/pkg/detectors/privacy/privacy.go index 30a73016a89c..fb62f6c478af 100644 --- a/pkg/detectors/privacy/privacy.go +++ b/pkg/detectors/privacy/privacy.go @@ -3,10 +3,11 @@ package privacy 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" diff --git a/pkg/detectors/uri/uri.go b/pkg/detectors/uri/uri.go index 111869ea9a8c..42b695d9f1e4 100644 --- a/pkg/detectors/uri/uri.go +++ b/pkg/detectors/uri/uri.go @@ -30,7 +30,7 @@ var _ interface { } = (*Scanner)(nil) var ( - keyPat = regexp.MustCompile(`\b(?:https?:)?\/\/[\S]{3,50}:([\S]{3,50})@[-.%\w\/:]+\b`) + keyPat = regexp.MustCompile(`\b(?:https?:\/\/)?[\w-\.$~!]{3,50}:([\w-\.%$^&#]{3,50})@[-.\w]+\b`) // TODO: make local addr opt-out defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses @@ -131,6 +131,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } } + results = append(results, r) } diff --git a/pkg/detectors/uri/uri_test.go b/pkg/detectors/uri/uri_test.go index 7c0762bb0434..bdde2b9e8555 100644 --- a/pkg/detectors/uri/uri_test.go +++ b/pkg/detectors/uri/uri_test.go @@ -13,6 +13,7 @@ import ( var ( validPattern = "https://kaNydBSAodo87dsm9asuiSAFtsd7.com:1234@qYY3SylY7fHP" + validPattern2 = `

http://username:password@127.0.0.1

` invalidPattern = "https://kaNydBSAodo87dsm9asuiSAFtsd7.com.1234@qYY3SylY7fHP" keyword = "uri" ) @@ -30,6 +31,11 @@ func TestURI_Pattern(t *testing.T) { input: fmt.Sprintf("%s token = '%s'", keyword, validPattern), want: []string{validPattern}, }, + { + name: "valid pattern - do not process duplicate", + input: fmt.Sprintf("%s token = '%s'", keyword, validPattern2), + want: []string{"http://username:password@127.0.0.1"}, + }, { name: "invalid pattern", input: fmt.Sprintf("%s = '%s'", keyword, invalidPattern),