Repository navigation
2.7.18.16: ftplib.ftpcp() trusts the PASV host (CVE-2026-8328) - #94
Merged
Merged
Conversation
…026-8328) Backport of python/cpython pythongh-87451 (3.15 5dadc64). 2.7.18.x already carries the CVE-2021-4189 fix in FTP.makepasv(): it ignores the IPv4 address a server advertises in its PASV reply and uses the control connection's peer address unless trust_server_pasv_ipv4_address is set. ftpcp() still called parse227() directly and passed the server-supplied host to target.sendport(), so a malicious source server could point the target's data connection at an arbitrary host:port (SSRF). ftpcp() now applies the same rule. 2.7.18.x: no unittest.mock in 2.7, so TestFtpcpSecurity uses small fake FTP/socket classes; % formatting instead of f-strings; the class is added to test_main(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
ezequielp-activestate
approved these changes
Oct 28, 2026
ezequielp-activestate
left a comment
There was a problem hiding this comment.
No blockers.
- Fix matches upstream. The new
ftpcp()code is line-for-line upstream pythongh-87451 (eac4fe3). There are no later upstream changes toftpcp(). - Repro: a source server whose PASV reply advertises
10.0.0.99while its real peer address is203.0.113.5:- Base:
target.sendport('10.0.0.99', 1930). - This branch:
target.sendport('203.0.113.5', 1930).
- Base:
- Tests:
test_ftplibon this branch: 85 run. The 2 failures and 1 error (test_source_address,test_source_address_passive_connection,test_with_statement) are identical on the base, which runs 83.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of python/cpython pythongh-87451 (CVE-2026-8328, PSF-2026-24) to 2.7.18.x.
Problem: 2.7.18.x already has the CVE-2021-4189 fix in
FTP.makepasv(), butftpcp()still passed the host from the source server's PASV reply straight totarget.sendport(). A malicious source server could therefore redirect the target's data connection to any host:port (SSRF).Fix:
ftpcp()now follows the same rule asmakepasv(). It uses the source's real peer address unlesstrust_server_pasv_ipv4_addressis set.Test:
TestFtpcpSecurity. Python 2.7 has nounittest.mock, so the test uses small fake FTP objects.test_ftpcp_ignores_untrusted_pasv_hostfails on 2.7.18.15 and passes with the fix. The other 6test_ftplibfailures are the existing source-address and with-statement failures from my local environment, and they happen with or without this change.Part of 2.7.18.16. It targets the
2.7.18.16integration branch.