GitHub Advisoryadvisory · PyPI

GHSA-72qc-wxch-74mg NiceGUI Reflected XSS in ui.add_css, ui.add_scss, and ui.add_sass via Style Injection

MEDIUM Published 2025-12-08 Modified 2025-12-09 Official page ↗
Aliases
CVE-2025-66469
Ecosystem
PyPI
Packages
nicegui
Severity
Moderate
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
Weaknesses
CWE-79
Reviewed
2025-12-08

Affected packages

• PyPI nicegui: < 3.4.0 → fixed in 3.4.0

Description

Summary A Cross-Site Scripting (XSS) vulnerability exists in `ui.add_css`, `ui.add_scss`, and `ui.add_sass` functions in NiceGUI (v3.3.1 and earlier). These functions allow developers to inject styles dynamically. However, they lack proper sanitization or encoding for the JavaScript context they generate. An attacker can break out of the intended `` or `` tags by injecting closing tags (e.g., `` or ``), allowing for the execution of arbitrary JavaScript. Details The vulnerability stems from how these functions inject content into the DOM using `client.run_javascript` (or `add_head_html` internally) without sufficient escaping for the transport layer. • `ui.add_css`: Injects content into a `` tag. Input containing `` closes the tag prematurely, allowing subsequent HTML/JS injection. • `ui.add_scss` / `ui.add_sass`: These rely on client-side compilation within `` tags. Input containing `` breaks the execution context, allowing XSS. PoC Scenario: A developer allows users to customize a theme color via a URL parameter. ```python from nicegui import ui @ui.page('/') def main(color: str = 'blue'): # Vulnerable implementation of dynamic theming ui.add_css(f'.q-btn {{ background-color: {color} !important; }}') ui.button('Click Me') ui.run(port=8082) ``` Attack Vector: Accessing the following URL executes arbitrary JavaScript: `http://localhost:8082/?color=red;}` Impact • Type: Reflected XSS • Severity: Moderate • Affected Components: Applications using `ui.add_css`, `ui.add_scss`, or `ui.add_sass` with untrusted input (e.g., dynamic theming based on user input).

Related

Alias · CVE (1)

  • CVE-2025-66469 NiceGUI is a Python-based UI framework. vulnerability

Weakness · CWE (1)

  • CWE-79 Improper Neutralization of Input During Web Page Generation weakness

References