{"id":"CVE-2026-57130","aliases":["CVE-2026-57130","GHSA-c969-5x3p-vq3v","PYSEC-2026-3532"],"related":[],"kind":"vulnerability","state":"published","title":"PraisonAI: IMAP Command Injection via Unsanitized Email Search Parameters","summary":"PraisonAI is a multi-agent teams system. Prior to praisonaiagents 1.6.59, src/praisonai-agents/praisonaiagents/tools/email_tools.py interpolates LLM-controlled from_addr, subject, and query values directly into quoted IMAP SEARCH criteria. Embedded quote, backslash, newline, or null characters can escape the intended criterion and alter IMAP operations when search_emails, reply_email, or archive_email is exposed to an agent with configured email credentials, allowing mailbox data access, modification, deletion, or connection disruption. This issue is fixed in praisonaiagents 1.6.59.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"PraisonAI is a multi-agent teams system. Prior to praisonaiagents 1.6.59, src/praisonai-agents/praisonaiagents/tools/email_tools.py interpolates LLM-controlled from_addr, subject, and query values directly into quoted IMAP SEARCH criteria. Embedded quote, backslash, newline, or null characters can escape the intended criterion and alter IMAP operations when search_emails, reply_email, or archive_email is exposed to an agent with configured email credentials, allowing mailbox data access, modification, deletion, or connection disruption. This issue is fixed in praisonaiagents 1.6.59.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe email search tool in `src/praisonai-agents/praisonaiagents/tools/email_tools.py` constructs IMAP SEARCH commands by interpolating LLM-controlled parameters (from_addr, subject, query) directly into IMAP protocol strings using f-string formatting with double-quote delimiters. An attacker who can influence the arguments to the `search_emails` or `reply_email` tool (via crafted agent prompts) can inject arbitrary IMAP commands, potentially exfiltrating email data from other folders, deleting emails, or performing other unauthorized IMAP operations.\n## Details\n\n**Vulnerable code (lines 493–502):**\n```python\ncriteria = []\nif from_addr:\n    criteria.append(f'FROM \"{from_addr}\"')\nif subject:\n    criteria.append(f'SUBJECT \"{subject}\"')\nif query:\n    criteria.append(f'TEXT \"{query}\"')\nif not criteria:\n    criteria.append(\"ALL\")\nsearch_str = \" \".join(criteria)\nstatus, data = mail.search(None, search_str)\n```\n\nThe `from_addr`, `subject`, and `query` parameters originate from LLM tool call arguments (the `search_emails` public function at line 665). These values flow through without any sanitization or escaping. The double-quote (`\"`) characters in these parameters allow breaking out of the IMAP SEARCH quoted string context.\n\n**Additional injection points:**\n- Line 416: `mail.search(None, f'HEADER Message-ID \"{search_id}\"')`\n- Line 447: Same pattern in `_smtp_reply_email`\n- Line 542: Same pattern in `_smtp_archive_email`\n\nThe `search_id` / `message_id` parameter in these functions is also LLM-controlled via the `reply_email` and `archive_email` public tool functions.\n\n**Reachability:** The `search_emails`, `reply_email`, and `archive_email` functions are exposed as agent tools. They are reachable when an agent is configured with email tools (EMAIL_ADDRESS + EMAIL_PASSWORD environment variables set). This is a documented deployment scenario for email-capable agents.\n\n## PoC\n\n**Setup:** Requires an IMAP server (not run here — this is a static proof). The vulnerability is demonstrated by tracing the data flow.\n\n**Positive trigger — IMAP injection via `search_emails`:**\nAn LLM agent processing a crafted prompt calls:\n```python\nsearch_emails(from_addr='user@example.com\" LOGOUT')\n```\nThis produces the IMAP command:\n```\nSEARCH FROM \"user@example.com\" LOGOUT\"\n```\nThe `LOGOUT` command is injected after the prematurely closed quoted string, causing the IMAP connection to be terminated.\n\n**More severe injection — exfiltrate emails from another folder:**\n```python\nsearch_emails(query='\" SEARCH RETURN (MIN) ALL')\n```\nProduces: `TEXT \"\" SEARCH RETURN (MIN) ALL\"` — injects a secondary SEARCH command.\n\n**Negative control — legitimate search:**\n```python\nsearch_emails(from_addr='user@example.com')\n```\nProduces: `FROM \"user@example.com\"` — correct, no injection.\n\n**Cleanup:** No persistent changes for read-only injection. For destructive injection (DELETE, EXPUNGE), impact persists.\n\n## Impact\n\nAn attacker who can craft prompts that cause an LLM agent to call `search_emails` with injection payloads can:\n\n- **Terminate IMAP connections** (denial of service)\n- **Inject arbitrary IMAP commands** — including LIST (enumerate folders), SELECT (switch folders), FETCH (read emails from other mailboxes), STORE (modify flags), COPY/MOVE (move emails), DELETE/EXPUNGE (permanently delete emails)\n- **Exfiltrate email contents** from folders the user did not intend to expose to the agent\n- **Permanently delete emails** via injected DELETE + EXPUNGE commands\n\nThe attack requires the IMAP backend to be configured (EMAIL_ADDRESS + EMAIL_PASSWORD env vars), which is a documented and common deployment for email-capable agents.\n\n## Suggested remediation\n\n1. **Escape double-quote characters** in IMAP parameters. Per RFC 3501, literal strings use `{n}\\r\\n` format or quoted strings with `\\` escaping:\n```python\ndef _escape_imap_string(s: str) -> str:\n    \"\"\"Escape a string for safe use in IMAP quoted strings.\"\"\"\n    # Use IMAP literal syntax for safety: {length}\\r\\n<data>\n    encoded = s.encode('utf-8')\n    return f'{{{len(encoded)}}}\\r\\n{encoded}'\n```\n\n2. Use IMAP literal syntax (`{n}\\r\\ndata`) instead of quoted strings for all user-controlled parameters. This prevents any injection regardless of content.\n\n3. Apply the escaping to all IMAP search criteria parameters: `from_addr`, `subject`, `query`, and `search_id`/`message_id`.","format":"markdown","source":"ghsa"}],"published":"2026-06-18T14:25:03.000Z","modified":"2026-09-15T14:45:28.563Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":8.1,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":8.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":8.1,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":8.1,"rating":"HIGH"}],"cwes":["CWE-20","CWE-77"],"affected":[{"ranges":[{"version":"< 1.6.59","status":"affected"}],"vendor":"MervinPraison","product":"praisonaiagents","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.6.59"}],"ecosystem":"PyPI","package":"praisonaiagents","purl":"pkg:pypi/praisonaiagents","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.6.59"}],"ecosystem":"PyPI","package":"praisonaiagents","purl":"pkg:pypi/praisonaiagents","source":"pysec"}],"references":[{"url":"https://github.com/MervinPraison/PraisonAI/security/advisories/GHSA-c969-5x3p-vq3v","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/MervinPraison/PraisonAI/commit/b4270173d4123fb1ee8910588f0896668ee21b59","tags":["x-refsource-misc"],"sources":["cvelist","nvd"]},{"url":"https://github.com/MervinPraison/PraisonAI/releases/tag/v4.6.59","tags":["x-refsource-misc"],"sources":["cvelist","nvd"]},{"url":"https://github.com/MervinPraison/PraisonAI","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/praisonaiagents","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-c969-5x3p-vq3v","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-57130","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-09-14T14:46:30.550Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-57130","url":"https://www.cve.org/CVERecord?id=CVE-2026-57130","licence":"CVE Terms of Use","modified":"2026-09-14T14:47:00.197Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-c969-5x3p-vq3v","url":"https://github.com/advisories/GHSA-c969-5x3p-vq3v","licence":"CC-BY-4.0","modified":"2026-07-23T15:11:29.688Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-57130","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-57130","licence":"Public domain","modified":"2026-09-15T14:45:28.563Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-3532","url":"https://osv.dev/vulnerability/PYSEC-2026-3532","licence":"CC-BY-4.0","modified":"2026-07-23T15:00:22.408Z"}],"updatedAt":"2026-11-25T22:59:38.284Z","epss":{"score":0.00347,"percentile":0.30262,"date":"2026-12-01T12:00:22.000Z"}}