CVE-2026-21873 Overview
CVE-2026-21873 is a Cross-Site Scripting (XSS) vulnerability affecting NiceGUI, a Python-based UI framework. The vulnerability stems from an unsafe implementation in the pushstate event listener used by ui.sub_pages, which allows an attacker to manipulate the fragment identifier of the URL through a cross-site iframe attack. This vulnerability affects versions 2.22.0 through 3.4.1 and has been addressed in version 3.5.0.
Critical Impact
Attackers can exploit this vulnerability to manipulate URL fragments cross-site using iframes, potentially leading to unauthorized actions, session manipulation, or information disclosure within applications built on the NiceGUI framework.
Affected Products
- NiceGUI versions 2.22.0 through 3.4.1
Discovery Timeline
- 2026-01-08 - CVE CVE-2026-21873 published to NVD
- 2026-01-08 - Last updated in NVD database
Technical Details for CVE-2026-21873
Vulnerability Analysis
This vulnerability is classified as CWE-79 (Cross-Site Scripting). The flaw exists in the pushstate event listener implementation within the ui.sub_pages component of NiceGUI. The unsafe handling of fragment identifiers in the URL allows attackers to bypass same-origin restrictions by embedding a vulnerable NiceGUI application within an iframe on a malicious website.
When a user visits an attacker-controlled page containing the malicious iframe, the attacker can manipulate the fragment portion of the URL (the part after the # symbol) even though the attack originates from a different site. This cross-site capability is particularly concerning as it can enable various attack scenarios including DOM-based XSS, state manipulation, and potential hijacking of application navigation flows.
Root Cause
The root cause of this vulnerability lies in the improper validation and handling of pushstate events within the ui.sub_pages functionality. The event listener does not adequately verify the origin of fragment identifier changes, allowing cross-origin manipulation through iframe embedding. This implementation oversight permits attackers to influence the application state despite browser same-origin policy protections that would normally prevent such cross-site interactions.
Attack Vector
The attack requires network access and can be executed without authentication. An attacker creates a malicious webpage containing an iframe that loads the target NiceGUI application. Through JavaScript manipulation, the attacker can modify the fragment identifier of the embedded application's URL. Since the vulnerable pushstate event listener does not properly validate the source of these changes, the manipulation is processed as legitimate navigation, potentially affecting application behavior, user sessions, or exposing sensitive information.
The vulnerability can be exploited by hosting a malicious iframe that targets vulnerable NiceGUI applications. When users visit the attacker's page, the embedded iframe allows fragment identifier manipulation that bypasses expected cross-site restrictions. For technical implementation details, refer to the GitHub Security Advisory GHSA-mhpg-c27v-6mxr.
Detection Methods for CVE-2026-21873
Indicators of Compromise
- Unexpected iframe embeddings of NiceGUI applications on external domains
- Anomalous URL fragment identifier changes in application logs
- Cross-origin requests targeting ui.sub_pages endpoints from unknown referrers
- User reports of unexpected application behavior or navigation redirects
Detection Strategies
- Monitor web server logs for requests with the Referer header indicating embedding on external domains
- Implement Content Security Policy (CSP) frame-ancestors directive to detect unauthorized iframe embedding attempts
- Review JavaScript console logs for pushstate event anomalies or cross-origin manipulation attempts
- Deploy web application firewalls (WAF) with rules to detect XSS patterns targeting fragment identifiers
Monitoring Recommendations
- Enable detailed logging for ui.sub_pages component interactions
- Configure alerts for applications being loaded within iframes from untrusted origins
- Monitor for unusual patterns in URL fragment changes that may indicate exploitation attempts
- Implement client-side monitoring to detect unexpected DOM modifications
How to Mitigate CVE-2026-21873
Immediate Actions Required
- Upgrade NiceGUI to version 3.5.0 or later immediately
- Audit all applications using ui.sub_pages functionality for potential exposure
- Implement Content Security Policy headers with restrictive frame-ancestors directive
- Review application logs for evidence of prior exploitation attempts
Patch Information
The vulnerability has been patched in NiceGUI version 3.5.0. The fix addresses the unsafe pushstate event listener implementation by adding proper origin validation for fragment identifier changes. Organizations should upgrade to this version or later as the primary remediation action. The patched release is available at the GitHub Release v3.5.0.
Workarounds
- Implement strict Content Security Policy headers with frame-ancestors 'self' to prevent iframe embedding
- Add X-Frame-Options header set to SAMEORIGIN or DENY for additional protection
- Deploy a reverse proxy or WAF to filter requests from unauthorized referrers
- Temporarily disable or restrict access to ui.sub_pages functionality if upgrading is not immediately possible
# Example nginx configuration to prevent iframe embedding
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Content-Security-Policy "frame-ancestors 'self';" always;
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

