PSF-2026-24: FTP PASV SSRF, ftpcp() does not use actual peer address, trusts server-supplied PASV host address
The ftpcp() function in Lib/ftplib.py was not updated when CVE-2021-4189 was fixed. While makepasv() was patched to replace server-supplied PASV host addresses with the actual peer address (getpeername()[0]), ftpcp() still calls parse227() directly and passes the raw attacker-controllable IP address and port to target.sendport(). This patch is related to CVE-2021-4189.
Affected Software
Event History
Frequently Asked Questions
What conditions are required to exploit this issue?
An attacker must be able to act as, or control, the FTP server used by an application that calls ftpcp(). They can supply a PASV response containing an attacker-controlled IP address and port, which ftpcp() passes to target.sendport().
Which code path is affected, and is the existing PASV hardening sufficient?
The affected path is ftpcp() in Lib/ftplib.py. The makepasv() hardening that substitutes the actual FTP peer address does not protect ftpcp(), because ftpcp() directly calls parse227() and uses the server-supplied address.
How can an organization determine whether it is exposed?
Review applications that use Python's ftplib.ftpcp() function, particularly where the FTP server endpoint may be untrusted or attacker-controlled. Uses limited to trusted FTP servers do not remove the vulnerable behavior, but reduce the opportunity for an attacker to provide a malicious PASV response.