/

CVE-2026-31232

Severity:

HIGH RISK

(8.8)

Unsafe Deserialization in CosyVoice Model Loading

CVE-2026-31232

Awaiting Analysis

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.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

CosyVoice contains an unsafe deserialization flaw in its model loading process when reading .pt files from a user-specified --model_dir directory using torch.load() without weights_only=True.

If a victim loads a malicious model directory via the CosyVoice web interface, arbitrary Python objects embedded in crafted .pt files can be deserialized, potentially leading to remote code execution on the victim's system.

Affected context

The vulnerability occurs when CosyVoice loads PyTorch model files (.pt) from a directory supplied via the --model_dir argument, particularly when directories are chosen or uploaded through the web interface.

It is relevant in environments where users can point CosyVoice to model directories not fully controlled or vetted by the system owner, such as shared research environments, demo servers, or systems that accept community or third-party models.

Exploit preconditions

  • Attack surface: CosyVoice model loading endpoint / workflow that accepts a user-specified --model_dir.
  • Required access: Ability to supply or control a model directory containing .pt files (e.g., local file access, upload, network share, or synced storage).
  • Trigger point: A victim (or automated process) starts CosyVoice or uses its web interface to load models from the attacker-controlled directory.
  • Why exploitation is possible: torch.load() is called on .pt files without the security-restrictive weights_only=True parameter, which defaults to Pickle-based deserialization of arbitrary Python objects embedded in the files.

Why this happens

This issue is rooted in the use of a general-purpose deserialization mechanism (Pickle via torch.load()) on data that can be influenced by untrusted users.

PyTorch's torch.load() without weights_only=True reconstructs arbitrary Python objects, not just plain tensor weights, allowing attackers to embed objects that execute code during unpickling.

This maps directly to CWE-502: Deserialization of Untrusted Data, where input data is treated as serialized executable state and rehydrated without strict type or content constraints.

Potential impact

  • Execution of arbitrary OS commands on the system running CosyVoice.
  • Full compromise of the host running the vulnerable application (data theft, credential access, lateral movement).
  • Modification or sabotage of model behavior, including data or model poisoning.
  • Use of the compromised host as a pivot for further attacks within the network.

General mitigation guidance

Effective mitigation focuses on reducing trust in serialized model inputs and constraining what can be deserialized:

  • Prefer safer loading patterns such as torch.load(..., weights_only=True) when only tensor weights are required.
  • Restrict model loading to a curated set of trusted directories or pre-approved model artifacts, avoiding arbitrary user-specified paths.
  • Introduce an explicit allowlist or manifest-based mechanism for models, where only known-safe formats and files are processed.
  • Run CosyVoice with least-privilege OS accounts and sandboxing where feasible, so that a compromise has limited impact.
  • Clearly separate environments for testing third-party or community models from production deployments, limiting cross-contamination risks.

How teams detect issues like this

Organizations can identify and monitor for this class of vulnerability using:

  • Static analysis rules that flag uses of torch.load() (and similar APIs) without safe parameters or in code paths reachable from user-controlled inputs.
  • Code review checklists that treat any Pickle-based deserialization as insecure by default, requiring explicit justification and scoping.
  • Application-level logging of model loading events, including the source directory and file names, to support detection of anomalous or unexpected locations.
  • Security policy enforcement in CI/CD pipelines that searches for unsafe deserialization patterns and blocks merges until they are remediated.

Sources

SourceLink
github.comgithub.com/FunAudioLLM/CosyVoice
notion.sonotion.so/CVE-2026-31232-35d1e1393188817f869cdcfce13402a8

Frequently asked

questions

It can be, depending on how CosyVoice is deployed. If an attacker can cause the server to load models from a directory they control (for example via uploaded content, mounted storage, or a remote share), they may achieve remote code execution when a victim triggers the model loading.

The attacker needs a way to influence the .pt files in the directory passed to --model_dir. This might be through direct filesystem access, upload mechanisms in the web interface, or control over network storage that the server reads from.

The broad fix is to avoid general-purpose deserialization of untrusted data. Use safer loading options like weights_only=True when using torch.load(), and limit model inputs to curated, trusted artifacts stored in controlled locations.

Treat all serialized objects and model files as untrusted by default; avoid Pickle-based deserialization in user-reachable paths, enforce strict separation between trusted and untrusted model sources, and include checks for unsafe deserialization APIs in code review and automated security scanning.

Find out what's already
exploitable in your codebase.