Summary
Xinference enables Hugging Face remote model code execution unconditionally during several model-loading paths. A user with model-launch access may register a model with an attacker-controlled directory, causing Python code declared by the model configuration to execute with the worker process's privileges.
Affected context
The vulnerability occurs in Xinference deployments that load Hugging Face models through affected reranking, embedding, or Transformers-based language-model paths. Risk is present when a caller can launch a model using an arbitrary or untrusted model path and the loader processes model metadata that enables custom Python components without an explicit trust decision.
Exploit preconditions
- Attack surface: Xinference model-launch and model-loading interfaces
- Required access: Permission to register or launch a model and provide its model path or configuration
- Trigger point: Hugging Face tokenizer, component, or model loading
- Why exploitation is possible: Affected call sites enable
trust_remote_codeunconditionally, allowing model metadata to direct the loader to import Python code from the model directory
Why this happens
The underlying bug is an unsafe trust-boundary decision in model loading. Several Xinference call sites pass trust_remote_code=True or use an unconditional default, so code supplied by a model repository is treated as trusted executable logic rather than untrusted model data.
This behavior maps to CWE-94: Improper Control of Generation of Code, because attacker-influenced model metadata can cause Python modules to be imported and executed without an effective authorization or policy check.
Potential impact
- An attacker could execute arbitrary Python code in the worker process
- The worker environment could be modified or compromised
- Model-serving credentials or locally accessible secrets may be exposed
- The attacker could alter model outputs or poison inference behavior
- Compromised workers could be used for lateral movement, subject to deployment privileges
General mitigation guidance
Mitigation generally focuses on making execution of model-supplied code an explicit, restricted choice rather than a default behavior.
Common defensive patterns include:
- Disable remote model code execution by default and require an explicit policy-controlled opt-in
- Permit custom code only for an allowlisted set of reviewed, bundled, or otherwise trusted models
- Restrict model-launch users from supplying arbitrary paths or unapproved repositories
- Validate model metadata and separate model data from executable components
- Run model workers with least-privilege identities, isolated filesystems, and limited network access
- Treat model artifacts as untrusted supply-chain inputs and verify their provenance before deployment
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis searches for literal
trust_remote_code=Truevalues and unconditional defaults - Code review checks for model-loading APIs that import repository-provided Python modules
- Policy enforcement that rejects unapproved remote-code execution settings or repositories
- Runtime monitoring for unexpected Python imports, subprocess creation, filesystem changes, or outbound connections from model workers
- Configuration audits confirming that model-launch permissions and remote-code policies are independently controlled
- Automated security review tools that flag unsafe trust-boundary settings in dependency and model-loading code

