requests icon indicating copy to clipboard operation
requests copied to clipboard

Session adapter doesn't update https connections cert data

Open aleperno opened this issue 9 years ago • 4 comments

Under a session, the first https request sets the HTTPSConnectionPool certs data. If in a subsequent request, we change the certs data (eg: Set verify to True), the adaptor will update the ConnectionPool attributes, however each connection in the pool will still contain the old certs data, thus when requesting a connection from the pool, its info will differ from what we would expect.

Expected Result

The used connection should have updated certs data

Actual Result

The used connection have "old" certs data.

Reproduction Steps

These tests where performed against a server with a self-signed CA.

In [1]: from requests import Session

In [2]: url = "https://somepage"

In [3]: auth = ("admin", "admin123")

In [4]: s = Session()

In [5]: s.get(url, auth=auth, verify=False)

Out[5]: <Response [200]>

# This should fail, but doesnt
In [6]: s.get(url, auth=auth, verify=True)

Out[6]: <Response [200]>

# Create a new session
In [7]: Session().get(url, auth=auth, verify=True)
# Raises certificate verify failed

I'm aware ConnectionPool is in urllib realm, but since it's the adaptor who is updating the pool data, perhaps it should also handle this scenario?

System Information

{ "chardet": { "version": "3.0.4" }, "cryptography": { "version": "1.7.2" }, "idna": { "version": "2.6" }, "implementation": { "name": "CPython", "version": "2.7.12" }, "platform": { "release": "4.4.0-59-generic", "system": "Linux" }, "pyOpenSSL": { "openssl_version": "1000207f", "version": "16.0.0" }, "requests": { "version": "2.18.4" }, "system_ssl": { "version": "1000207f" }, "urllib3": { "version": "1.22" }, "using_pyopenssl": true }

aleperno avatar Oct 04 '17 17:10 aleperno

Yeah. Requests is using some old APIs in urllib3 that don’t interact with the connection pooling. It should update to pass the TLS data into the pool manager to ensure that the TLS info factors in.

Lukasa avatar Oct 04 '17 17:10 Lukasa

@Lukasa thanks for your prompt reply

aleperno avatar Oct 04 '17 20:10 aleperno

This is also true of the certificate/key paths provided in the cert keyword argument. It seems that the certfile and keyfile attributes are maintained on the connection and not reset if a new cert kwarg is given on a subsequent request on the session.

foslock avatar Nov 28 '17 18:11 foslock

Still observing this in 2.21.0, but you can issue session.close() to clear out the poolmanager, which will allow new requests with different verify values to be paid attention to.

gluemaker avatar Jan 04 '19 17:01 gluemaker