Fix #1632: fall back to Requests' CA bundle when OpenSSL's default certs are empty - #1934
Open
vinayK34 wants to merge 1 commit into
Open
Fix #1632: fall back to Requests' CA bundle when OpenSSL's default certs are empty#1934vinayK34 wants to merge 1 commit into
vinayK34 wants to merge 1 commit into
Conversation
…ult certs are empty `ensure_default_certs_loaded()` only called `SSLContext.load_default_certs()`, which relies on OpenSSL's default verify paths. Those are empty on some platforms (notably macOS python.org/pyenv builds), and because HTTPie always passes its own SSLContext, Requests skips its certifi-backed context and `load_verify_locations()` entirely -- leaving no trust store at all, so every HTTPS request failed with CERTIFICATE_VERIFY_FAILED even though plain `requests` worked fine in the same environment. Now, if the context still has no CA certs after `load_default_certs()`, load the bundle Requests itself would have used (certifi) via `DEFAULT_CA_BUNDLE_PATH`, handling both file and directory bundles and tolerating a missing path.
vinayK34
marked this pull request as ready for review
August 11, 2026 16:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1632
Root cause
httpie/compat.py::ensure_default_certs_loaded()only calledSSLContext.load_default_certs(), which populates the context from OpenSSL'sdefault verify paths. On some platforms those paths are empty — notably the
macOS python.org / pyenv builds, where OpenSSL is not wired to the system
keychain and no
SSL_CERT_FILE/openssl@3bundle is in play.That alone would normally be harmless, because Requests would fall back to its
own certifi-backed bundle. But HTTPie always passes its own
SSLContextintoRequests (
HTTPieHTTPSAdapter.init_poolmanager), and Requests treats acaller-supplied context as authoritative:
_urllib3_request_context(),pool_kwargs["ssl_context"] = _preloaded_ssl_context(Requests' own certifi-loaded context) is skipped when the poolmanager already
has an
ssl_context— i.e. always, for HTTPie;cert_verify(),load_verify_locations()is only reached whenverifyis astring path; for the default
verify=Trueit is deliberately skipped as anoptimization.
So with
verify=True(the default), HTTPie ended up performing verificationagainst a context with zero CA certificates, and every HTTPS request failed
with
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate— whileplain
requestsin the very same virtualenv worked fine. This also explains whythe reporter's
https --verify "$(python -m certifi)" ...workaround succeeded:passing an explicit path is the one code path that does call
load_verify_locations().The fix
If the context still has no CA certs after
load_default_certs(), fall back tothe CA bundle Requests itself would have used (
requests.utils.DEFAULT_CA_BUNDLE_PATH,i.e. certifi), via
extract_zipped_paths()so frozen/zipped installs keep working.Both file and directory bundles are handled (
cafile=/capath=), and a missingpath is tolerated rather than raising.
This is additive and conservative: it only ever runs when the context would
otherwise have had no trust store at all, so platforms where
load_default_certs()already works are completely unaffected.Verification
All of the following was actually executed in a sandbox (Python 3.14,
httpie 3.2.4, requests 2.32.3 — the exact version from the issue report,
urllib3 2.2.3). The macOS condition was reproduced by pointing
SSL_CERT_FILE/SSL_CERT_DIRat nonexistent paths so OpenSSL's default storeresolves empty while a valid bundle still exists on disk.
1. The real
httpieCLI against a real host — before vs. after2. Isolated reproduction (local HTTPS server), showing the
requests-works /HTTPie-fails asymmetry from the issue
3. Edge cases
--verify=nostill skips verification200 ok--verify=<correct bundle path>200 okbefore=1 after=1(no reload/duplication)150 CA certs loaded— unchanged behaviourDEFAULT_CA_BUNDLE_PATHhttpie.ssl_import +DEFAULT_SSL_CIPHERS_STRINGflake8 --ignore=E501,W503clean on the changed file; module doctests pass.On security: I explicitly A/B-tested whether this makes an explicit
--verify=<unrelated CA>wrongly succeed when the server's CA happens to be inthe default store. It behaves identically before and after this patch (trust is
additive on the shared context in both cases), so this is pre-existing upstream
behaviour and not a regression introduced here — worth noting separately, but out
of scope for this fix.