CVE-2026-21873: NiceGUI apps which use `ui.sub_pages` vulnerable to zero-click XSS
Summary An unsafe implementation in the pushstate event listener used by ui.subpages allows an attacker to manipulate the fragment identifier of the URL, which they can do despite being cross-site, using an iframe. Details The problem is traced as follows: 1. On pushstate, handleStateEvent is executed.
Published Jan 8, 2026
Affected packages
nicegui
- Ecosystem
- PyPI
- Affected
- >= 2.22.0, <= 3.4.1
- Fixed in
- 3.5.0
- Check
pip show nicegui
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Summary
An unsafe implementation in the pushstate event listener used by ui.sub_pages allows an attacker to manipulate the fragment identifier of the URL, which _they can do despite being cross-site, using an iframe_.
Details
The problem is traced as follows:
- On
pushstate,handleStateEventis executed.
https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/elements/sub_pages.js#L38-L39
handleStateEventemitssub_pages_openevent.
https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/elements/sub_pages.js#L22-L25
SubPagesRouter(used byui.sub_pages), lisnening onsub_pages_open,_handle_openruns.
https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/sub_pages_router.py#L18-L22
_handle_openfinds anySubPagesand runs_show()on them
https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/sub_pages_router.py#L63-L71
- If the if-logic is followed or debug prints are added, it can be found that it calls
self._handle_scrolling(match, behavior='smooth')directly
https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/elements/sub_pages.py#L76-L100
- CULPRIT
_handle_scrollingruns_scroll_to_fragmentas there is a fragment, which runs vulnerable JS if thefragment(attacker-controlled) escapes out of the quotes.
https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/elements/sub_pages.py#L206-L217
PoC
Just visiting this page (no click required), consistently triggers XSS in https://nicegui.io domain.
<html>
<body>
<iframe id="myiframe" src="https://nicegui.io" width="100%" height="600px" onload="triggerXSS()"></iframe>
<script>
function triggerXSS() {
if (!myiframe.src.includes("#")) {
myiframe.src = "https://nicegui.io#x');alert(document.domain)//";
}
}
</script>
</body>
</html>Impact
Any page which uses ui.sub_pages and does not actively prevent itself from being put in an iframe is affected.
The impact is high since by-default NiceGUI pages are iframe-embeddable with no native opt-out functionalities except by manipulating the underlying app via FastAPI methods, and that ui.sub_pages is actively promoted as the new modern way to create Single-Page Applications (SPA).
Patch
- Not use
ui.sub_pages - Block iframe with the following code
@app.middleware('http')
async def iframe_blocking_middleware(request, call_next):
response = await call_next(request)
response.headers['X-Frame-Options'] = 'DENY'
return responseAppendix
AI is used safely to judge the CVSS scoring (input is censored).
Please find the results in https://poe.com/s/3FXuwp7TAYxqLomARXma
Scoring update after manual review
The scoring done by AI was quite biased. Upon further review it is less dramatic.
- User Interaction None: There's _almost_ no interaction required, and none of the interaction is with the vulnerable system.
- Confidentiality & Integrity Low: The extent of data confidentiality & integrity loss is bounded by the highest priviledged user in the entire NiceGUI application. There does not exist a means of performing data manipulating tasks that said admin cannot already do.
- Availability None: No DDoS is possible with this. Site remains performant as ever.
Credited to evnchn, falkoschindler.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More PyPI vulnerabilities
All PyPI entriesCVE-2026-45553
NiceGUI: Local file disclosure via Docutils file insertion in ui.restructured_text()
high7.5May 18, 2026CVE-2026-45554
NiceGUI: Unauthenticated log-volume denial of service in dynamic resource routes
medium5.3May 18, 2026CVE-2026-39844
NiceGUI: Upload filename sanitization bypass via backslashes allows path traversal on Windows
medium5.9Apr 8, 2026CVE-2026-33332
NiceGUI's unvalidated chunk size parameter in media routes can cause memory exhaustion
medium5.3Mar 19, 2026CVE-2026-27156
NiceGUI vulnerable to XSS via Code Injection during client-side element function execution
medium6.1Feb 24, 2026CVE-2026-25516
NiceGUI's XSS vulnerability in ui.markdown() allows arbitrary JavaScript execution through unsanitized HTML content
medium6.1Feb 5, 2026
