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 withoutweights_only=Trueor 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.

