CVE-2026-21871: Nicegui Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-7grm-h62g-5m97
CVSS 6.1
CWE-79
Published
Advisory Summary

CVE-2026-21871 is a MODERATE (CVSS 6.1) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Nicegui libraries in the PyPI ecosystem. The issue involves nicegui is vulnerable to xss via unescaped url in ui.navigate.history.push() / replace(). Remediation is available by upgrading affected packages to version 3.5.0.

CVE-2026-21871 at a Glance

CVE Identifier CVE-2026-21871
GHSA Identifier GHSA-7grm-h62g-5m97
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Nicegui
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2026-21871

To remediate this vulnerability, upgrade all affected Nicegui dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nicegui fixed: 3.5.0
pip install nicegui>=3.5.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show nicegui

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-21871, inspect your installed packages using pip:

pip show nicegui

Analyze the terminal output to locate any version of Nicegui in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.5.0), your application is affected.

Note: The pip show nicegui command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Nicegui, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary XSS risk exists 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.** ### Details NiceGUI provides `ui.navigate.history.push(url)` and `ui.navigate.history.replace(url)` to update the URL using the browser History API. If an application forwards user-controlled data (e.g., URL path segments, query parameters like `next=...`, form values, etc.) into these methods, an attacker can inject characters such as quotes and statement terminators to escape the JavaScript string context and execute arbitrary code. A vulnerable pattern is: - attacker controls a value (e.g., via the request path), - the application passes it to `ui.navigate.history.push(payload)` (or `replace`). This is similar in spirit to other NiceGUI XSS advisories: - `ui.html()`,`ui.chat_message()` can cause XSS when developers render untrusted input as HTML (XSS risk/footgun). - `ui.interactive_image` had XSS via unsanitized SVG content and was handled as a security advisory with a fix and severity rating. Because `ui.navigate.history.*` is expected to accept a URL (data) rather than executable code, the library should escape/encode the argument before emitting JavaScript. ### PoC #### Create a simple app ```python from nicegui import ui @ui.page('/') def index(): # A link/button a victim could click (attacker can also send the URL directly) ui.button('open crafted path', on_click=lambda: ui.navigate.to('/%22);alert(document.domain);//')) @ui.page('/{payload:path}') def victim(payload: str): ui.label(f'payload = {payload!r}') # Vulnerable use: forwarding attacker-controlled path to history.push ui.button('trigger', on_click=lambda: ui.navigate.history.push(payload)) ui.run() ``` #### Run the app ```bash python app.py ``` #### Trigger 1. Open `http://localhost:8080/` 2. Click `open crafted path` 3. Click `trigger` Expected result: JavaScript executes (an alert showing `document.domain`). ### Impact - Vulnerability type: DOM-based XSS - Attack vector: attacker-controlled input embedded into JavaScript via `ui.navigate.history.push/replace` - Affected users: any NiceGUI-based application that forwards untrusted input into `ui.navigate.history.push()` or `ui.navigate.history.replace()` - Potential outcomes: client-side code execution, phishing UI injection, and other typical XSS impacts

CVE-2026-21871 Affected Nicegui Versions

1 component(s)
Fixed Versions:
3.5.0
Product / Package Ecosystem Affected Versions Fixed Version
nicegui
PyPI
≥ 2.13.0
< 3.5.0
3.5.0

References

Frequently Asked Questions

What is CVE-2026-21871?
CVE-2026-21871 is a security vulnerability in Nicegui involving NiceGUI is vulnerable to XSS via Unescaped URL in ui.navigate.history.push() / replace() under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Nicegui versions are affected?
Affected versions include releases prior to 3.5.0 across affected packages: nicegui.
What version fixes CVE-2026-21871?
Upgrading to 3.5.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nicegui affected?
Yes, nicegui is affected in releases prior to 3.5.0. Upgrade your dependency to 3.5.0 or later.
What is the CVSS score of CVE-2026-21871?
CVE-2026-21871 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2026-21871?
CVE-2026-21871 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check PyPI dependencies for CVE-2026-21871?
Run the dependency tree command: 'pip show nicegui'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7grm-h62g-5m97",
  "modified" : "2026-01-08T20:00:29Z",
  "published" : "2026-01-08T20:00:29Z",
  "aliases" : [ "CVE-2026-21871" ],
  "summary" : "NiceGUI is vulnerable to XSS via Unescaped URL in ui.navigate.history.push() / replace()",
  "details" : "### Summary\nXSS risk exists 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.\n\n**Applications that do not pass untrusted input into `ui.navigate.history.push/replace` are not affected.**\n\n### Details\nNiceGUI provides `ui.navigate.history.push(url)` and `ui.navigate.history.replace(url)` to update the URL using the browser History API. If an application forwards user-controlled data (e.g., URL path segments, query parameters like `next=...`, form values, etc.) into these methods, an attacker can inject characters such as quotes and statement terminators to escape the JavaScript string context and execute arbitrary code.\n\nA vulnerable pattern is:\n- attacker controls a value (e.g., via the request path),\n- the application passes it to `ui.navigate.history.push(payload)` (or `replace`).\n\nThis is similar in spirit to other NiceGUI XSS advisories:\n- `ui.html()`,`ui.chat_message()` can cause XSS when developers render untrusted input as HTML (XSS risk/footgun).\n- `ui.interactive_image` had XSS via unsanitized SVG content and was handled as a security advisory with a fix and severity rating.\n\nBecause `ui.navigate.history.*` is expected to accept a URL (data) rather than executable code, the library should escape/encode the argument before emitting JavaScript.\n\n### PoC\n#### Create a simple app\n\n```python\nfrom nicegui import ui\n\n@ui.page('/')\ndef index():\n    # A link/button a victim could click (attacker can also send the URL directly)\n    ui.button('open crafted path', on_click=lambda: ui.navigate.to('/%22);alert(document.domain);//'))\n\n@ui.page('/{payload:path}')\ndef victim(payload: str):\n    ui.label(f'payload = {payload!r}')\n\n    # Vulnerable use: forwarding attacker-controlled path to history.push\n    ui.button('trigger', on_click=lambda: ui.navigate.history.push(payload))\n\nui.run()\n```\n\n#### Run the app\n\n```bash\npython app.py\n```\n\n#### Trigger\n\n1. Open `http://localhost:8080/`\n2. Click `open crafted path`\n3. Click `trigger`\n\nExpected result: JavaScript executes (an alert showing `document.domain`).\n\n### Impact\n- Vulnerability type: DOM-based XSS\n- Attack vector: attacker-controlled input embedded into JavaScript via `ui.navigate.history.push/replace`\n- Affected users: any NiceGUI-based application that forwards untrusted input into `ui.navigate.history.push()` or `ui.navigate.history.replace()`\n- Potential outcomes: client-side code execution, phishing UI injection, and other typical XSS impacts",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "nicegui"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.13.0"
      }, {
        "fixed" : "3.5.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.4.1"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/zauberzeug/nicegui/security/advisories/GHSA-7grm-h62g-5m97"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-21871"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/zauberzeug/nicegui"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/zauberzeug/nicegui/releases/tag/v3.5.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-01-08T20:00:29Z",
    "nvd_published_at" : "2026-01-08T10:15:55Z"
  }
}