Skip to content

Commit a293450

Browse files
feat(transport): Use env vars for default CA cert bundle location (#3160)
Many libraries use the SSL_CERT_FILE environment variable to point at a CA bundle to use for HTTPS certificate verification. This is often used in corporate environments with internal CAs or HTTPS hijacking proxies, where the Sentry server presents a certificate not signed by one of the CAs bundled with Certifi. Additionally, Requests, Python's most popular HTTP client library, uses the REQUESTS_CA_BUNDLE variable instead. Use the SSL_CERT_FILE or REQUESTS_CA_BUNDLE vars if present to set the default CA bundle. Fixes GH-3158 Co-authored-by: Neel Shah <[email protected]>
1 parent ffc4610 commit a293450

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sentry_sdk/transport.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22
import io
3+
import os
34
import gzip
45
import socket
56
import time
@@ -457,7 +458,6 @@ def _get_pool_options(self, ca_certs):
457458
options = {
458459
"num_pools": self._num_pools,
459460
"cert_reqs": "CERT_REQUIRED",
460-
"ca_certs": ca_certs or certifi.where(),
461461
}
462462

463463
socket_options = None # type: Optional[List[Tuple[int, int, int | bytes]]]
@@ -477,6 +477,13 @@ def _get_pool_options(self, ca_certs):
477477
if socket_options is not None:
478478
options["socket_options"] = socket_options
479479

480+
options["ca_certs"] = (
481+
ca_certs # User-provided bundle from the SDK init
482+
or os.environ.get("SSL_CERT_FILE")
483+
or os.environ.get("REQUESTS_CA_BUNDLE")
484+
or certifi.where()
485+
)
486+
480487
return options
481488

482489
def _in_no_proxy(self, parsed_dsn):

0 commit comments

Comments
 (0)