CVE-2026-40112: PraisonAI Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-cfg2-mxfj-j6pw
CVSS 5.4
CWE-79
Published
Advisory Summary

CVE-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

CVE Identifier CVE-2026-40112
GHSA Identifier GHSA-cfg2-mxfj-j6pw
Severity MODERATE
CVSS v3.1 Base Score 5.4
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product PraisonAI
Package Ecosystem PyPI
Published Date
Last Updated

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).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (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.

PraisonAI fixed: 4.5.128
pip install PraisonAI>=4.5.128
Verify Direct and Transitive Dependencies

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

## Summary The 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. ## Details In `src/praisonai/api.py`, lines 6-14 define the sanitizer with a try/except ImportError fallback: ```python try: import nh3 def _sanitize_html(html: str) -> str: return nh3.clean(html) except ImportError: def _sanitize_html(html: str) -> str: """Fallback: no nh3, return as-is (install nh3 for XSS protection).""" return html ``` The `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: ```python @app.route('/') def home(): output = basic() html_output = _sanitize_html(markdown.markdown(str(output))) return f'<html><body>{html_output}</body></html>' ``` Since `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. Additionally, `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. ## PoC 1. Set up a PraisonAI instance with an agent that processes external content (e.g., web scraping or RAG retrieval): ```yaml # agents.yaml framework: crewai topic: test roles: researcher: role: Researcher goal: Process user-provided content backstory: You process content exactly as given tasks: process: description: "Return this exact text: <img src=x onerror=alert(document.cookie)>" expected_output: The text as-is ``` 2. Verify `nh3` is not installed (default): ```bash pip show nh3 2>&1 | grep -c "not found" # Returns 1 (not installed) ``` 3. Start the API: ```bash python src/praisonai/api.py ``` 4. Access the endpoint: ```bash curl http://localhost:5000/ ``` 5. Response contains unsanitized HTML: ```html <html><body><p><img src=x onerror=alert(document.cookie)></p></body></html> ``` 6. Opening this in a browser executes the JavaScript payload. ## Impact - **Session hijacking**: An attacker can steal cookies or session tokens from users viewing the API output. - **Credential theft**: Injected scripts can present fake login forms or exfiltrate data to attacker-controlled servers. - **Actions on behalf of users**: Malicious JavaScript can perform actions in the context of the victim's browser session. The 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. ## Recommended Fix Make `nh3` a required dependency when using the API, and remove the silent fallback: ```python # Option 1: Make nh3 required in pyproject.toml under the "api" optional dependency # In pyproject.toml: # api = [ # "flask>=3.0.0", # ... # "nh3>=0.2.14", # ] # Option 2: Use markdown's built-in HTML stripping as a safe default import markdown def _sanitize_html(html: str) -> str: try: import nh3 return nh3.clean(html) except ImportError: import re return re.sub(r'<[^>]+>', '', html) # Strip all HTML tags as fallback # Option 3 (preferred): Use Flask's Jinja2 templating with auto-escaping # instead of f-string interpolation, or use markupsafe.escape() from markupsafe import Markup @app.route('/') def home(): output = basic() # Use markdown with safe extensions only html_output = markdown.markdown(str(output), extensions=[]) try: import nh3 html_output = nh3.clean(html_output) except ImportError: raise RuntimeError("nh3 is required for safe HTML rendering. Install with: pip install nh3") return f'<html><body>{html_output}</body></html>' ``` Also fix `deploy.py:76-91` to include sanitization in the generated `api.py`.

CVE-2026-40112 Affected PraisonAI Versions

1 component(s)
Fixed Versions:
4.5.128
Product / Package Ecosystem Affected Versions Fixed Version
PraisonAI
PyPI
< 4.5.128
4.5.128

References

Frequently Asked Questions

What is CVE-2026-40112?
CVE-2026-40112 is a security vulnerability in PraisonAI involving PraisonAI Vulnerable to Stored XSS via Unsanitized Agent Output in HTML Rendering (nh3 Not a Required Dependency) under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which PraisonAI versions are affected?
Affected versions include releases prior to 4.5.128 across affected packages: PraisonAI.
What version fixes CVE-2026-40112?
Upgrading to 4.5.128 (or the latest patched release for your respective branch) resolves the vulnerability.
Is PraisonAI affected?
Yes, PraisonAI is affected in releases prior to 4.5.128. Upgrade your dependency to 4.5.128 or later.
What is the CVSS score of CVE-2026-40112?
CVE-2026-40112 has a CVSS v3.1 base score of 5.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2026-40112?
CVE-2026-40112 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (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.).
How can I check PyPI dependencies for CVE-2026-40112?
Run the dependency tree command: 'pip show PraisonAI'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}