Repository navigation
tunnel FTPHTTPClient PASV data connection to the FTP host, not the proxy - #416
Open
Sahana2524 wants to merge 1 commit into
Open
Sahana2524 wants to merge 1 commit into
Sahana2524 wants to merge 1 commit into
Conversation
Since 3.9.0, _parsePassiveModeReply ignores the PASV reply address by default and uses the control socket's peer instead. In FTPHTTPClient that peer is the HTTP proxy, so the data connection was tunneled with CONNECT <proxy-address>:<port>, the port being chosen by the FTP server. Use the FTP host given to connect() unless the legacy ipAddressFromPasvResponse flag is set, and only record tunnelHost in connect() so a data tunnel cannot overwrite it.
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.
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.Since 3.9.0 (the CVE-2021-37533 change),
_parsePassiveModeReplyignores the address in the PASV reply by default and uses_socket_.getInetAddress()instead. That is correct forFTPClient, but inFTPHTTPClientthe control socket is connected to the HTTP proxy, so the substituted address is the proxy itself._openDataConnection_then sends:where the port comes from the FTP server's
227reply. IPv4 PASV is the default path here, since EPSV is only tried for IPv6 or withsetUseEPSVwithIPv4(true).Two consequences:
FTPHTTPClientgo to the wrong host by default.STORthe client streams file data into that socket. This is a server-side request forgery through the proxy (CWE-918), and the FTP server should not get to choose a destination other than itself.The fix uses the host given to
connect()(the existingtunnelHostfield, already used for EPSV) as the PASV target, and keeps the PASV reply address only when the legacyipAddressFromPasvResponseflag is set, matching whatFTPClientdoes.tunnelHostis now set inconnect()rather than intunnelHandshake(), so a data tunnel built in legacy mode can no longer overwrite the control host that later EPSV transfers rely on.FTPHTTPClientTestruns a small fake proxy that tunnels the control connection, answers PASV with(10,1,2,3,4,1), and records the secondCONNECTline. Without the fix it isCONNECT 127.0.0.1:1025(the proxy address); with it,CONNECT ftp.example.invalid:1025. The defaultmvnbuild passes locally on JDK 21.