CVE-2026-25516
JSON

6.1medium

NiceGUI's XSS vulnerability in ui.markdown() allows arbitrary JavaScript execution through unsanitized HTML content

Severity
6.1medium CVSS:3.1 by GitHub_M
Exploit likelihood
0.28% (higher than 21% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-v82v-c5x8-w282PYSEC-2026-2231

Description

NiceGUI is a Python-based UI framework. 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. This vulnerability is fixed in 3.7.0.

Affected

Product or packageVersionsReported by
zauberzeug nicegui< 3.7.0, before 3.7.0CVE List, NVD
nicegui (PyPI)before 3.7.0GitHub Advisory Database, PyPA Advisory Database

All scores

GitHub_M6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
GitHub6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
PyPA Advisory Database6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N

Classification

CWE-79

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

NiceGUI is a Python-based UI framework. 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. This vulnerability is fixed in 3.7.0.

GitHub Advisory Database

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

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 published in version 3.7.0.

For Users (Immediate Workaround)

Until a fix is released, do not pass untrusted content directly to ui.markdown(). Instead, use one of these approaches:

Option 1: Convert and sanitize manually using ui.html()

import markdown2
from html_sanitizer import Sanitizer

sanitizer = Sanitizer()

def safe_markdown(content: str) -> None:
    """Render markdown with HTML sanitization."""
    html = markdown2.markdown(content)
    ui.html(sanitizer.sanitize(html), sanitize=False)

# Usage
safe_markdown(user_input)

Option 2: Escape HTML before markdown conversion (if raw HTML not needed)

import html

# Escape HTML entities - prevents any HTML from being interpreted
ui.markdown(html.escape(user_input))
Proposed Fix

Add a sanitize parameter to ui.markdown() consistent with other HTML-rendering components, and/or add an escape_html parameter.

NVD (es)

NiceGUI es un framework de interfaz de usuario (UI) basado en Python. El componente ui.markdown() utiliza la biblioteca markdown2 para convertir contenido markdown a HTML, que luego se renderiza a través de innerHTML. Por defecto, markdown2 permite que el HTML sin procesar pase sin cambios. Esto significa que si una aplicación renderiza contenido controlado por el usuario a través de ui.markdown(), un atacante puede inyectar HTML malicioso que contenga manejadores de eventos de JavaScript. A diferencia de otros componentes de NiceGUI que renderizan HTML (ui.html(), ui.chat_message(), ui.interactive_image()), el componente ui.markdown() no proporciona ni requiere un parámetro de saneamiento, dejando las aplicaciones vulnerables a ataques XSS. Esta vulnerabilidad se corrige en la versión 3.7.0.

References

Sources

SourceRecordLicence
CVE ListCVE-2026-25516 changed 2026-02-09CVE Terms of Use
GitHub Advisory DatabaseGHSA-v82v-c5x8-w282 changed 2026-07-13CC-BY-4.0
NVDCVE-2026-25516 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2026-2231 changed 2026-07-13CC-BY-4.0