You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SSL_KEYWORDS is missing assert_hostname and assert_fingerprint, leaking HTTPS-only kwargs into HTTP connection construction #5077
PoolManager._new_pool strips SSL-only kwargs from connection-pool
kwargs when creating an HTTP pool, via the SSL_KEYWORDS allowlist.
That list is missing assert_hostname and assert_fingerprint, both
of which are HTTPS-only (declared as named parameters on HTTPSConnection.__init__, rejected by HTTPConnection.__init__).
When a caller sets either on PoolManager.connection_pool_kw and then
issues a plain-HTTP request, the kwarg leaks past the filter into HTTPConnection.__init__, which raises a TypeError.
Adding both to SSL_KEYWORDS fixes it, matching the existing intent
of the filter.
importurllib3defshow(kwarg: str) ->None:
pool=urllib3.PoolManager()
pool.connection_pool_kw[kwarg] =Falseprint(f"--- connection_pool_kw[{kwarg!r}] = False, GET http://...")
try:
pool.request("GET", "http://127.0.0.1:1/", retries=False, timeout=0.1)
exceptTypeErrorasexc:
print(f" TypeError: {exc}")
exceptExceptionasexc:
print(f" {type(exc).__name__}: {exc}")
print()
if__name__=="__main__":
print(f"urllib3 version: {urllib3.__version__}\n")
# Both leak; both should be in SSL_KEYWORDS.show("assert_hostname")
show("assert_fingerprint")
# For contrast: cert_reqs IS in SSL_KEYWORDS, gets stripped correctly.show("cert_reqs")
Expected Behavior
A PoolManager with assert_hostname or assert_fingerprint set on connection_pool_kw should successfully dispatch to plain-HTTP URLs.
Those kwargs should be stripped before reaching HTTPConnection.__init__, the same way cert_reqs, ca_certs, and
the rest of SSL_KEYWORDS already are.
Actual Behavior
HTTPConnection.__init__ raises TypeError:
TypeError: HTTPConnection.__init__() got an unexpected keyword argument 'assert_hostname'
The same happens for assert_fingerprint. For comparison, kwargs
already in SSL_KEYWORDS (e.g. cert_reqs) are correctly stripped
and the request proceeds to the network leg.
--- connection_pool_kw['assert_hostname'] = False, GET http://...
TypeError: HTTPConnection.__init__() got an unexpected keyword argument 'assert_hostname'
--- connection_pool_kw['assert_fingerprint'] = False, GET http://...
TypeError: HTTPConnection.__init__() got an unexpected keyword argument 'assert_fingerprint'
--- connection_pool_kw['cert_reqs'] = False, GET http://...
NewConnectionError: HTTPConnection(host='127.0.0.1', port=1): Failed to establish a new connection: [Errno 61] Connection refused
Activity