CVE-2026-21871·Python vulnerability
NiceGUI is a Python-based UI framework. From versions 2.13.0 to 3.4.1, there is a XSS risk in NiceGUI when developers pass attacker-controlled strings into ui.navigate.history.push() or ui.navigate.history.replace(). These helpers are documented as History API wrappers for updating the browser URL without page reload. However, if the URL argument is embedded into generated JavaScript without proper escaping, a crafted payload can break out of the intended string context and execute arbitrary JavaScript in the victim’s browser. Applications that do not pass untrusted input into ui.navigate.history.push/replace are not affected. This issue has been patched in version 3.5.0.
- Severity
- medium
- Software
- Python
- Fixed in
- 3.5.0
- Published
- 2026-01-08
Affected versions
From: 2.13.0
Until: 3.5.0
Fixed in: 3.5.0
How to fix this CVE
Upgrade NiceGUI to version 3.5.0 or later to patch the XSS vulnerability in the history navigation helpers. If your application passes user-controlled input to ui.navigate.history.push() or ui.navigate.history.replace(), this update is critical. Ensure all Python dependencies are updated after patching.
sudo dnf update python3-niceguiDefensia detects this vulnerability
What an exploitation attempt looks like
Sample log line indicative of exploitation attempts:
POST|GET request with URL parameters containing encoded JavaScript payloads (e.g., %27onclick=%27|javascript:|<script) passed to endpoints that process ui.navigate.history navigation callsWAF mitigation (if patching is not yet possible)
Add this rule to your WAF to block exploitation attempts while you schedule the patch.
Block or sanitize URL parameters passed to backend endpoints that trigger ui.navigate.history.push() or ui.navigate.history.replace(). Implement output encoding rules to escape single quotes, angle brackets, and JavaScript protocol handlers in URL values before embedding them in generated JavaScript.How to check if you are affected
- Step 1: Check the installed NiceGUI version with: pip show nicegui | grep Version
- Step 2: Review your application code for calls to ui.navigate.history.push() or ui.navigate.history.replace() that accept external input: grep -r 'ui.navigate.history' /path/to/app --include='*.py'
- Step 3: Search web server logs for anomalous JavaScript payloads in URL parameters or POST data, particularly strings containing javascript: or script tags in navigated URLs
- Step 4: Verify the patch by re-running 'pip show nicegui' and confirming the version is 3.5.0 or higher
FAQ
What is CVE-2026-21871?
CVE-2026-21871 is a cross-site scripting (XSS) vulnerability in NiceGUI's history navigation API where unsafe URL arguments are embedded into JavaScript without proper escaping, allowing attackers to inject malicious code that executes in the user's browser.
Is CVE-2026-21871 being actively exploited?
No, CVE-2026-21871 is not currently listed in the CISA Known Exploited Vulnerabilities catalog and no public exploits have been released.
What versions of NiceGUI are affected by CVE-2026-21871?
NiceGUI versions 2.13.0 through 3.5.0 (exclusive) are vulnerable. Version 3.5.0 and later contain the patch.
How do I check if my server is vulnerable to CVE-2026-21871?
Run 'pip show nicegui' to check your installed version. If it is between 2.13.0 and 3.4.1 inclusive, and your application uses ui.navigate.history.push() or ui.navigate.history.replace() with untrusted input, you are vulnerable.
Does Defensia detect CVE-2026-21871?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If NiceGUI is installed on a monitored server, CVE-2026-21871 will appear in your dashboard with remediation steps.
Related Python CVEs
References
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2026-21871. Free for 1 server.
Get started free