Skip some FTP FPs (#929)

This commit is contained in:
Dustin Decker 2022-11-21 06:52:21 -08:00 committed by GitHub
parent 9757c339d9
commit b45369cdbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View file

@ -50,12 +50,17 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if _, ok := parsedURL.User.Password(); !ok {
continue
}
if parsedURL.User.Username() == "anonymous" {
continue
}
redact := strings.TrimSpace(strings.Replace(urlMatch, password, strings.Repeat("*", len(password)), -1))
rawURL, _ := url.Parse(urlMatch)
rawURL.Path = ""
redact := strings.TrimSpace(strings.Replace(rawURL.String(), password, "********", -1))
s := detectors.Result{
DetectorType: detectorspb.DetectorType_FTP,
Raw: []byte(urlMatch),
Raw: []byte(rawURL.String()),
Redacted: redact,
}
@ -70,7 +75,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
}
if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, false) {
if detectors.IsKnownFalsePositive(string(s.Raw), []detectors.FalsePositive{"@ftp.freebsd.org"}, false) {
continue
}

View file

@ -12,7 +12,7 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
)
func TestURI_FromChunk(t *testing.T) {
func TestFTP_FromChunk(t *testing.T) {
type args struct {
ctx context.Context
data []byte
@ -71,6 +71,16 @@ func TestURI_FromChunk(t *testing.T) {
},
wantErr: false,
},
{
name: "blocked FP",
s: Scanner{},
args: args{
ctx: context.Background(),
data: []byte("ftp://abc:123@ftp.freebsd.org/pub/FreeBSD/doc/tr/articles/explaining-bsd/explaining-bsd_tr.pdf"),
verify: true,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View file

@ -50,7 +50,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
continue
}
redact := strings.TrimSpace(strings.Replace(urlMatch, password, strings.Repeat("*", len(password)), -1))
redact := strings.TrimSpace(strings.Replace(urlMatch, password, "********", -1))
s := detectors.Result{
DetectorType: detectorspb.DetectorType_Redis,

View file

@ -71,8 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
rawURL, _ := url.Parse(urlMatch)
rawURL.Path = ""
redact := strings.TrimSpace(strings.Replace(rawURL.String(), password, strings.Repeat("*", len(password)), -1))
redact := strings.TrimSpace(strings.Replace(rawURL.String(), password, "********", -1))
s := detectors.Result{
DetectorType: detectorspb.DetectorType_URI,