{"id":1500,"cve":"CVE-2025-66469","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2025-66469\/","cwe":"CWE-79","cwe_number":79,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/79","cvss_score":6.1,"published":"2025-12-09","owasp":"A03 Injection","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Cross-Site Scripting (XSS)","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Reflected XSS in NiceGUI's CSS functions allows arbitrary JS execution.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2025-66469\/","description":"NiceGUI is a Python-based UI framework. Versions 3.3.1 and below are vulnerable to Reflected XSS through its ui.add_css, ui.add_scss, and ui.add_sass functions. The functions lack proper sanitization or encoding for the JavaScript context they generate. An attacker can break out of the intended <style> or <script> tags by injecting closing tags (e.g., <\/style> or <\/script>), allowing for the execution of arbitrary JavaScript. This issue is fixed in version 3.4.0.","solution":"Upgrade to version 3.4.0 or later.","affected_component":"NiceGUI","fixed_by_upgrading":true,"vulnerable_code":"from nicegui import ui, app\n\n@ui.page('\/')\ndef vulnerable_page():\n    ui.label('Demonstration of Reflected XSS Vulnerability')\n    ui.markdown('This page is vulnerable to XSS via the `style` query parameter.')\n\n    # Retrieve potentially malicious input from the URL query string.\n    payload = app.storage.request.query.get('style')\n\n    if payload:\n        # In the vulnerable version, the 'payload' is passed directly to ui.add_css\n        # without any sanitization or encoding.\n        # An attacker can close the intended <style> tag and inject a <script> tag.\n        # Example Payload: <\/style><script>alert('XSS Vulnerability Executed')<\/script>\n        ui.add_css(payload)\n        \n        ui.label('The following payload was injected:').classes('text-red-500')\n        ui.code(payload).classes('w-full')\n    else:\n        ui.label('To test the vulnerability, add a `style` query parameter to the URL.')\n        ui.link('Click here for a demonstration', '\/?style=<\/style><script>alert(\"XSS\")<\/script>')\n\n# To test the vulnerability, run this script and navigate to a URL like:\n# http:\/\/127.0.0.1:8080\/?style=<\/style><script>alert(\"This is a demonstration of CVE-2025-66469\")<\/script>\nui.run()","patched_code":"def _validate_css_for_injection(content: str) -> None:\n    \"\"\"\n    Prevents Reflected XSS by ensuring the provided content cannot break\n    out of the intended <style> context. This represents the core of the fix\n    for CVE-2025-66469.\n\n    It works by disallowing substrings that an attacker would use to close\n    the style tag and inject malicious script tags.\n    \"\"\"\n    # Use lowercase for case-insensitive matching\n    lower_content = content.lower()\n\n    # Block the primary injection vector: a closing style tag\n    if '<\/style>' in lower_content:\n        raise ValueError('CSS content is not allowed to contain \"<\/style>\".')\n\n    # As a defense-in-depth measure, also block closing script tags\n    if '<\/script>' in lower_content:\n        raise ValueError('CSS content is not allowed to contain \"<\/script>\".')\n\n\ndef add_css(content: str) -> None:\n    \"\"\"\n    Represents the fixed version of ui.add_css.\n\n    The fix is to call the validation function before any further processing.\n    \"\"\"\n    _validate_css_for_injection(content)\n    # ... original logic to add the validated CSS to the page would proceed here ...\n\n\ndef add_scss(content: str) -> None:\n    \"\"\"\n    Represents the fixed version of ui.add_scss.\n\n    The fix is to call the validation function before compilation and processing.\n    \"\"\"\n    _validate_css_for_injection(content)\n    # ... original logic to compile the validated SCSS and add it to the page would proceed here ...\n\n\ndef add_sass(content: str) -> None:\n    \"\"\"\n    Represents the fixed version of ui.add_sass.\n\n    The fix is to call the validation function before compilation and processing.\n    \"\"\"\n    _validate_css_for_injection(content)\n    # ... original logic to compile the validated SASS and add it to the page would proceed here ...","payload_needed":true,"payload":"```\n<\/style><script>alert('XSS')<\/script>\n```","payload_status":"available","published_fix":[{"repository":"zauberzeug\/nicegui","commit_url":"https:\/\/github.com\/zauberzeug\/nicegui\/commit\/a8fd25b7d5e23afb1952d0f60a1940e18b5f1ca8","commit_subject":"Merge commit from fork","units":[{"file":"nicegui\/functions\/style.py","function":"add_css"},{"file":"nicegui\/functions\/style.py","function":"add_scss"}]}],"references":null}