CVE-2024-40647
Description
Sentry's Python SDK before 2.8.0 leaks environment variables to subprocesses even when env={} is set, due to a bug in the Stdlib integration.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Sentry's Python SDK before 2.8.0 leaks environment variables to subprocesses even when `env={}` is set, due to a bug in the Stdlib integration.
Vulnerability
The bug resides in the sentry_sdk Python SDK versions prior to 2.8.0. When the Stdlib integration (enabled by default) is active, the SDK incorrectly overrides the env argument in subprocess calls, causing all environment variables to be passed to child processes even if the user explicitly sets env={} to prevent that [2]. The Python subprocess module normally passes environment variables by default, but the env argument allows overriding; the SDK's instrumentation breaks this expectation [1].
Exploitation
An attacker does not need special privileges to exploit this; the vulnerability is triggered automatically whenever an application using the vulnerable SDK spawns a subprocess with env={}. The attacker must have some way to observe the subprocess's environment, for example by controlling the subprocess or its output. No user interaction beyond normal application execution is required.
Impact
Successful exploitation leads to unintended disclosure of environment variables to subprocesses. Environment variables often contain sensitive information such as API keys, database credentials, or secrets. This information leakage could compromise the security of the application and its infrastructure.
Mitigation
The issue is patched in sentry-sdk version 2.8.0, released with pull request #3251 [2]. Users should upgrade to 2.8.0 or later. If upgrading is not possible, a workaround is to disable all default integrations by setting default_integrations=False when calling sentry_sdk.init() [3][4]. This will disable the Stdlib integration and prevent the bug.
AI Insight generated on Jun 1, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
sentry-sdkPyPI | >= 2.0.0a1, < 2.8.0 | 2.8.0 |
sentry-sdkPyPI | < 1.45.1 | 1.45.1 |
Affected products
5- Range: 0.2.0
- ghsa-coords4 versionspkg:pypi/sentry-sdkpkg:rpm/opensuse/python-sentry-sdk&distro=openSUSE%20Leap%2015.5pkg:rpm/opensuse/python-sentry-sdk&distro=openSUSE%20Tumbleweedpkg:rpm/suse/python-sentry-sdk&distro=SUSE%20Package%20Hub%2015%20SP5
>= 2.0.0a1, < 2.8.0+ 3 more
- (no CPE)range: >= 2.0.0a1, < 2.8.0
- (no CPE)range: < 0.14.4-bp155.3.3.1
- (no CPE)range: < 2.10.0-1.1
- (no CPE)range: < 0.14.4-bp155.3.3.1
Patches
2763e40aa4cb5fix(integrations): don't send full env to subprocess (#3251)
2 files changed · +18 −1
sentry_sdk/integrations/stdlib.py+5 −1 modified@@ -207,7 +207,11 @@ def sentry_patched_popen_init(self, *a, **kw): ): if env is None: env = _init_argument( - a, kw, "env", 10, lambda x: dict(x or os.environ) + a, + kw, + "env", + 10, + lambda x: dict(x if x is not None else os.environ), ) env["SUBPROCESS_" + k.upper().replace("-", "_")] = v
tests/integrations/stdlib/test_subprocess.py+13 −0 modified@@ -174,6 +174,19 @@ def test_subprocess_basic( assert sys.executable + " -c" in subprocess_init_span["description"] +def test_subprocess_empty_env(sentry_init, monkeypatch): + monkeypatch.setenv("TEST_MARKER", "should_not_be_seen") + sentry_init(integrations=[StdlibIntegration()], traces_sample_rate=1.0) + with start_transaction(name="foo"): + args = [ + sys.executable, + "-c", + "import os; print(os.environ.get('TEST_MARKER', None))", + ] + output = subprocess.check_output(args, env={}, universal_newlines=True) + assert "should_not_be_seen" not in output + + def test_subprocess_invalid_args(sentry_init): sentry_init(integrations=[StdlibIntegration()])
6f4685e29b07Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
11- github.com/advisories/GHSA-g92j-qhmh-64v2ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-40647ghsaADVISORY
- docs.python.org/3/library/subprocess.htmlnvdWEB
- docs.sentry.io/platforms/python/integrations/default-integrationsnvdWEB
- docs.sentry.io/platforms/python/integrations/default-integrations/nvdWEB
- github.com/getsentry/sentry-python/commit/763e40aa4cb57ecced467f48f78f335c87e9bdffnvdWEB
- github.com/getsentry/sentry-python/pull/3251nvdWEB
- github.com/getsentry/sentry-python/releases/tag/1.45.1ghsaWEB
- github.com/getsentry/sentry-python/releases/tag/2.8.0nvdWEB
- github.com/getsentry/sentry-python/security/advisories/GHSA-g92j-qhmh-64v2nvdWEB
- lists.debian.org/debian-lts-announce/2026/06/msg00001.htmlnvdWEB
News mentions
0No linked articles in our index yet.