DEV Community

yutianle
yutianle

Posted on

Perl Net::FTP PASV handling lets a server choose the client's next connection

Perl Net::FTP PASV handling lets a server choose the client's next connection

Passive FTP can sound like a server-side convenience: the client asks the server for a data port and connects to it. CVE-2026-40558 shows why the client must still constrain that connection. In Perl's Net::FTP before libnet 3.17, the pasv method uses the IP address in the server's 227 reply for the data connection and does not compare it with the control connection's peer. A malicious FTP server can therefore make the client open TCP connections to arbitrary hosts and ports, including addresses reachable only from the client.

The CNA classifies the issue as CWE-918, server-side request forgery, in the context of a client library. The label is useful even though the vulnerable code is a client. The trust decision is being made on the wrong side of the network boundary. The FTP server controls the destination, while the client's network position controls what can be reached. A worker that is allowed to reach an internal database or metadata service can be turned into a relay without the FTP server ever receiving a direct connection to that service.

The affected package is libnet before 3.17. The CVE record also lists Perl core versions through 5.45.5 as affected because they ship a vulnerable cpan/libnet/lib/Net/FTP.pm. This matters for application inventories that check only CPAN modules and forget the copy bundled with the Perl interpreter. A host can appear to have a patched module elsewhere on disk while the application loads the core version first.

Upgrade to libnet 3.17 or later and verify @INC resolution. The fix described in the release notes ignores the IP address in the 227 reply and connects the data channel back to the control-connection peer. Test with the actual interpreter and a small FTP server that returns a mismatched address. Inspect $Net::FTP::VERSION and the resolved module path in the application process. A package manager can show an updated RPM or DEB while a locally installed Perl tree hides it.

Network policy should reduce the blast radius. FTP clients are often deployed inside batch workers that can reach many internal services. Restrict the worker to the FTP servers and application endpoints it needs. Block cloud metadata, link-local addresses, and management subnets from the FTP client's network context. Log the destination address chosen from the PASV response and the peer address used for the control channel. A mismatch is a useful detection signal.

Code using Net::FTP should also enforce application-level expectations. If the service is supposed to fetch from a named partner, compare that identity with the control peer and the certificate or IP policy, not only with the URL in a configuration file. Disable active mode unless it is required, set timeouts, cap download sizes, and close failed sockets promptly. A blocked data connection should not leave a process hanging indefinitely.

This issue is not a reason to assume every FTP transfer is malicious. It is a reminder that FTP has two connections and the server can influence both. Patch the library, verify which copy Perl loads, and put a destination-aware egress policy around the worker. That combination makes a malicious server unable to use the client as a path into the internal network.

References

Top comments (0)