Percent-decode userinfo in URL credentials (#1623) - #1943
Open
CAOShurong wants to merge 1 commit into
Open
Conversation
urlsplit() leaves the userinfo percent-encoded, so a URL like https://u%40d:1%3d2%3f@example.org was authenticated with the literal username 'u%40d' instead of 'u@d' (and a wrong password), causing spurious 401s. Reserved characters simply could not be supplied in the URL. URL-decode username and password extracted from the netloc (unquote) so behavior matches curl. Plain (non-encoded) credentials are unaffected; added a regression test. AI assistance disclosed: drafted with an LLM coding agent, verified locally (RED on main, GREEN with fix; full test_auth.py 33 passed).
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.
Summary
Fixes #1623.
urlsplit()leaves the userinfo percent-encoded, so a URL likewas authenticated with the literal username
u%40d(and a wrong password) instead ofu@d, producing spurious 401s. Reserved characters simply could not be supplied directly in the URL.Root cause
In
_process_auth(httpie/cli/argparser.py),url.username/url.passwordwere used verbatim. Python'surllib.parse.urlsplitdoes not percent-decode userinfo, sou%40dstayedu%40d.Fix
URL-decode the username and password extracted from the netloc with
unquote(). Behavior now matches curl. Plain (non-encoded) credentials are unaffected.Verification (no run no claim)
main:urlsplit(...).username == "u%40d".test_credentials_in_url_are_percent_decoded(4 cases).main(percent-encoded cases fail), GREEN with fix.tests/test_auth.py: 33 passed;tests/test_auth_plugins.py: 4 passed. No regression.AI assistance disclosed: drafted with an LLM coding agent, then independently verified locally (RED→GREEN).