Skip to content

Commit d010607

Browse files
fixed uri regex issue (#3815)
* fixed uri regex issue * extended password special char set * rebased * updated test case * added rgmz suggested regex * updated regex
1 parent 7185b31 commit d010607

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

pkg/detectors/privacy/privacy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package privacy
33
import (
44
"context"
55
"fmt"
6-
regexp "github.com/wasilibs/go-re2"
76
"net/http"
87
"strings"
98

9+
regexp "github.com/wasilibs/go-re2"
10+
1011
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1112
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1213
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"

pkg/detectors/uri/uri.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var _ interface {
3030
} = (*Scanner)(nil)
3131

3232
var (
33-
keyPat = regexp.MustCompile(`\b(?:https?:)?\/\/[\S]{3,50}:([\S]{3,50})@[-.%\w\/:]+\b`)
33+
keyPat = regexp.MustCompile(`\bhttps?:\/\/[\w!#$%&()*+,\-./;<=>?@[\\\]^_{|}~]{0,50}:([\w!#$%&()*+,\-./:;<=>?[\\\]^_{|}~]{3,50})@[a-zA-Z0-9.-]+(?:\.[a-zA-Z]{2,})?(?::\d{1,5})?[\w/]+\b`)
3434

3535
// TODO: make local addr opt-out
3636
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
@@ -131,6 +131,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
131131
continue
132132
}
133133
}
134+
134135
results = append(results, r)
135136
}
136137

pkg/detectors/uri/uri_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
var (
1515
validPattern = "https://kaNydBSAodo87dsm9asuiSAFtsd7.com:1234@qYY3SylY7fHP"
16+
validPattern2 = `<p><a href="http://username:[email protected]">http://username:[email protected]</a></p>`
1617
invalidPattern = "https://kaNydBSAodo87dsm9asuiSAFtsd7.com.1234@qYY3SylY7fHP"
1718
keyword = "uri"
1819
)
@@ -30,6 +31,11 @@ func TestURI_Pattern(t *testing.T) {
3031
input: fmt.Sprintf("%s token = '%s'", keyword, validPattern),
3132
want: []string{validPattern},
3233
},
34+
{
35+
name: "valid pattern - do not process duplicate",
36+
input: fmt.Sprintf("%s token = '%s'", keyword, validPattern2),
37+
want: []string{"http://username:[email protected]"},
38+
},
3339
{
3440
name: "invalid pattern",
3541
input: fmt.Sprintf("%s = '%s'", keyword, invalidPattern),

0 commit comments

Comments
 (0)