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
.ptfiles (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.ptfiles without the security-restrictiveweights_only=Trueparameter, 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.

