Summary
AnythingLLM Desktop before 1.11.2 contains a cross-site scripting (XSS) flaw in the live chat rendering path that allows untrusted content to be injected into the DOM during streaming.
Because the Electron shell is configured insecurely, an attacker who can control streamed chat content can escalate this XSS into remote code execution on the underlying host with no extra user interaction beyond normal chat usage.
Affected context
This vulnerability occurs in the AnythingLLM Desktop application's chat UI when messages are rendered during the streaming phase.
The issue specifically affects the custom markdown-it image renderer in frontend/src/utils/chat/markdown.js, which injects token.content directly into an alt attribute, and the PromptReply component, which renders this HTML via dangerouslySetInnerHTML without sanitization.
In contrast, historical messages use DOMPurify.sanitize() correctly, so the risk is concentrated in the live, streaming chat path under default Electron settings.
Exploit preconditions
- Attack surface: Desktop chat interface running inside an Electron shell.
- Required access: Ability to cause malicious content to appear in a streamed chat message (e.g., through prompt injection, external integrations, shared workspaces, or malicious upstream data sources).
- Trigger point: Rendering of a streaming chat response in the
PromptReplycomponent, which usesdangerouslySetInnerHTMLon unsanitized HTML produced by the custom markdown renderer. - Why exploitation is possible:
- The markdown-it image renderer interpolates
token.contentdirectly into an HTML attribute without HTML entity escaping. PromptReplybypasses DOMPurify and trusts this HTML, leading to XSS.- The Electron environment is configured insecurely (e.g.,
nodeIntegrationor similar bridging features), allowing XSS to pivot into arbitrary code execution on the host.
Why this happens
The underlying bug is a classic reflected/DOM-based XSS pattern where untrusted text is converted to HTML and injected into the DOM without proper escaping or sanitization.
Specifically:
- The custom markdown-it renderer constructs an
<img>tag by concatenating rawtoken.contentinto thealtattribute. - This output is then rendered using React's
dangerouslySetInnerHTMLinPromptReply, bypassing React's built-in escaping and omitting any sanitization step such as DOMPurify.
Within an Electron context configured with powerful web preferences, this maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting) and effectively becomes an XSS-to-RCE chain because DOM JavaScript execution can access sensitive Electron APIs or preload bridges.
Potential impact
- Remote execution of arbitrary commands or code on the host operating system via the Electron runtime.
- Exfiltration of local files and sensitive data accessible to the AnythingLLM Desktop app.
- Theft of API keys, access tokens, and credentials stored or used by the application.
- Manipulation of chat content, prompt history, and retrieved context to poison outputs or mislead users.
- Use of the compromised desktop client as a pivot to attack other internal systems reachable from the host.
General mitigation guidance
Effective mitigation focuses on both the HTML rendering pipeline and the Electron security model:
- Ensure all user-controlled or model-controlled content is sanitized before being inserted into the DOM, including streaming content paths; apply a robust HTML sanitizer such as DOMPurify consistently across components.
- Avoid using
dangerouslySetInnerHTMLfor rich text rendering where possible; prefer structured rendering that escapes content by default. - When custom markdown renderers are necessary, properly escape or encode all interpolated values, especially within HTML attributes, and avoid raw string concatenation.
- Harden the Electron configuration following least-privilege principles: disable or strictly limit node integration, remote module access, and any direct bridging that lets web content execute OS-level commands.
- Place sensitive capabilities (file access, shell execution, key handling) behind narrow, validated IPC interfaces and treat the renderer process as untrusted.
How teams detect issues like this
Detection can rely on a combination of code-centric and configuration-centric approaches:
- Static analysis rules or linters that flag:
- Uses of
dangerouslySetInnerHTMLor similar raw HTML injection APIs. - Custom markdown or HTML rendering logic that concatenates untrusted data into tags or attributes without escaping.
- Code review checklists that:
- Require DOMPurify (or equivalent) on any path rendering user- or model-controlled HTML.
- Explicitly review Electron
BrowserWindowandwebPreferencesconfiguration for unsafe settings (e.g.,nodeIntegration: true,contextIsolation: false). - Security-focused unit and integration tests for the chat UI that attempt to inject script-like payloads into streaming responses and confirm they are neutralized.
- Periodic automated scanning of the codebase with SAST tools tuned for XSS-in-Electron patterns and insecure Electron preferences.

