Text of discuss.python.org › t › avoiding-compromised-certificates-in-pip › 109602 as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Avoiding compromised certificates in pip - Packaging - Discussions on Python.org

Avoiding compromised certificates in pip Packaging ichard26 (Richard Si) October 21, 2026, 6:39pm 1 Hi, another pip maintainer here I’ve been investigating alternative remedies for those unable to upgrade pip immediately. As far as I can tell, setting PIP_CERT to a valid CA bundle that has been patched (edit: AND setting PIP_USE_DEPRECATED=legacy-certs if on Python 3.10+, see below) is sufficient to stop pip from using the vendored certifi bundle.

Some caveats: The environment variable need to be used so the custom CA bundle is passed down to pip subprocesses used for installing build dependencies. Using the --cert flag is not enough . On Python 3.10 and higher, setting PIP_USE_DEPRECATED=legacy-certs (once again, the CLI option is insufficient) is recommended if your environment does not need the system trust store for pip to function. pip’s truststore logic always loads the certifi CA bundle as a fallback while setting up the SSL context.

Experiments suggest that setting PIP_CERT also prevents the SSL context from being used for verification, but I haven’t been able to trace through the requests/Python SSL code to be sure of this fact. The legacy-certs mode forces pip to rely solely on requests’ TLS handling and passing --cert or PIP_CERT will set the verify option on pip’s internal requests session object, which will prevent the certifi default bundle from being used. https://github.com/pypa/pip/blob/2f4d4a836ed00076001376fbb0ce6dc4f22cdae2/src/pip/\_vendor/requests/adapters.py#L292-L306 This remedy can be confirmed by passing a patched, empty, or near empty CA bundle via PIP_CERT and observing that the TLS verification fails despite the vendored certifi for a command like PIP_CERT=bundle... pip install -r https://dv-g3b-emudhra.we-have-a-problem.com/ . (If it is vulnerable, then you should get a parse error that HTML is not a valid requirement file.) I would investigate further to determine whether PIP_USE_DEPRECATED=legacy-certs is needed for Python 3.10 and higher, but I am very busy in my personal life so I won’t have the time to do so until much later , so I’m sharing what I have so far for now.

I have also not investigated REQUESTS_CA_BUNDLE at all. 2 Likes Information for Python users regarding eMudhra / emSign CA certificate security incident Information for Python users regarding eMudhra / emSign CA certificate security incident tiran (Christian Heimes) October 21, 2026, 7:31pm 2 The PIP_CERT trick does not work for me with pip 26.2.1. $ pip install -U pip==26.2.1 $ PIP_CERT=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem pip install -v emudhra --index-url https://dv-g3b-emudhra.we-have-a-problem.com/ Using pip 26.2.1 from /tmp/testenv/lib64/python3.12/site-packages/pip (python 3.12) Looking in indexes: https://dv-g3b-emudhra.we-have-a-problem.com/ ERROR: Could not find a version that satisfies the requirement emudhra (from versions: none) ERROR: No matching distribution found for emudhra legacy-certs + PIP_CERT work: $ PIP_USE_DEPRECATED=legacy-certs PIP_CERT=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem pip install -v emudhra --index-url https://dv-g3b-emudhra.we-have-a-problem.com/ Using pip 26.2.1 from /tmp/testenv/lib64/python3.12/site-packages/pip (python 3.12) Looking in indexes: https://dv-g3b-emudhra.we-have-a-problem.com/ WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:998)'))': /emudhra/ curl and uv refuse a connection: $ curl --cacert /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem https://dv-g3b-emudhra.we-have-a-problem.com/ curl: (60) SSL certificate problem: unable to get local issuer certificate ... $ UV_SYSTEM_CERTS=1 uv pip install emudhra --index-url https://dv-g3b-emudhra.we-have-a-problem.com/ Using Python 3.12.14 environment at: /tmp/testenv ⠙ Resolving dependencies... error: Failed to fetch: `https://dv-g3b-emudhra.we-have-a-problem.com/emudhra/` Caused by: error sending request for url (https://dv-g3b-emudhra.we-have-a-problem.com/emudhra/) Caused by: client error (Connect) Caused by: invalid peer certificate: UnknownIssuer 1 Like ichard26 (Richard Si) October 21, 2026, 7:47pm 3 I really wish I knew why PIP_CERT isn’t sufficient on Python 3.10+ for you, but I honestly do not know.

Are you sure that pip isn’t caching the index pages? Recent versions of pip respect the cache control header for simple API index page responses. Try setting PIP_NO_CACHE=1 or pip cache purge . I’m glad the legacy-certs and PIP_CERT combo does work, though. Edit: the cache shouldn’t… matter? or at least I’d expect the other commands to work if it were cached, but TBH, I am exhausted and not of the mental clarity needed to look further.

I’ll update my comment to recommend PIP_USE_DEPRECATED for now. tiran (Christian Heimes) October 21, 2026, 8:39pm 4 @ichard26 Your recommendation does not work because pip always loads certifi certificates in addition to system certs from truststore . PIP_CERT or --cert do not change the code path. Only legacy-certs trigger a different path that does not load certifi . I explained the issue in my initial comment Information for Python users regarding eMudhra / emSign CA certificate security incident - #3 by tiran You can easily reproduce the problem by either strace -ing the process or by making the cacert.pem unreadable: $ chmod 0 /tmp/testenv/lib/python3.14/site-packages/pip/_vendor/certifi/cacert.pem $ PIP_CERT=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem pip install emudhra --index-url https://dv-g3b-emudhra.we-have-a-problem.com/ WARNING: There was an error checking the latest version of pip.

ERROR: Exception: Traceback (most recent call last): File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/cli/base_command.py", line 109, in _run_wrapper status = _inner_run() File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/cli/base_command.py", line 102, in _inner_run return self.run(options, args) ~~~~~~~~^^^^^^^^^^^^^^^ File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/cli/req_command.py", line 106, in wrapper return func(self, options, args) File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/commands/install.py", line 431, in run session = self.get_default_session(options) File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/cli/index_command.py", line 80, in get_default_session self._session = self.enter_context(self._build_session(options)) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/cli/index_command.py", line 99, in _build_session ssl_context = _create_truststore_ssl_context() File "/tmp/testenv/lib64/python3.14/site-packages/pip/_internal/cli/index_command.py", line 50, in _create_truststore_ssl_context ctx.load_verify_locations(certifi.where()) ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/tmp/testenv/lib64/python3.14/site-packages/pip/_vendor/truststore/_api.py", line 160, in load_verify_locations return self._ctx.load_verify_locations( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ cafile=cafile, capath=capath, cadata=cadata ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ PermissionError: [Errno 13] Permission denied 3 Likes notatallshaw (Damian Shaw) October 21, 2026, 9:04pm 5 Yes, over at pip we need to reassess our defaults, what options we provide to users, fix some documentation, and fix some bugs.

We’re starting on Switch to using truststore only by default (currently mixed certifi + truststore) · Issue #14374 · pypa/pip · GitHub , but I’m sure there will be several follow up issues and PRs. For now, as you say, if you want to enforce your cert bundle only you can run: --use-deprecated=legacy-certs --cert bundle.pem To set this legacy-certs mode in an env you can run: # Unix-like: export PIP_USE_DEPRECATED=legacy-certs # Powershell:

The rest of this page is on the live site.