NiceGUI's XSS vulnerability in ui.markdown() allows arbitrary JavaScript execution through unsanitized HTML content
Date: 2026-02
Affected: pip/nicegui
Attack vector: xss
Category: vulnerability-disclosure
Severity: Medium
CVE: CVE-2026-25516
CWE: CWE-79
CVSS: 6.1 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

## Description The `ui.markdown()` component uses the `markdown2` library to convert markdown content to HTML, which is then rendered via `innerHTML`. By default, `markdown2` allows raw HTML to pass through unchanged. This means that if an application renders user-controlled content through `ui.markdown()`, an attacker can inject malicious HTML containing JavaScript event handlers. Unlike other NiceGUI components that render HTML (`ui.html()`, `ui.chat_message()`, `ui.interactive_image()`), the `ui.markdown()` component does not provide or require a `sanitize` parameter, leaving applications vulnerable to XSS attacks. ## Proof of Concept ```python from nicegui import ui # User-controlled input containing malicious payload user_input = 'Hello! <img src=x onerror="alert(\'XSS\')">' ui.markdown(user_input) # XSS executes when page loads ui.run() ``` When this page loads, the JavaScript in the `onerror` handler executes, potentially allowing an attacker to: - Steal session cookies or authentication tokens - Perform actions on behalf of the user - Redirect users to malicious sites - Modify page content ## Impact Applications that render user-provided content through `ui.markdown()` are vulnerable to stored or reflected XSS attacks. This is particularly concerning for: - Chat applications displaying user messages - CMS or documentation systems with user-editable content - Any application that displays markdown from untrusted sources ## Remediation A release has been pu


Mitigations:

Architectural layers (MAESTRO):