Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix(ftp): set read deadline on connection to prevent indefinite hang (#4759)
dylanTrufflee3cbb3afc66d
diff --git a/pkg/detectors/ftp/ftp.go b/pkg/detectors/ftp/ftp.goindex c9c751e9d..1be552067 100644--- a/pkg/detectors/ftp/ftp.go+++ b/pkg/detectors/ftp/ftp.go@@ -3,6 +3,7 @@ package ftpimport ("context""errors"+ "net""net/textproto""net/url""strings"@@ -128,7 +129,20 @@ func verifyFTP(timeout time.Duration, u *url.URL) error {host = host + ":21"}- c, err := ftp.Dial(host, ftp.DialWithTimeout(timeout))+ // Use a custom dial function that sets a deadline on the connection so that+ // the FTP banner read and login are also bounded by the timeout. Without this,+ // a server that accepts TCP but never sends a banner will block indefinitely.+ c, err := ftp.Dial(host, ftp.DialWithDialFunc(func(network, address string) (net.Conn, error) {+ conn, err := net.DialTimeout(network, address, timeout)+ if err != nil {+ return nil, err+ }+ if err := conn.SetDeadline(time.Now().Add(timeout)); err != nil {+ conn.Close()+ return nil, err+ }+ return conn, nil+ }))if err != nil {return err}