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

MODERATE
Advisory Identifier: GHSA-m7j5-rq9j-6jj9
CVSS 6.1
CWE-79
Published
Advisory Summary

CVE-2026-21872 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 apps are vulnerable to xss which uses `ui.sub_pages` and render arbitrary user-provided links. Remediation is available by upgrading affected packages to version 3.5.0.

CVE-2026-21872 at a Glance

CVE Identifier CVE-2026-21872
GHSA Identifier GHSA-m7j5-rq9j-6jj9
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-21872

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-21872, 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 An unsafe implementation in the `click` event listener used by `ui.sub_pages`, combined with attacker-controlled link rendering on the page, causes an XSS when the user actively clicks on the link. ### Details 1. On `click`, eventually `sub_pages_navigate` event is emitted. https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/elements/sub_pages.js#L41-L63 2. SubPagesRouter (used by ui.sub_pages), lisnening on `sub_pages_navigate`, `_handle_navigate` runs. https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/sub_pages_router.py#L18-L22 3. `_handle_navigate` runs `run_javascript` with f-string substituting `self.current_path` which is simply surrounded by double-quotes. The string context can be broken out easily. https://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/sub_pages_router.py#L73-L88 ### PoC The minimal PoC boils down to this: ```py from nicegui import ui ui.sub_pages({'/': lambda: ui.link('Go to XSS', '/"+alert(1)+"')}) ui.run() ``` However, it is more likely that the attack takes place with attacker-controlled input, for which this shows it: ```py from nicegui import app, ui ui.sub_pages({'/': lambda: ui.label('Hello, World!')}) ui.textarea('Markdown content').bind_value(app.storage.general, 'markdown_content') ui.markdown().bind_content_from(app.storage.general, 'markdown_content') ui.run() ``` Vulnerable input is `[XSS LINK](/"+alert(document.domain)+")` (causes double payload execution, though) **Both cases require someone to click on the link.** <img width="1428" height="254" alt="image" src="https://github.com/user-attachments/assets/8be4f345-c0cf-4df2-9917-677a2ea72626" /> ### Impact Any page which uses `ui.sub_pages` and renders arbitrary links on screen (common case of `ui.markdown`) is affected. The impact is low since a click is always required from the user, who can on-hover to discover the sketchy content of the link and stop if well-trained. ### Appendix AI is used safely to judge the CVSS scoring (input is not even provided, just the impact statement). Please find the results in https://poe.com/s/y5DvyqgtszDGLUuHin1O ### Scoring update after manual review - Scope **Changed** is more inline with other posted XSS vulnerabilities - Availability **None**: No DDoS is possible with this. Site remains performant as ever.

CVE-2026-21872 Affected Nicegui Versions

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

References

Frequently Asked Questions

What is CVE-2026-21872?
CVE-2026-21872 is a security vulnerability in Nicegui involving NiceGUI apps are vulnerable to XSS which uses `ui.sub_pages` and render arbitrary user-provided links 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-21872?
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-21872?
CVE-2026-21872 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-21872?
CVE-2026-21872 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-21872?
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-m7j5-rq9j-6jj9",
  "modified" : "2026-01-08T20:08:42Z",
  "published" : "2026-01-08T20:08:42Z",
  "aliases" : [ "CVE-2026-21872" ],
  "summary" : "NiceGUI apps are vulnerable to XSS which uses `ui.sub_pages` and render arbitrary user-provided links",
  "details" : "### Summary\n\nAn unsafe implementation in the `click` event listener used by `ui.sub_pages`, combined with attacker-controlled link rendering on the page, causes an XSS when the user actively clicks on the link. \n\n### Details\n\n1. On `click`, eventually `sub_pages_navigate` event is emitted.\nhttps://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/elements/sub_pages.js#L41-L63\n\n2. SubPagesRouter (used by ui.sub_pages), lisnening on `sub_pages_navigate`, `_handle_navigate` runs.\nhttps://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/sub_pages_router.py#L18-L22\n\n3. `_handle_navigate` runs `run_javascript` with f-string substituting `self.current_path` which is simply surrounded by double-quotes. The string context can be broken out easily. \n\nhttps://github.com/zauberzeug/nicegui/blob/59fa9424c470f1b12c5d368985fa36e21fda706b/nicegui/sub_pages_router.py#L73-L88\n\n### PoC\n\nThe minimal PoC boils down to this:\n\n```py\nfrom nicegui import ui\n\nui.sub_pages({'/': lambda: ui.link('Go to XSS', '/\"+alert(1)+\"')})\n\nui.run()\n```\n\nHowever, it is more likely that the attack takes place with attacker-controlled input, for which this shows it:\n\n```py\nfrom nicegui import app, ui\n\nui.sub_pages({'/': lambda: ui.label('Hello, World!')})\n\nui.textarea('Markdown content').bind_value(app.storage.general, 'markdown_content')\n\nui.markdown().bind_content_from(app.storage.general, 'markdown_content')\n\nui.run()\n```\n\nVulnerable input is `[XSS LINK](/\"+alert(document.domain)+\")` (causes double payload execution, though)\n\n**Both cases require someone to click on the link.** \n\n<img width=\"1428\" height=\"254\" alt=\"image\" src=\"https://github.com/user-attachments/assets/8be4f345-c0cf-4df2-9917-677a2ea72626\" />\n\n### Impact\n\nAny page which uses `ui.sub_pages` and renders arbitrary links on screen (common case of `ui.markdown`) is affected.\n\nThe impact is low since a click is always required from the user, who can on-hover to discover the sketchy content of the link and stop if well-trained. \n\n### Appendix\n\nAI is used safely to judge the CVSS scoring (input is not even provided, just the impact statement).\n\nPlease find the results in https://poe.com/s/y5DvyqgtszDGLUuHin1O\n\n### Scoring update after manual review\n\n- Scope **Changed** is more inline with other posted XSS vulnerabilities\n- Availability **None**: No DDoS is possible with this. Site remains performant as ever.",
  "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.22.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-m7j5-rq9j-6jj9"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-21872"
  }, {
    "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:08:42Z",
    "nvd_published_at" : "2026-01-08T10:15:55Z"
  }
}