CVE-2026-40112: PraisonAI Cross-Site Scripting Vulnerability
MODERATECVE-2026-40112 is a MODERATE (CVSS 5.4) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting PraisonAI libraries in the PyPI ecosystem. The issue involves praisonai vulnerable to stored xss via unsanitized agent output in html rendering (nh3 not a required dependency). Remediation is available by upgrading affected packages to version 4.5.128.
CVE-2026-40112 at a Glance
Security Impact
CVSS: 5.4
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N).
How to Fix CVE-2026-40112
To remediate this vulnerability, upgrade all affected PraisonAI dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install PraisonAI>=4.5.128
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show PraisonAI
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2026-40112, inspect your installed packages using pip:
pip show PraisonAI
Analyze the terminal output to locate any version of PraisonAI in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.5.128), your application is affected.
Note: The pip show PraisonAI command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In PraisonAI, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-40112 Affected PraisonAI Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
PraisonAI
|
PyPI |
< 4.5.128
|
4.5.128
|
References
Frequently Asked Questions
What is CVE-2026-40112?
Which PraisonAI versions are affected?
What version fixes CVE-2026-40112?
Is PraisonAI affected?
What is the CVSS score of CVE-2026-40112?
What CWE is associated with CVE-2026-40112?
How can I check PyPI dependencies for CVE-2026-40112?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-cfg2-mxfj-j6pw",
"modified" : "2026-04-10T19:22:18Z",
"published" : "2026-04-10T19:22:18Z",
"aliases" : [ "CVE-2026-40112" ],
"summary" : "PraisonAI Vulnerable to Stored XSS via Unsanitized Agent Output in HTML Rendering (nh3 Not a Required Dependency)",
"details" : "## Summary\n\nThe Flask API endpoint in `src/praisonai/api.py` renders agent output as HTML without effective sanitization. The `_sanitize_html` function relies on the `nh3` library, which is not listed as a required or optional dependency in `pyproject.toml`. When `nh3` is absent (the default installation), the sanitizer is a no-op that returns HTML unchanged. An attacker who can influence agent input (via RAG data poisoning, web scraping results, or prompt injection) can inject arbitrary JavaScript that executes in the browser of anyone viewing the API output.\n\n## Details\n\nIn `src/praisonai/api.py`, lines 6-14 define the sanitizer with a try/except ImportError fallback:\n\n```python\ntry:\n import nh3\n def _sanitize_html(html: str) -> str:\n return nh3.clean(html)\nexcept ImportError:\n def _sanitize_html(html: str) -> str:\n \"\"\"Fallback: no nh3, return as-is (install nh3 for XSS protection).\"\"\"\n return html\n```\n\nThe `home()` route at lines 21-25 converts agent output to HTML via `markdown.markdown()` (which preserves raw HTML tags by default) and embeds it in an HTML response using an f-string — bypassing Flask's Jinja2 auto-escaping:\n\n```python\n@app.route('/')\ndef home():\n output = basic()\n html_output = _sanitize_html(markdown.markdown(str(output)))\n return f'<html><body>{html_output}</body></html>'\n```\n\nSince `nh3` is not in any dependency list (`pyproject.toml` core deps, optional deps, or requirements files), a standard installation will always hit the fallback path. The `markdown` library's default behavior passes through raw HTML tags in input text, so any `<script>` or event handler attributes in the agent output flow directly into the response.\n\nAdditionally, `deploy.py:76-91` generates a deployment version of `api.py` that has **no sanitization at all** — it directly calls `markdown.markdown(output)` without any `_sanitize_html` wrapper.\n\n## PoC\n\n1. Set up a PraisonAI instance with an agent that processes external content (e.g., web scraping or RAG retrieval):\n\n```yaml\n# agents.yaml\nframework: crewai\ntopic: test\nroles:\n researcher:\n role: Researcher\n goal: Process user-provided content\n backstory: You process content exactly as given\n tasks:\n process:\n description: \"Return this exact text: <img src=x onerror=alert(document.cookie)>\"\n expected_output: The text as-is\n```\n\n2. Verify `nh3` is not installed (default):\n```bash\npip show nh3 2>&1 | grep -c \"not found\"\n# Returns 1 (not installed)\n```\n\n3. Start the API:\n```bash\npython src/praisonai/api.py\n```\n\n4. Access the endpoint:\n```bash\ncurl http://localhost:5000/\n```\n\n5. Response contains unsanitized HTML:\n```html\n<html><body><p><img src=x onerror=alert(document.cookie)></p></body></html>\n```\n\n6. Opening this in a browser executes the JavaScript payload.\n\n## Impact\n\n- **Session hijacking**: An attacker can steal cookies or session tokens from users viewing the API output.\n- **Credential theft**: Injected scripts can present fake login forms or exfiltrate data to attacker-controlled servers.\n- **Actions on behalf of users**: Malicious JavaScript can perform actions in the context of the victim's browser session.\n\nThe attack surface includes any scenario where agent output contains attacker-influenced content: RAG retrieval from poisoned documents, web scraping of malicious pages, processing of adversarial user prompts, or multi-agent communication where one agent's output is tainted.\n\n## Recommended Fix\n\nMake `nh3` a required dependency when using the API, and remove the silent fallback:\n\n```python\n# Option 1: Make nh3 required in pyproject.toml under the \"api\" optional dependency\n# In pyproject.toml:\n# api = [\n# \"flask>=3.0.0\",\n# ...\n# \"nh3>=0.2.14\",\n# ]\n\n# Option 2: Use markdown's built-in HTML stripping as a safe default\nimport markdown\n\ndef _sanitize_html(html: str) -> str:\n try:\n import nh3\n return nh3.clean(html)\n except ImportError:\n import re\n return re.sub(r'<[^>]+>', '', html) # Strip all HTML tags as fallback\n\n# Option 3 (preferred): Use Flask's Jinja2 templating with auto-escaping\n# instead of f-string interpolation, or use markupsafe.escape()\nfrom markupsafe import Markup\n\n@app.route('/')\ndef home():\n output = basic()\n # Use markdown with safe extensions only\n html_output = markdown.markdown(str(output), extensions=[])\n try:\n import nh3\n html_output = nh3.clean(html_output)\n except ImportError:\n raise RuntimeError(\"nh3 is required for safe HTML rendering. Install with: pip install nh3\")\n return f'<html><body>{html_output}</body></html>'\n```\n\nAlso fix `deploy.py:76-91` to include sanitization in the generated `api.py`.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "PraisonAI"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "4.5.128"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/MervinPraison/PraisonAI/security/advisories/GHSA-cfg2-mxfj-j6pw"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-40112"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/MervinPraison/PraisonAI"
}, {
"type" : "WEB",
"url" : "https://github.com/MervinPraison/PraisonAI/releases/tag/v4.5.128"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-04-10T19:22:18Z",
"nvd_published_at" : "2026-04-09T22:16:34Z"
}
}