GHSA-72qc-wxch-74mg
MEDIUMNiceGUI Reflected XSS in ui.add_css, ui.add_scss, and ui.add_sass via Style Injection
EPSS Exploitation Probability
EPSS (Exploit Prediction Scoring System) is a daily probability model maintained by FIRST.org. It estimates the likelihood a CVE will be exploited in production environments within the next 30 days, derived from real-world threat intelligence signals.
Blast Radius
niceguiReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
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 <style> or <script> tags by injecting closing tags (e.g., </style> or </script>), 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<style>tag. Input containing</style>closes the tag prematurely, allowing subsequent HTML/JS injection.ui.add_scss/ui.add_sass: These rely on client-side compilation within<script>tags. Input containing</script>breaks the execution context, allowing XSS.
PoC
Scenario: A developer allows users to customize a theme color via a URL parameter.
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;}</style><img src=x onerror=alert(document.domain)><style>
Impact
- Type: Reflected XSS
- Severity: Moderate
- Affected Components: Applications using
ui.add_css,ui.add_scss, orui.add_sasswith untrusted input (e.g., dynamic theming based on user input).
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | nicegui | all versions | 3.4.0 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for nicegui. O3's reachability analysis confirms whether the vulnerable code path is actually invoked in your application, so you act on real exposure instead of every transitive match.
Fix
Update nicegui to 3.4.0 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-72qc-wxch-74mg is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 pinpoints whether GHSA-72qc-wxch-74mg is reachable in your code and exactly where to fix it, then blocks exploitation in production at runtime until the patched version is deployed.
Tailored to GHSA-72qc-wxch-74mg. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is GHSA-72qc-wxch-74mg in your dependencies?
O3 detects GHSA-72qc-wxch-74mg across PyPI dependencies and uses function-level reachability to confirm whether the vulnerable code path is actually reachable — not just present. No false positives.