The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(ssl): certifi re-resolution reaches real certifi; requests keeps its CA overrides
Tekniumf162c82ac488
diff --git a/agent/ssl_verify.py b/agent/ssl_verify.pyindex 65cb86cb483..acfb6a7c139 100644--- a/agent/ssl_verify.py+++ b/agent/ssl_verify.py@@ -236,8 +236,17 @@ def requests_verify() -> bool | str:cannot reach, so a rotated environment leaves every ``requests`` call raising``OSError: Could not find a suitable TLS CA certificate bundle``. The live bundle(certifi's, re-derived; else OpenSSL's own default) keeps those calls working;- ``True`` only when nothing resolves, which is requests' own default.+ ``True`` only when nothing resolves, which is requests' own default. A healthy+ install keeps ``True`` too: requests reads ``REQUESTS_CA_BUNDLE``/``CURL_CA_BUNDLE``+ only for ``verify=True``, and an explicit path would silently bypass a user's+ proxy CA."""+ from requests.utils import DEFAULT_CA_BUNDLE_PATH++ if os.environ.get("REQUESTS_CA_BUNDLE") or os.environ.get("CURL_CA_BUNDLE"):+ return True+ if Path(DEFAULT_CA_BUNDLE_PATH).is_file():+ return Truebundle = certifi_bundle_path()if bundle:return bundlediff --git a/tests/agent/test_ssl_verify.py b/tests/agent/test_ssl_verify.pyindex 7ed3a5fd454..3a3b357984a 100644--- a/tests/agent/test_ssl_verify.py+++ b/tests/agent/test_ssl_verify.py@@ -264,6 +264,7 @@ def _rotated_certifi(tmp_path: Path, monkeypatch, *, replacement: bool) -> _Rotaimport sysimport certifi as real_certifi+ import requests.utilsbundle = Path(real_certifi.where()).read_bytes() # a real PEM: contexts must load itstale = _stand_in_certifi_env(tmp_path, "env-a", bundle)@@ -278,6 +279,8 @@ def _rotated_certifi(tmp_path: Path, monkeypatch, *, replacement: bool) -> _Rotastand_in = importlib.import_module("certifi")monkeypatch.setitem(sys.modules, "certifi", stand_in)assert Path(stand_in.where()).parent == stale+ # requests froze its default bundle path from the same certifi at import.+ monkeypatch.setattr(requests.utils, "DEFAULT_CA_BUNDLE_PATH", stand_in.where())shutil.rmtree(stale)assert not Path(stand_in.where()).exists()return _Rotation(stand_in, stale, live)@@ -447,3 +450,15 @@ assert live.is_file() and live.parent.resolve() == Path(env_b, 'certifi').resolvenv=_child_env(tmp_path), capture_output=True, text=True, timeout=60, check=False,)assert child.returncode == 0, child.stdout + child.stderr+++def test_requests_verify_keeps_requests_own_ca_overrides(monkeypatch, no_ca_env):+ """requests reads ``REQUESTS_CA_BUNDLE`` only for ``verify=True``; a healthy install+ or a configured override must keep it, or a proxy CA stops being trusted."""+ from agent import ssl_verify++ assert ssl_verify.requests_verify() is True+ monkeypatch.setenv("REQUESTS_CA_BUNDLE", "/corp/proxy-ca.pem")+ monkeypatch.setattr("requests.utils.DEFAULT_CA_BUNDLE_PATH", "/gone/cacert.pem")+ assert ssl_verify.requests_verify() is True+