CVE-2026-40112 — praisonai
MEDIUMCVE-2026-40112 is a medium-severity (CVSS 5.4) Cross-site Scripting (XSS) vulnerability in praisonai. A fix is available for praisonai — see the affected versions and patch details below.
PraisonAI has Stored XSS via Unsanitized Agent Output in HTML Rendering (nh3 Not a Required Dependency)
Exploitation Status
Proof-of-concept exploit code exists
- CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
Exploitation and automatability from CISA’s SSVC triage for CVE-2026-40112.
EPSS Exploitation Probability
EPSS (Exploit Prediction Scoring System) is a daily probability model maintained by FIRST.org. It estimates the likelihood a CVE will be exploited in production environments within the next 30 days, derived from real-world threat intelligence signals.
How urgent is this, really
CVE-2026-40112 plotted by exploitation likelihood (EPSS) against impact (CVSS). The shaded corner — EPSS 50%+ and CVSS 7.0+ — is where this CVE doesn't sit, though severity or exploitability alone can still warrant action.
Where this sits among everything scored
Of 377,636 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Real counts from FIRST.org, not a sample — log-scaled since the landscape is heavily right-skewed.
Real-World Exposure
praisonaiReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
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:
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:
@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
- Set up a PraisonAI instance with an agent that processes external content (e.g., web scraping or RAG retrieval):
# 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
- Verify
nh3is not installed (default):
pip show nh3 2>&1 | grep -c "not found"
# Returns 1 (not installed)
- Start the API:
python src/praisonai/api.py
- Access the endpoint:
curl http://localhost:5000/
- Response contains unsanitized HTML:
<html><body><p><img src=x onerror=alert(document.cookie)></p></body></html>
- 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:
# 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.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | praisonai | all versions | 4.5.128pip install --upgrade 'praisonai==4.5.128' |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for praisonai, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update praisonai to 4.5.128 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2026-40112 is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 Security's impact-aware SCA analyses which vulnerable code paths your application actually calls, so a match like CVE-2026-40112 can be triaged on real exposure rather than presence alone.
Tailored to CVE-2026-40112. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is CVE-2026-40112 in your dependencies?
O3 Security finds CVE-2026-40112 across PyPI dependencies, including transitive ones, and its impact-aware SCA ranks findings by whether your code actually calls the vulnerable path.