Skip to content

gh-155694: Scope HTTPPasswordMgr credentials by URL scheme - #155696

Open
lkk7 wants to merge 3 commits into
python:mainfrom
lkk7:fix-http-password-mgr-scheme
Open

gh-155694: Scope HTTPPasswordMgr credentials by URL scheme#155696
lkk7 wants to merge 3 commits into
python:mainfrom
lkk7:fix-http-password-mgr-scheme

Conversation

@lkk7

@lkk7 lkk7 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #155694.

Scope HTTPPasswordMgr credentials by URL scheme. This prevents a situation where credentials stored for an HTTPS URL match a corresponding HTTP URL. URIs without a scheme will still match any scheme.

@read-the-docs-community

read-the-docs-community Bot commented Aug 13, 2026

Copy link
Copy Markdown

@Eclips4 Eclips4 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment thread Lib/urllib/request.py
return (scheme or None, *self.reduce_uri(uri, default_port))

def _is_suburi_with_scheme(self, base, test):
if (base[0] is not None and test[0] is not None and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only compares the scheme if both are non-None, is that correct? Or should it check the scheme regardless of whether each is None?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's intentional, both None cases matter.
test[0] is not None needed here because of ProxyBasicAuthHandler.http_error_407 which queries by req.host.

Maybe it's makes sense to add this to add_password documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it to the documentation. I'll fully understand if you'll say that the two sentences are confusing.

If a URI includes a scheme, its credentials only match authentication URIs with the same scheme or no scheme.
A URI without a scheme matches authentication URIs with any scheme.

Feel free to edit it yourself or post a suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTPPasswordMgr can send saved HTTPS credentials via HTTP because of incorrect scheme matching

3 participants