/

CVE-2026-58116

Severity:

CRITICAL RISK

(9.8)

Remote Code Execution via Model Loading in LLaMA-Factory

CVE-2026-58116

Analyzed

Vulnerability type

Category:

Remote Code Execution

CWE:

CWE-94, CWE-829

Impact:

Arbitrary Code Execution on Server

Severity:

CRITICAL RISK

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

LLaMA-Factory through version 0.9.5 allows attackers with WebUI access to execute arbitrary Python code by providing a crafted model path in Chat or Training workflows.

Because user-controlled model paths are passed directly into Hugging Face from_pretrained() calls with trust_remote_code=True, the server may fetch and execute untrusted code from remote or local model repositories.

Affected context

This vulnerability appears in deployments of LLaMA-Factory that expose the WebUI for chat, inference, or training tasks. It becomes relevant when users are allowed to specify custom model paths or repositories, and those values are forwarded to the underlying Hugging Face Transformers APIs. The risk is heightened in environments where the server runs with elevated privileges or has access to sensitive data, because any loaded model can introduce executable code if remote code execution is implicitly trusted.

Exploit preconditions

  • Attack surface: LLaMA-Factory WebUI endpoints for Chat and Training that accept a model path or repository identifier.
  • Required access: Ability to authenticate or otherwise interact with the WebUI interface where model paths can be supplied.
  • Trigger point: Submission of a malicious model path that points to a repository containing custom loading code; the application then calls AutoTokenizer.from_pretrained() and AutoModel.from_pretrained() with trust_remote_code=True.
  • Why exploitation is possible: User input is treated as a trusted reference to executable model code, and the framework automatically imports and runs repository-provided Python without validation, sandboxing, or restriction, aligning with CWE-94 and CWE-829.

Why this happens

The bug stems from directly binding user-controlled model path input to dynamic code loading mechanisms in the Hugging Face Transformers library. When trust_remote_code=True is hardcoded, the framework will execute arbitrary Python modules shipped with the specified model repository during object initialization. Conceptually, this is an instance of CWE-94: Improper Control of Generation of Code, because external input controls which code is loaded and executed. It also reflects CWE-829: Inclusion of Functionality from Untrusted Control Sphere, where remote or locally supplied repositories are treated as trusted components without provenance checks, review, or isolation.

Potential impact

  • Attackers may execute arbitrary Python code with the privileges of the LLaMA-Factory server process.
  • Malicious models could exfiltrate API keys, secrets, or training data accessible to the application.
  • An attacker can modify or corrupt model weights and outputs, leading to data poisoning or unreliable inference.
  • Compromised servers may be used as a foothold for lateral movement within the hosting environment.
  • Persistent backdoors or cryptominers may be deployed through hostile model loading code.

General mitigation guidance

Effective mitigation focuses on tightening the trust boundary around model loading and reducing the ability for user inputs to control executable code sources. Common defensive patterns include:

  • Disabling or avoiding trust_remote_code=True for user-specified models, favoring standard, non-executable config formats.
  • Restricting model selection to a curated, vetted catalog rather than arbitrary paths or repositories supplied via WebUI.
  • Introducing strict validation and allowlisting on model identifiers to ensure only known-safe repositories are referenced.
  • Running the application under least-privilege accounts and isolating model loading in constrained environments to limit blast radius.
  • Treating all externally sourced models as untrusted artifacts and applying code review or provenance checks before deployment.

How teams detect issues like this

Organizations can detect and manage this class of vulnerability by:

  • Defining static analysis rules and configuration checks that flag trust_remote_code=True usage in code paths influenced by user input.
  • Reviewing WebUI handlers and API endpoints for any parameters that are forwarded into dynamic from_pretrained() calls.
  • Enforcing security policies that require curated model registries and prohibit runtime loading of arbitrary repositories.
  • Using automated scanning tools to monitor dependencies and application configuration for risky dynamic loading patterns.
  • Instrumenting logging around model loading events to identify unusual or unapproved repositories being fetched by the server.

Sources

SourceLink
gist.github.comgist.github.com/henrrrychau/08d76ec672f42136bbc1449c4f2973f8
vulncheck.comvulncheck.com/advisories/llama-factory-remote-code-execution-via-webui-model-path

Frequently asked

questions

Yes, if the LLaMA-Factory WebUI is accessible over the network and allows users to specify arbitrary model paths or repositories, an attacker can exploit the issue without local access to the host.

The attacker needs the ability to interact with the Chat or Training interfaces where model paths are accepted. This may require valid credentials in some deployments, but in less restricted setups any WebUI user could attempt exploitation.

The most robust pattern is to decouple user input from dynamic code loading. Disable trusted remote code execution for user-supplied models, limit model choices to a vetted catalog, and ensure that model loading uses non-executable configurations wherever possible.

Future designs should treat models as data rather than code, avoid automatic execution of repository-provided Python, and incorporate strict controls around plugin-like functionality. Combine secure defaults (no remote trusted code), allowlists for model sources, and security-focused code review for any component that loads or initializes models at runtime.

Find out what's already
exploitable in your codebase.