Oct 6, 2026·6 min read·24 visits
PyMongo's CSFLE key management parsing evaluates '.sock' suffixes as local Unix domain sockets rather than remote hostnames. Attackers with database write access can exploit this to achieve local SSRF against Unix domain sockets on the application host.
A vulnerability in the Client-Side Field-Level Encryption (CSFLE) component of the MongoDB Python Driver (PyMongo) allows an attacker with database write access to trigger local Unix domain socket connections. By manipulating the Key Management Service (KMS) endpoint configuration inside the key vault collection to end with a '.sock' extension, an attacker forces the application to perform a Server-Side Request Forgery (SSRF) against internal Unix domain sockets.
PyMongo, the official Python driver for MongoDB, supports Client-Side Field-Level Encryption (CSFLE) and Queryable Encryption to allow applications to encrypt fields before transmitting them to the database. This implementation relies on a local or remote Key Management Service (KMS) to wrap and unwrap data encryption keys. These keys are defined by metadata documents stored within a dedicated vault collection inside the MongoDB instance, typically named admin.datakeys.
The vulnerability arises from how the PyMongo driver handles address resolution for these KMS endpoints. During the decryption or encryption pipeline, PyMongo parses the configured endpoint using its internal helper function parse_host(). This function contains legacy routing logic designed to support local Unix domain sockets for MongoDB server connections.
When a KMS endpoint ends with the .sock suffix, the driver improperly treats it as a local filesystem path rather than a remote hostname. This behavior exposes a Server-Side Request Forgery (SSRF) vector categorized under CWE-918. A malicious user who possesses write access to the database's key vault collection can manipulate these endpoint configurations to force the client application to open connections to internal sockets.
The root cause of CVE-2026-96747 resides within the interaction between PyMongo's generalized connection string parsing logic and the CSFLE connection initiation routines. PyMongo's host parsing function, parse_host(), evaluates connection strings to determine the target protocol family. If the input string ends with the suffix .sock, the function skips normal DNS resolution and port validation.
Instead of generating a standard AF_INET or AF_INET6 socket configuration, parse_host() treats the input verbatim as a Unix domain socket path. This returns a resolved address tuple where the protocol family is flagged for Unix IPC. This design was originally intended to simplify local development by allowing developers to pass local socket paths like /var/run/mongodb-27017.sock as the MongoDB URI.
However, the CSFLE engine utilizes this exact same parse_host() routine when establishing connections to external KMS systems. The driver extracts the masterKey.endpoint value directly from the decrypted key metadata retrieved from the database. Because no validation restricts KMS endpoints to TCP/IP hosts, a .sock endpoint is processed without validation. The driver's internal socket creation module _create_connection intercepts the parsed address and attempts to establish an AF_UNIX connection to the specified path on the application host.
The vulnerability was addressed in PyMongo version 4.18.2 by implementing explicit string validation immediately after the host parsing step. In both synchronous and asynchronous implementations of the encryption module, the driver now checks the parsed address structure to prevent Unix domain socket paths from being used as KMS endpoints.
The fix is applied inside pymongo/synchronous/encryption.py and pymongo/asynchronous/encryption.py within the kms_request() method. Below is an annotated visual representation of the patch diff:
# Vulnerable implementation in pymongo/synchronous/encryption.py
address = parse_host(endpoint, _HTTPS_PORT)
sleep_u = kms_context.usleep
# Patched implementation in pymongo/synchronous/encryption.py
address = parse_host(endpoint, _HTTPS_PORT)
# Fix: Intercept and reject any endpoint that resolves to a local socket path
if address[0].endswith(".sock"):
raise ConfigurationError(f"Invalid KMS endpoint {endpoint!r}")
sleep_u = kms_context.usleepThis validation effectively mitigates the vulnerability by raising a ConfigurationError before any socket creation routine can be triggered. However, the driver still relies heavily on the parse_host helper, which continues to accept .sock configurations globally. While this fix successfully secures the CSFLE connection path, developers must ensure that any custom implementations utilizing parse_host for external network resources implement similar validations.
Exploitation of CVE-2026-96747 requires an attacker to achieve specific database-level privileges. Specifically, the adversary must have write privileges (insert or update) on the collection housing the client-side encryption keys, which is typically admin.datakeys. This level of access corresponds to the Low Privileges requirement specified in the CVSS metrics.
Once access is established, the attacker identifies a target data key document inside the collection and updates the masterKey.endpoint field. The attacker sets this field to point to a sensitive Unix domain socket on the application server. The diagram below illustrates the communication flow during an exploit attempt:
After the database is poisoned, the attack is triggered passively when a legitimate user or application process executes a query requiring CSFLE encryption or decryption. PyMongo automatically fetches the poisoned key from the key vault to decrypt the required fields. During the key unwrapping phase, the driver parses the malicious KMS endpoint, resolves it to the local Unix socket, and establishes a connection.
The direct impact of successful exploitation is a local Server-Side Request Forgery (SSRF) that allows the driver to interact with arbitrary Unix domain sockets on the host operating system. Depending on the environment, this could allow an attacker to connect to critical local sockets. Examples of target sockets include container management runtimes like /var/run/docker.sock or local application IPC sockets.
However, the attack is bound by strict constraints inherent to PyMongo's connection lifecycle. Because the driver expects a secure KMS endpoint, it initiates a TLS handshake immediately upon establishing the socket connection. The only data transmitted over the Unix domain socket is the binary payload of a standard TLS ClientHello message.
This limitation prevents the attacker from transmitting arbitrary commands, such as HTTP REST API calls or custom socket commands. As a result, direct remote code execution or privilege escalation via container APIs is not feasible through this vector alone. The threat is primarily limited to probing for socket existence, triggering socket resource exhaustion, or inducing unexpected application state changes or crashes.
The recommended remediation path is upgrading PyMongo to version 4.18.2 or later, which completely disables Unix socket connections for KMS endpoints. In environments where an immediate upgrade is not feasible, security administrators should implement strict role-based access control (RBAC). Restricting write access to the key vault collection prevents unauthorized modifications to the KMS endpoints.
Additionally, network and system-level hardening should be deployed to minimize the attack surface of local sockets. If the application runs within a containerized environment, avoid mounting critical sockets like docker.sock inside the container namespace. Utilizing container security profiles, such as AppArmor or SELinux, can also restrict the application's ability to interact with host-level IPC mechanisms.
Finally, auditing should be enabled on the MongoDB database to track all write operations targeting the key vault collections. Any configuration changes that introduce non-standard endpoints, especially those ending with the .sock suffix, should trigger high-priority alerts within security information and event management (SIEM) systems.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:N/A:N| Product | Affected Versions | Fixed Version |
|---|---|---|
PyMongo (MongoDB Python Driver) MongoDB | >= 3.9.0, < 4.18.2 | 4.18.2 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-918 (Server-Side Request Forgery) |
| Attack Vector | Network (AV:N) |
| CVSS v3.1 Score | 5.0 (Medium) |
| Exploit Maturity | none (no public PoC available) |
| CISA KEV Status | Not Listed |
| Privileges Required | Low (requires write access to key vault) |
| Impact Category | Low Confidentiality / Information Disclosure via SSRF |
The web server receives a URL or similar request pointing to an upstream service and retrieves the representation of this resource, without sufficiently ensuring that the request is directed at the intended destination.
CVE-2026-126360 (GHSA-mf5v-w3w3-f6cg) is an algorithmic complexity vulnerability (Regular Expression Denial of Service) in the trace context propagation logic of the opentelemetry-api package within the OpenTelemetry Python ecosystem. In versions prior to 1.45.2, the TraceContextTextMapPropagator.extract() method utilizes a regular expression susceptible to quadratic-time backtracking when parsing malformed W3C traceparent headers containing long sequences of whitespace followed by an embedded newline character. In Python applications—particularly those using single-threaded asynchronous event loops—an unauthenticated remote attacker transmitting payloads over newline-preserving carriers can monopolize CPU execution and induce application-level Denial of Service.
CVE-2026-126359 (GHSA-3gg2-335m-rxc6) is an improper input neutralization vulnerability (CWE-79) in the Hono web framework (`honojs/hono`). Versions from 3.12.0 prior to 4.13.16 evaluate and escape interpolated strings in the `hono/css` helper individually before concatenating template chunks and stripping CSS comments. When a `<` character and a `/style>` sequence are split across template boundaries, adjacent interpolations, or separated by a CSS comment, the sanitizer fails to escape the closing tag sequence. During Server-Side Rendering (SSR), the `<Style />` component outputs an unescaped `</style>` delimiter, permitting an attacker to break out of the CSS raw text context and execute arbitrary HTML and JavaScript in the victim's browser.
An incorrect authorization vulnerability (CWE-863) exists in the Hono web application framework (npm package `hono`) from version 4.1.4 prior to 4.13.16. Flaws in the registration-time coverage calculation and regular expression compilation within `RegExpRouter` cause wildcard middleware to be omitted under three specific routing conditions: parameter pattern equivalence mismatches, wildcard boundary collisions, and request paths containing percent-encoded line terminators. Because Hono's default `SmartRouter` selects `RegExpRouter` for most standard web applications, unauthenticated remote clients can bypass authentication, authorization, or security middleware registered on wildcard paths to directly access protected route handlers or the application's not-found handler.
CVE-2026-126357 (GHSA-4m76-xfj5-7975) is an authentication bypass vulnerability in the Hono web application framework prior to version 4.13.16. The flaw resides in the prefix-stripping and URL reconstruction logic of `app.mount()` and the `mount()` middleware. Two distinct path transformation errors—static route-pattern length slicing on dynamic prefixes and URL normalization of decoded pathnames—create a routing discrepancy between the outer Hono router and the mounted sub-application. An unauthenticated attacker can exploit these discrepancies to bypass outer authentication or authorization middleware and access protected inner routes directly.
A parser differential vulnerability exists in the Hono web application framework versions 4.5.1 prior to 4.13.16. The built-in form validation middleware (`validator('form')`) utilizes an overly restrictive regular expression to evaluate the HTTP `Content-Type` header for `multipart/form-data` payloads. When a client supplies additional valid MIME parameters (such as `charset=utf-8`) or multiple whitespace characters following a semicolon delimiter, the regular expression fails to match. Consequently, the validator passes an empty object to the validation callback instead of the parsed form fields. If the validation logic permits empty objects or only checks for disallowed values on optional properties, the request passes validation, allowing downstream route handlers calling `c.req.parseBody()` or `c.req.formData()` to process unvalidated user input.
CVE-2026-126355 (GHSA-46wx-v44x-9hh2) is a Cross-Site Request Forgery (CSRF) validation bypass in Hono, a web application framework for JavaScript runtimes. Prior to version 4.13.16, Hono's built-in csrf() middleware only evaluated origin headers for requests matching standard HTML form MIME types (application/x-www-form-urlencoded, multipart/form-data, and text/plain). By leveraging the HTML anchor ping attribute in Chromium-based browsers, an attacker can initiate an unprompted, credentialed cross-origin HTTP POST request with Content-Type: text/ping without triggering a CORS preflight request. Because text/ping was omitted from the middleware regular expression, requests bypassed Origin and Sec-Fetch-Site verification, allowing unauthorized state-changing operations.