/

CVE-2026-31251

Severity:

HIGH RISK

(7.3)

Unsafe Deserialization in CosyVoice gRPC Server

CVE-2026-31251

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-20, CWE-94, CWE-915

Impact:

Remote Code Execution

Severity:

HIGH RISK

(7.3)

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

CosyVoice's gRPC server component insecurely deserializes model files using torch.load() without restricting deserialization to tensor weights only.

If a user points the server to a directory containing a malicious model file, arbitrary Python objects can be instantiated during startup, leading to remote code execution on the host running the server.

Affected context

The vulnerability arises in deployments of the CosyVoice gRPC server where the speech synthesis model directory is user-configurable.

At server startup, model artifacts in the provided directory are loaded with torch.load() using default settings, which rely on Python's pickle mechanism.

In environments where users, scripts, or orchestration systems can influence the model directory or its contents, untrusted model files may be processed before any additional validation or sandboxing is applied.

Exploit preconditions

  • Attack surface: Local or remote, depending on how the model directory path is supplied (e.g., CLI flags, environment variables, configuration files, or orchestration tools).
  • Required access: Ability to place or replace model files in the target directory, or to influence which directory the gRPC server uses at startup.
  • Trigger point: Initialization of the CosyVoice gRPC server, when it calls torch.load() on model files in the configured directory.
  • Why exploitation is possible: torch.load() defaults to pickle-based deserialization of arbitrary Python objects and is invoked without weights_only=True or equivalent restrictions, allowing attacker-controlled constructors to run during deserialization.

Why this happens

This issue stems from treating model artifacts as inherently trusted input and using a generic deserialization mechanism that executes embedded Python object constructors.

Specifically, torch.load() is invoked without restricting deserialization to tensor weights or enforcing a constrained object graph, effectively exposing a raw pickle deserialization path.

This matches the unsafe deserialization bug class, where data formats designed for trusted environments are applied to untrusted or semi-trusted inputs.

Contributing weaknesses include insufficient input validation (CWE-20), improper code generation or execution from data (CWE-94), and improper resource or interpreter control when deserializing complex objects (CWE-915).

Potential impact

  • Execution of arbitrary OS-level commands under the privileges of the process running the gRPC server
  • Full compromise of the host running CosyVoice, including potential lateral movement in the environment
  • Tampering with or sabotaging speech synthesis pipelines and generated audio output
  • Establishment of persistence mechanisms via backdoored model artifacts
  • Use of the compromised server as a pivot point to access internal services or data

General mitigation guidance

Effective mitigation focuses on restricting deserialization capabilities and tightening trust boundaries for model files:

  • Prefer deserialization modes that limit loading to tensor weights only or use safer, format-constrained serialization APIs.
  • Treat model directories as sensitive inputs and ensure they can only reference artifacts from trusted, authenticated sources.
  • Introduce explicit validation of model files, such as verifying checksums, signatures, or format-specific metadata before loading.
  • Run the gRPC server with least-privilege accounts and apply OS-level hardening (e.g., restricted filesystem access, application sandboxing).
  • Separate responsibilities so that model creation and deployment are controlled processes, reducing the chance that arbitrary users can influence runtime model artifacts.

How teams detect issues like this

Detection typically combines code-level and operational signals:

  • Use static analysis or manual review to identify calls to torch.load() or other pickle-backed APIs that operate on configurable paths or user-controlled inputs.
  • Enforce code review rules that flag unrestricted deserialization within server startup paths or other privileged initialization routines.
  • Apply security policies in CI/CD pipelines that prohibit generic pickle usage for untrusted artifacts, or require explicit justifications and safeguards.
  • Monitor runtime behavior for unusual subprocess launches, file writes, or network connections originating from the gRPC server process during startup, which may indicate malicious model payloads.

Sources

SourceLink
github.comgithub.com/FunAudioLLM/CosyVoice
notion.sonotion.so/CVE-2026-31251-35d1e1393188816f9bf5f3ccea3aa16f

Frequently asked

questions

It can be, if an attacker can remotely influence the model directory or its contents—for example, via a deployment pipeline, network-shared storage, or a control plane that fetches models from external sources. If the model path and files are strictly local and tightly controlled, the exposure is reduced.

An attacker needs the ability to place or modify model files in a directory that the CosyVoice gRPC server will use, or to control the configuration that specifies that directory. This could be achieved through compromised storage, misconfigured permissions, or a manipulated deployment process.

The most robust pattern is to eliminate generic pickle-based deserialization for untrusted or semi-trusted inputs, using safer loading modes that restrict to tensor weights or structured formats. Combined with this, ensure that only authenticated and integrity-checked model artifacts are accepted by the server.

Establish a policy that any deserialization of complex objects, especially in startup or privileged code paths, must use constrained formats and undergo security review. Integrate checks for unsafe deserialization into code scanning and CI pipelines, and limit who can introduce or modify model artifacts used by production systems.

Find out what's already
exploitable in your codebase.