/

CVE-2026-31220

Severity:

CRITICAL RISK

(9.8)

Code Injection / Remote Code Execution in PySyft Server

CVE-2026-31220

Deferred

Vulnerability type

Category:

Code Injection / Remote Code Execution

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

PySyft Datasite/Server allows low-privileged users to submit Python functions for remote execution, but these functions are executed using exec() and eval() without adequate validation or sandboxing.

Once a function is approved through the existing review mechanism, an attacker can execute arbitrary Python code on the server, potentially taking full control of the server environment.

Affected context

This vulnerability appears in PySyft Datasite/Server deployments that:

  • Allow users to submit Python functions via @sy.syft_function() for remote execution
  • Rely on a human or workflow-based "approval" step without automated security checks
  • Execute approved code in the main server process using dynamic evaluation (exec, eval)
  • Do not use OS-level or interpreter-level sandboxes, container isolation, or strict policy enforcement

Risk is highest in multi-tenant or shared environments where untrusted or semi-trusted users can upload code.

Exploit preconditions

  • Attack surface: Network-accessible PySyft Datasite/Server endpoints that accept user-submitted functions.
  • Required access: Low-privileged or regular user ability to submit Python functions for review/approval.
  • Trigger point: Execution of an approved @sy.syft_function() on the server, which runs via exec()/eval() in the server process.
  • Why exploitation is possible: The system treats user-supplied code as trusted after approval, but performs no security or policy checks for dangerous operations and runs the code without sandboxing or privilege separation, allowing arbitrary Python execution.

Why this happens

The core issue is a code injection pattern where user-controlled Python source is executed directly with exec() and eval() inside the server process.

This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), where dynamically built or supplied code is executed without robust validation, constraints, or isolation.

The approval workflow focuses on functional correctness rather than enforcing a strict, machine-verifiable safety policy, and no sandbox or restricted execution environment is used to contain the behavior of approved functions.

Potential impact

  • Execution of arbitrary Python code on the server
  • Reading, modifying, or deleting files accessible to the server process
  • Accessing or exfiltrating sensitive data managed by PySyft or co-located services
  • Running system commands or spawning subprocesses (where permitted by the environment)
  • Establishing persistence or backdoors on the host
  • Using the compromised server as a pivot point for lateral movement within the infrastructure

General mitigation guidance

Mitigation typically focuses on strictly limiting what user-submitted code can do and moving untrusted execution into hardened boundaries:

  • Replace generic exec()/eval() execution of user code with structured, declarative APIs (e.g., whitelisted operations, computation graphs, or domain-specific languages) that do not accept raw Python source.
  • Introduce a sandboxed execution environment (such as isolated containers, separate processes, or restricted interpreters) with tightly controlled interfaces, resource limits, and no direct access to OS primitives or sensitive files.
  • Apply policy-based checks to submitted code or tasks (for example, static filters that reject disallowed modules, attributes, or operations) before approval.
  • Enforce least privilege for the execution context so that even if code misbehaves, it has minimal filesystem, network, and process-level permissions.
  • Treat code approval as a security decision: incorporate security criteria and, where possible, automated checks to ensure dangerous operations are not allowed.

How teams detect issues like this

Detection can combine code-level review with runtime monitoring:

  • Use static analysis or linting rules to flag usage of exec(), eval(), or similar dynamic execution constructs tied to user input paths.
  • During code review, look for patterns where user-supplied functions or scripts are accepted and executed without a well-defined sandbox or policy enforcement layer.
  • Implement logging around user-submitted function approval and execution, capturing which users submitted which functions and what operations they perform.
  • Monitor runtime behavior for unusual file, network, or process activity originating from the worker or server components that handle user functions.
  • Enforce CI/CD checks that disallow new dynamic execution entry points unless they are explicitly justified and wrapped in controlled, sandboxed environments.

Sources

SourceLink
github.comgithub.com/OpenMined/PySyft
notion.sonotion.so/CVE-2026-31220-35d1e1393188814186b9e00114a8aba7

Frequently asked

questions

Yes. As long as an attacker can reach the PySyft server interface and has the ability to submit functions for approval, they can potentially achieve remote code execution once a function is approved.

The attacker typically needs low-privileged user access sufficient to upload or submit @sy.syft_function() definitions. They do not need administrative access if the workflow allows non-admin users to submit code for approval.

The safest approach is to remove direct execution of user-provided Python source via exec()/eval() and instead run untrusted logic in a tightly controlled, sandboxed environment or replace raw code execution with a constrained, declarative API that cannot express arbitrary OS-level operations.

Avoid designs that execute arbitrary user-supplied code, and where computation needs to be user-defined, enforce a combination of sandboxing, least privilege, and strict policy checks. Incorporate automated detection for dynamic execution constructs and treat any new user-code execution feature as a high-risk area requiring careful security review.

Find out what's already
exploitable in your codebase.