/

CVE-2026-31231

Severity:

CRITICAL RISK

(9.8)

Code Injection in Cognee Notebook Cell API

CVE-2026-31231

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Cognee through v0.4.0 exposes a notebook cell execution API that directly passes user-supplied Python code into the built-in exec() function without sandboxing or validation.

An attacker who can send requests to this endpoint can execute arbitrary Python code on the Cognee server with the privileges of the server process, potentially leading to full system compromise.

Affected context

The vulnerability appears in Cognee deployments that expose the notebook cell execution endpoint to users or other services.

In affected versions, the backend takes arbitrary Python source code from an HTTP POST body and executes it directly with exec() in the server environment.

This typically impacts multi-tenant or shared environments where the same server process handles requests for multiple users and where OS-level isolation is minimal or absent.

Exploit preconditions

  • Attack surface: HTTP API endpoint for notebook cell execution
  • Required access: Ability to send POST requests to the execution endpoint (e.g., network access, valid session if authentication is present)
  • Trigger point: Submission of Python source code that is executed by the backend using exec() without sandboxing
  • Why exploitation is possible: The server trusts incoming code as if it were trusted notebook content, runs it in the main process context, and does not enforce isolation, resource limits, or security checks around what the code may do

Why this happens

This issue stems from using Python's exec() function on attacker-controlled input within the main application process.

There is no separation between trusted and untrusted code, no restricted execution environment, and no policy to constrain what built-in modules or system calls the executed code may access.

Conceptually, this maps to CWE-94: Improper Control of Generation of Code, where dynamically supplied code is executed without appropriate validation, confinement, or trust boundaries.

The insecure pattern is treating a "notebook cell execution" feature as inherently safe while failing to acknowledge that each cell is arbitrary code with full interpreter privileges.

Potential impact

  • Arbitrary command execution on the Cognee server with the privileges of the application process
  • Reading, modifying, or deleting application data and configuration files
  • Installing backdoors or pivoting to other internal systems reachable from the server
  • Exfiltrating secrets such as API keys, database credentials, or tokens available in the environment
  • Denial of service by consuming excessive CPU, memory, or disk resources through malicious code

General mitigation guidance

Effective mitigation focuses on strictly controlling where and how user-supplied code is executed and reducing the trust placed in notebook content.

Common defensive patterns include:

  • Avoiding direct use of exec() on user-provided code; where dynamic execution is required, confine it to an isolated worker process, container, or virtual machine with minimal privileges
  • Applying strong authentication and authorization controls to any endpoint that can trigger code execution, ensuring only trusted principals may submit code
  • Implementing resource and capability limitations for executed code, such as restricted imports, constrained file-system access, and network isolation
  • Treating notebook cells as untrusted input by default and enforcing policy-based whitelisting of what operations are permitted
  • Separating control-plane APIs (e.g., notebook management) from data-plane execution environments to minimize blast radius if execution is abused

How teams detect issues like this

Detection efforts can focus on both code-level issues and runtime behavior:

  • Static analysis rules to flag direct or indirect use of exec(), eval(), or similar dynamic execution constructs when arguments may originate from HTTP requests or other untrusted sources
  • Code review checklists that require justification and explicit isolation for any dynamic code execution mechanisms in notebook or scripting features
  • Security policies that prohibit running untrusted code in the main application process, enforced through CI/CD checks and automated linters
  • Runtime monitoring and logging to detect anomalous behavior, such as unusual subprocess creation, file-system access patterns, or outbound network connections originating from the notebook execution path

Sources

SourceLink
github.comgithub.com/topoteretes/cognee
notion.sonotion.so/CVE-2026-31231-35d1e13931888178a963ef9efeb29113

Frequently asked

questions

Yes. If the notebook execution API is network-accessible, an attacker can exploit the issue remotely by sending crafted POST requests containing malicious Python code.

The attacker needs the ability to reach the execution endpoint and submit code. Depending on deployment, this may require authentication, but any principal that can execute notebook cells effectively gains code execution on the server.

The safest pattern is to avoid executing user-supplied code in the main server process. Instead, use isolated, least-privilege execution environments (such as separate containers or worker processes) for any notebook code, with strict access controls and resource limits.

Establish design guidelines that treat all user-contributed code as untrusted, prohibit unreviewed use of exec() and similar APIs, require isolation for any dynamic execution features, and enforce these rules through code review, static analysis, and security-focused testing.

Find out what's already
exploitable in your codebase.