Conversation
urllib.parse.urlparse() returns the raw (percent-encoded) userinfo components rather than decoded strings. parse_proxy() was passing those raw values straight through to Proxy.username / Proxy.password, so a credential such as p%40ss was sent to the proxy server instead of the intended p@ss. Fix by applying urllib.parse.unquote() to both components immediately after urlparse(). This matches the behaviour of python-socks (_helpers.parse_proxy_url) and requests, which both unquote proxy userinfo before using it. Also remove the urllib.parse.quote() call in the IRI branch: Proxy should always store plain (decoded) credentials; encoding them back was incorrect because build_authorization_basic() and python-socks both expect decoded strings. Tests: add two percent-encoded cases to PROXIES_WITH_USER_INFO and update the existing non-ASCII IRI case to expect decoded credentials. Fixes python-websockets#1761
Member
|
Hello, could you clarify how this PR accounts for my spec of what needs to be done to solve the issue. It seems that you've only solved a small subset. If everything else is actually OK, can you provide the evidence? Please just don't throw an AI at my comment; I have an AI, and I'd rather run it myself than through you. |
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.
Fixes #1761.
Problem
parse_proxy()usesurllib.parse.urlparse()to extract the userinfocomponents, but
urlparsereturns the raw, still-percent-encoded stringsfor
usernameandpassword. A proxy URL like(where the password is
p@ss, percent-encoded because@is a reservedcharacter in the authority component) produced:
The encoded string
p%40sswas then:build_authorization_basic()for HTTP CONNECTproxies, producing a wrong
Proxy-Authorizationheader (HTTP 407);connection because its own credential comparison expected the decoded form
(
ProxyError: failed to connect to SOCKS proxy).This is a regression relative to python-socks itself (
_helpers.parse_proxy_urlcalls
unquote()on both fields) andrequests(same).Fix
Apply
urllib.parse.unquote()tousernameandpasswordimmediately afterurlparse(), soProxyalways stores plain (decoded) credentials.Also remove the
urllib.parse.quote()re-encoding in the IRI branch: thatblock was encoding non-ASCII credentials back into percent-encoded form and
storing them in
Proxy, which was equally wrong because bothbuild_authorization_basic()and python-socks expect decoded strings.Tests
PROXIES_WITH_USER_INFO:socks5://alice:p%40ss@proxy→("alice", "p@ss")socks5://alice%3Abob:secret%25word@proxy→("alice:bob", "secret%word")(
("üser", "påss")instead of("%C3%BCser", "p%C3%A5ss")).