Skip to content

SSL_KEYWORDS is missing assert_hostname and assert_fingerprint, leaking HTTPS-only kwargs into HTTP connection construction #5077

Closed
michael-schvarcz/urllib3
#4

Description

@cipherself

Subject

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.

Environment

>>> OS macOS-26.3.1-arm64-arm-64bit-Mach-O
>>> Python 3.14.5
>>> OpenSSL 3.6.2 7 Apr 2026
>>> urllib3 2.7.0

Steps to Reproduce

import urllib3


def show(kwarg: str) -> None:
    pool = urllib3.PoolManager()
    pool.connection_pool_kw[kwarg] = False
    print(f"--- connection_pool_kw[{kwarg!r}] = False, GET http://...")
    try:
        pool.request("GET", "http://127.0.0.1:1/", retries=False, timeout=0.1)
    except TypeError as exc:
        print(f"  TypeError: {exc}")
    except Exception as exc:
        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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions