Skip to content

Percent-decode userinfo in URL credentials (#1623) - #1943

Open
CAOShurong wants to merge 1 commit into
httpie:masterfrom
CAOShurong:fix/url-userinfo-percent-decode
Open

Percent-decode userinfo in URL credentials (#1623)#1943
CAOShurong wants to merge 1 commit into
httpie:masterfrom
CAOShurong:fix/url-userinfo-percent-decode

Conversation

@CAOShurong

Copy link
Copy Markdown

Summary

Fixes #1623. urlsplit() leaves the userinfo percent-encoded, so a URL like

https://u%40d:1%3d2%3f@example.org/basic-auth/u%40d/1%3d2%3f

was authenticated with the literal username u%40d (and a wrong password) instead of u@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.password were used verbatim. Python's urllib.parse.urlsplit does not percent-decode userinfo, so u%40d stayed u%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)

  • Reproduced on main: urlsplit(...).username == "u%40d".
  • Added regression test test_credentials_in_url_are_percent_decoded (4 cases).
  • RED on main (percent-encoded cases fail), GREEN with fix.
  • Full 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).

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Username/password in the URL not decoded when used for basic authentication

1 participant