{"id":"CVE-2026-21871","aliases":["CVE-2026-21871","GHSA-7grm-h62g-5m97","PYSEC-2026-1698"],"related":[],"kind":"vulnerability","state":"published","title":"NiceGUI is vulnerable to XSS via Unescaped URL in ui.navigate.history.push() / replace()","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### 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","format":"markdown","source":"ghsa"},{"lang":"es","text":"NiceGUI es un framework de interfaz de usuario (UI) basado en Python. Desde las versiones 2.13.0 hasta la 3.4.1, existe un riesgo de XSS en NiceGUI cuando los desarrolladores pasan cadenas controladas por el atacante a ui.navigate.history.push() o ui.navigate.history.replace(). Estas funciones auxiliares están documentadas como envoltorios de la API de History para actualizar la URL del navegador sin recargar la página. Sin embargo, si el argumento de la URL se incrusta en JavaScript generado sin el escape adecuado, una carga útil diseñada puede salir del contexto de cadena previsto y ejecutar JavaScript arbitrario en el navegador de la víctima. Las aplicaciones que no pasan entradas no confiables a ui.navigate.history.push/replace no se ven afectadas. Este problema ha sido parcheado en la versión 3.5.0.","source":"nvd"}],"published":"2026-01-08T09:49:55.136Z","modified":"2026-07-07T17:57:28.403Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"}],"cwes":["CWE-79"],"affected":[{"ranges":[{"version":">= 2.13.0, < 3.5.0","status":"affected"}],"vendor":"zauberzeug","product":"nicegui","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"2.13.0","status":"affected","fixed":"3.5.0"}],"ecosystem":"PyPI","package":"nicegui","purl":"pkg:pypi/nicegui","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"2.13.0","fixed":"3.5.0"}],"vendor":"zauberzeug","product":"nicegui","cpe":"cpe:2.3:a:zauberzeug:nicegui:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"2.13.0","status":"affected","fixed":"3.5.0"}],"ecosystem":"PyPI","package":"nicegui","purl":"pkg:pypi/nicegui","source":"pysec"}],"references":[{"url":"https://github.com/zauberzeug/nicegui/security/advisories/GHSA-7grm-h62g-5m97","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/zauberzeug/nicegui/releases/tag/v3.5.0","tags":["release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-21871","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/zauberzeug/nicegui","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/nicegui","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-7grm-h62g-5m97","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-01-08T15:14:43.571Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-21871","url":"https://www.cve.org/CVERecord?id=CVE-2026-21871","licence":"CVE Terms of Use","modified":"2026-01-08T15:15:16.509Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-7grm-h62g-5m97","url":"https://github.com/advisories/GHSA-7grm-h62g-5m97","licence":"CC-BY-4.0","modified":"2026-07-07T17:57:28.403Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-21871","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-21871","licence":"Public domain","modified":"2026-06-17T10:19:03.873Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-1698","url":"https://osv.dev/vulnerability/PYSEC-2026-1698","licence":"CC-BY-4.0","modified":"2026-07-07T17:46:58.212Z"}],"updatedAt":"2026-11-25T22:59:12.659Z","epss":{"score":0.00273,"percentile":0.21078,"date":"2026-12-01T12:00:22.000Z"}}