Skip to content

gh-87451: Apply CVE-2021-4189 PASV fix to ftplib.ftpcp()#149648

Merged
gpshead merged 4 commits into
python:mainfrom
gpshead:gh-87451-ftplib-ftpcp
May 13, 2026
Merged

gh-87451: Apply CVE-2021-4189 PASV fix to ftplib.ftpcp()#149648
gpshead merged 4 commits into
python:mainfrom
gpshead:gh-87451-ftplib-ftpcp

Conversation

@gpshead
Copy link
Copy Markdown
Member

@gpshead gpshead commented May 10, 2026

ftpcp() called parse227() directly and passed the source server's self-reported PASV IPv4 address to the target server's PORT command, bypassing the CVE-2021-4189 fix that was applied only to FTP.makepasv(). A malicious source FTP server could use this to redirect the target server's data connection to an arbitrary host:port (SSRF).

ftpcp() now uses the source server's actual peer address, honoring the existing trust_server_pasv_ipv4_address opt-out, the same as makepasv().

Thanks to Qi Deng at Aurascape AI for the report. (GHSA-w8c5-q2xf-gf7c)

ftpcp() called parse227() directly and passed the source server's
self-reported PASV IPv4 address to the target server's PORT command,
bypassing the CVE-2021-4189 fix that was applied only to FTP.makepasv().
A malicious source FTP server could use this to redirect the target
server's data connection to an arbitrary host:port (SSRF).

ftpcp() now uses the source server's actual peer address, honoring the
existing trust_server_pasv_ipv4_address opt-out, the same as makepasv().

Thanks to Qi Ding (AKA ikow) for the report.
@gpshead gpshead requested a review from giampaolo as a code owner May 10, 2026 18:21
@gpshead gpshead added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes type-security A security issue and removed awaiting core review labels May 10, 2026
@read-the-docs-community
Copy link
Copy Markdown

@gpshead gpshead self-assigned this May 10, 2026
@gpshead gpshead requested a review from picnixz May 10, 2026 20:15
Comment thread Lib/test/test_ftplib.py Outdated
gpshead added 2 commits May 13, 2026 09:47
…pcp test

Replace the _Fake* helper classes in TestFtpcpSecurity with mock.Mock
objects spec'd against ftplib.FTP. The spec gives a real-API check that
ftpcp() only touches attributes that exist on FTP, and a keyword-only
_make_pair() helper keeps the call sites self-documenting.
@gpshead gpshead enabled auto-merge (squash) May 13, 2026 16:59
@gpshead gpshead merged commit eac4fe3 into python:main May 13, 2026
52 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11, 3.12, 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 13, 2026

GH-149792 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 13, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 13, 2026

GH-149793 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 13, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 13, 2026

GH-149794 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label May 13, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 13, 2026

GH-149795 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label May 13, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 13, 2026

GH-149796 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label May 13, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 13, 2026

GH-149797 is a backport of this pull request to the 3.10 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.10 only security fixes label May 13, 2026
gpshead added a commit that referenced this pull request May 13, 2026
…49648) (#149794)

gh-87451: Apply CVE-2021-4189 PASV fix to ftplib.ftpcp() (GH-149648)

ftpcp() called parse227() directly and passed the source server's
self-reported PASV IPv4 address to the target server's PORT command,
bypassing the CVE-2021-4189 fix that was applied only to FTP.makepasv().
A malicious source FTP server could use this to redirect the target
server's data connection to an arbitrary host:port (SSRF).

ftpcp() now uses the source server's actual peer address, honoring the
existing trust_server_pasv_ipv4_address opt-out, the same as makepasv().

Thanks to Qi Ding at Aurascape AI for the report. (GHSA-w8c5-q2xf-gf7c)
(cherry picked from commit eac4fe3)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gpshead added a commit that referenced this pull request May 13, 2026
…49648) (#149793)

gh-87451: Apply CVE-2021-4189 PASV fix to ftplib.ftpcp() (GH-149648)

ftpcp() called parse227() directly and passed the source server's
self-reported PASV IPv4 address to the target server's PORT command,
bypassing the CVE-2021-4189 fix that was applied only to FTP.makepasv().
A malicious source FTP server could use this to redirect the target
server's data connection to an arbitrary host:port (SSRF).

ftpcp() now uses the source server's actual peer address, honoring the
existing trust_server_pasv_ipv4_address opt-out, the same as makepasv().

Thanks to Qi Ding at Aurascape AI for the report. (GHSA-w8c5-q2xf-gf7c)
(cherry picked from commit eac4fe3)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-security A security issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants