Skip to content

Find, verify, and analyze leaked credentials

[INS-37] Fixed the issue of ftp connection ignoring the detector's co… (#4590)

Muneeb Ullah Khan83235ddfbb0e
diff --git a/pkg/detectors/ftp/ftp.go b/pkg/detectors/ftp/ftp.go
index dff83faba..c9c751e9d 100644
--- a/pkg/detectors/ftp/ftp.go
+++ b/pkg/detectors/ftp/ftp.go
@@ -78,8 +78,15 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
if verify {
- timeout := s.verificationTimeout
- if timeout == 0 {
+ var timeout time.Duration
+ if s.verificationTimeout > 0 {
+ // Use to configure a simulate timeout for interation tests
+ timeout = s.verificationTimeout
+ } else if dl, ok := ctx.Deadline(); ok {
+ // Here we assign the remaining time before our context expires
+ // This help us cater the timelimit set through --detector-timeout flag
+ timeout = time.Until(dl)
+ } else {
timeout = defaultVerificationTimeout
}
verificationErr := verifyFTP(timeout, parsedURL)
@@ -126,6 +133,9 @@ func verifyFTP(timeout time.Duration, u *url.URL) error {
return err
}
+ defer func() {
+ _ = c.Quit()
+ }()
password, _ := u.User.Password()
return c.Login(u.User.Username(), password)
}
diff --git a/pkg/detectors/ftp/ftp_integration_test.go b/pkg/detectors/ftp/ftp_integration_test.go
index ce4a3db33..2e546945b 100644
--- a/pkg/detectors/ftp/ftp_integration_test.go
+++ b/pkg/detectors/ftp/ftp_integration_test.go
@@ -149,7 +149,7 @@ func TestFTP_FromChunk(t *testing.T) {
t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError())
}
}
- opts := cmpopts.IgnoreFields(detectors.Result{}, "verificationError")
+ opts := cmpopts.IgnoreFields(detectors.Result{}, "verificationError", "primarySecret")
if diff := cmp.Diff(got, tt.want, opts); diff != "" {
t.Errorf("FTP.FromData() %s diff: (-got +want)\n%s", tt.name, diff)
}