Title: Direct HTTP 407 can receive HTTPS-scoped credentials · Issue #158907 · python/cpython · GitHub
Open Graph Title: Direct HTTP 407 can receive HTTPS-scoped credentials · Issue #158907 · python/cpython
X Title: Direct HTTP 407 can receive HTTPS-scoped credentials · Issue #158907 · python/cpython
Description: ProxyBasicAuthHandler may send HTTPS-scoped credentials to a direct HTTP origin after a 407 response Summary When an application explicitly installs ProxyBasicAuthHandler with an HTTPPasswordMgr containing credentials scoped to https://H...
Open Graph Description: ProxyBasicAuthHandler may send HTTPS-scoped credentials to a direct HTTP origin after a 407 response Summary When an application explicitly installs ProxyBasicAuthHandler with an HTTPPasswordMgr co...
X Description: ProxyBasicAuthHandler may send HTTPS-scoped credentials to a direct HTTP origin after a 407 response Summary When an application explicitly installs ProxyBasicAuthHandler with an HTTPPasswordMgr co...
Opengraph URL: https://github.com/python/cpython/issues/158907
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Direct HTTP 407 can receive HTTPS-scoped credentials","articleBody":"# ProxyBasicAuthHandler may send HTTPS-scoped credentials to a direct HTTP origin after a 407 response\n\n## Summary\n\nWhen an application explicitly installs `ProxyBasicAuthHandler` with an `HTTPPasswordMgr` containing credentials scoped to `https://HOST/`, a direct (non-proxied) HTTP server at the same authority can return `407 Proxy Authentication Required` with the matching realm. `ProxyBasicAuthHandler.http_error_407()` looks up credentials using `req.host`, which is scheme-less. `HTTPPasswordMgr` intentionally allows a scheme-less lookup to match credentials stored for any scheme, so the handler retries the direct HTTP request with a `Proxy-Authorization: Basic ...` header. The direct origin receives the HTTPS-scoped password in cleartext.\n\nThis requires a non-default opener configuration (the application must register `ProxyBasicAuthHandler`), a credential entry for the same authority at the root path, and a direct HTTP request to that authority. With a regular `HTTPPasswordMgr`, the server must know/challenge the configured realm. This does not describe normal proxy authentication: in a genuine proxy request `req.host` is the proxy authority.\n\n## Details\n\nIn `Lib/urllib/request.py`, `ProxyBasicAuthHandler.http_error_407()` passes `req.host` to `http_error_auth_reqed()`. For a direct HTTP request, that is the origin authority, without `http://`. The scheme-aware matching added for CVE-2026-15806 only rejects mismatches when both URIs have a scheme; `None` continues to match any scheme. The resulting credentials are placed in `Proxy-Authorization` and sent on the retry. The header is visible to the direct HTTP origin.\n\nThe relevant code is present in CPython 3.12.15 and remained present on the 3.12 branch checked at commit `58ed60b7415e218ce3d608302e39b5e55bfb0e88` (2026-10-01). The `Lib/urllib/request.py` blob in the 3.12.15 snapshot is `6320598c3ceda64addd0a0871b195ea6da21a7cf`, matching the current 3.12 branch file. The 3.12.15 tests document scheme-less matching, but do not cover a direct-origin 407 handled by `ProxyBasicAuthHandler`.\n\nThis appears distinct from the original CVE-2026-15806 trigger (ordinary HTTP authentication matching an HTTPS credential): it is a residual path through the explicitly registered proxy-auth handler. The original fix's PR #155696 explicitly preserves scheme-less wildcard matching and has no regression test for a direct 407 response.\n\n## Reproducer\n\nThe following local-only server acts as a direct HTTP origin, not as a proxy. It first sends a 407 challenge, then records the retry header.\n\n```python\nfrom http.server import BaseHTTPRequestHandler, HTTPServer\nfrom threading import Thread\nfrom urllib.request import (\n HTTPPasswordMgr, ProxyBasicAuthHandler, ProxyHandler, build_opener,\n)\n\nseen = []\n\nclass Handler(BaseHTTPRequestHandler):\n def do_GET(self):\n seen.append(self.headers.get(\"Proxy-Authorization\"))\n if len(seen) == 1:\n self.send_response(407)\n self.send_header(\"Proxy-Authenticate\", 'Basic realm=\"test-realm\"')\n self.end_headers()\n else:\n self.send_response(200)\n self.end_headers()\n self.wfile.write(b\"ok\")\n\n def log_message(self, *args):\n pass\n\nserver = HTTPServer((\"127.0.0.1\", 0), Handler)\nThread(target=server.serve_forever, daemon=True).start()\nurl = f\"http://127.0.0.1:{server.server_port}/resource\"\nhttps_scope = f\"https://127.0.0.1:{server.server_port}/\"\n\npasswords = HTTPPasswordMgr()\npasswords.add_password(\"test-realm\", https_scope, \"victim-user\", \"victim-secret\")\nopener = build_opener(\n ProxyHandler({}), # explicitly no proxy\n ProxyBasicAuthHandler(passwords),\n)\nwith opener.open(url, timeout=3) as response:\n print(response.status, response.read())\nprint(seen)\nserver.shutdown()\n```\n\nObserved on Python 3.12.13 with the CPython 3.12.15 snapshot's `Lib` (the tested `urllib/request.py` blob matches the current 3.12 branch):\n\n```text\n200 b'ok'\n[None, 'Basic dmljdGltLXVzZXI6dmljdGltLXNlY3JldA==']\n```\n\nThe second value decodes to `victim-user:victim-secret` and was captured by the direct HTTP origin.\n\n## Impact\n\nA peer able to answer the application's direct plaintext HTTP request to the same authority can receive credentials the caller registered specifically for HTTPS. This is a confidentiality impact. It is conditional on explicit proxy-auth handler configuration and same-authority/root-scope credential overlap; the default opener is not affected because it does not install `ProxyBasicAuthHandler`.\n\n## Suggested fix / regression test\n\nEnsure a 407 challenge is handled as proxy authentication only when the request is actually being made through a proxy, or otherwise retain enough transport/credential-scope information to prevent a direct HTTP origin from matching HTTPS-scoped credentials. Add a regression test where a direct HTTP origin returns 407 while the password manager contains HTTPS-scoped credentials for that authority; assert that no `Proxy-Authorization` header is sent to the origin. Keep tests for genuine proxy authentication working.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158956\n* gh-161919\n* gh-161920\n* gh-161921\n* gh-161922\n* gh-161923\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/bupt-Yy-young","@type":"Person","name":"bupt-Yy-young"},"datePublished":"2026-10-06T12:22:56Z","url":"https://github.com/python/cpython/issues/158907"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7fc422ad-c3e8-619f-5b24-315806b80c01 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6A0:3E418A:20097D7:29F3DD8:6B023684 |
| html-safe-nonce | a4672b9ce00fb4a3b83c67e3939d18c6d6d3f850e0d106fbe66c5e977f35e17d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkEwOjNFNDE4QToyMDA5N0Q3OjI5RjNERDg6NkIwMjM2ODQiLCJ2aXNpdG9yX2lkIjoiNzg4NjM3Nzk5Mjg4MDI2NzU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e0394feef91feaeaac6c921a27498fc5c574b2812dd79f51156d059e0da77088 |
| hovercard-subject-tag | issue:5728288147 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158907/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25e95f08767a90286b8eb536eb56f446b45d62fe77df4cf6f4d585f07464de43/python/cpython/issues/158907 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25e95f08767a90286b8eb536eb56f446b45d62fe77df4cf6f4d585f07464de43/python/cpython/issues/158907 |
| og:image:alt | ProxyBasicAuthHandler may send HTTPS-scoped credentials to a direct HTTP origin after a 407 response Summary When an application explicitly installs ProxyBasicAuthHandler with an HTTPPasswordMgr co... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bupt-Yy-young |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width