Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt requests new get_connection API #164

Merged
merged 6 commits into from
May 28, 2024

Conversation

pquentin
Copy link
Member

@pquentin pquentin commented May 23, 2024

To fix a security vulnerability, requests removed HTTPAdapter.get_connection() in favor of HTTPAdapter.get_connection_with_tls_context(). This breaks the transport and client when using requests 2.32 or later, as the transport directly calls the removed API. This pull request fixes the issue.

See psf/requests#6710 for more details.

# elastic-transport is not vulnerable to CVE-2024-35195 because it uses
# requests.Session and an SSLContext without using the verify parameter.
# We should remove this branch when requiring requests 2.32 or later.
adapter.get_connection(self.base_url)

Choose a reason for hiding this comment

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

Do we need to preserve the type: ignore here? And are there any typing considerations for the new call?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't, the types were fixed in typeshed yesterday: python/typeshed#12000.

Copy link

@miguelgrinberg miguelgrinberg left a comment

Choose a reason for hiding this comment

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

Looks good.

Would it be worth testing two requests versions from before and after this change? Considering the new code appears to let through an invalid TLS combination, which is what that remaining test failure looks like.

@pquentin pquentin changed the title Fix requests 2.32 compatibility Adopt requests new get_connection API May 23, 2024
@pquentin
Copy link
Member Author

Yes, we should probably test using an older version of requests too. Waiting for requests 2.32.3 to proceed further here.

@pquentin
Copy link
Member Author

The remaining failure is due to psf/requests#6716. It will go away when requests 2.32.3 is released.

@pquentin
Copy link
Member Author

I'm merging this now because it improves the situation and I checked that the tests pass with the main branch of requests, which should be released any time now: psf/requests#6721.

@pquentin pquentin merged commit d89e9f0 into elastic:main May 28, 2024
6 of 11 checks passed
github-actions bot pushed a commit that referenced this pull request May 28, 2024
* Fix requests 2.32 compatibility

* Test minimum dependencies in CI

(cherry picked from commit d89e9f0)
github-actions bot pushed a commit that referenced this pull request May 28, 2024
* Fix requests 2.32 compatibility

* Test minimum dependencies in CI

(cherry picked from commit d89e9f0)
@pquentin pquentin deleted the fix-requests-2.32-compat branch May 28, 2024 06:01
pquentin added a commit that referenced this pull request May 28, 2024
* Fix requests 2.32 compatibility

* Test minimum dependencies in CI

(cherry picked from commit d89e9f0)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
pquentin added a commit that referenced this pull request May 28, 2024
* Fix requests 2.32 compatibility

* Test minimum dependencies in CI

(cherry picked from commit d89e9f0)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
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.

None yet

2 participants