VAITP Dataset

← Back to the dataset

CVE-2026-58116

RCE in LLaMA-Factory via malicious model path due to trust_remote_code=True.

  • CVSS 9.3
  • CWE-94
  • Input Validation and Sanitization
  • Remote

LLaMA-Factory through 0.9.5 contains a remote code execution vulnerability that allows attackers with WebUI access to execute arbitrary Python code by supplying a malicious model path in the Chat or Training interfaces. The application passes user-supplied model path input unvalidated into AutoTokenizer.from_pretrained() and AutoModel.from_pretrained() with a hardcoded trust_remote_code=True parameter, causing the Hugging Face transformers library to fetch and execute arbitrary code from a remote or local model repository with the privileges of the server process.

CVSS base score
9.3
Published
2026-06-30
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
LLaMA-Factor
Fixed by upgrading
Yes

Solution

Upgrade to LLaMA-Factory version 0.9.6 or later.

Vulnerable code sample

import os
from transformers import AutoTokenizer, AutoModelForCausalLM

# This function simulates the backend logic that receives a model path
# from the WebUI and attempts to load it.

def load_model_and_tokenizer(model_path_from_user: str):
    """
    Loads a model and tokenizer from a user-supplied path.
    This is the vulnerable function.
    """
    try:
        # The user-supplied `model_path_from_user` is passed directly.
        # The `trust_remote_code=True` parameter is hardcoded.
        # This forces the transformers library to download and execute any
        # Python code found in the specified model repository.
        tokenizer = AutoTokenizer.from_pretrained(
            model_path_from_user,
            trust_remote_code=True
        )

        model = AutoModelForCausalLM.from_pretrained(
            model_path_from_user,
            trust_remote_code=True
        )
        
        print(f"Successfully loaded model: {model_path_from_user}")
        return model, tokenizer

    except Exception as e:
        print(f"Failed to load model: {e}")
        return None, None

# Example of how an attacker would exploit this:
# An attacker would create a Hugging Face repository (e.g., "attacker/malicious-model")
# containing a Python file (e.g., modeling_llama.py) with malicious code like:
#
# import os
# os.system("echo 'pwned' > /tmp/hacked.txt")
#
# Then, they would input "attacker/malicious-model" into the WebUI.
# The `load_model_and_tokenizer` function would be called on the backend,
# triggering the remote code execution.

Patched code sample

from transformers import AutoModelForCausalLM, AutoTokenizer

def load_model_and_tokenizer_fixed(
    model_name_or_path: str,
    trust_remote_code: bool = False
):
    """
    Loads a model and tokenizer, representing the fix for the vulnerability.

    Instead of hardcoding `trust_remote_code=True`, this parameter is now
    exposed and defaults to `False`. This prevents the automatic execution
    of potentially malicious code from a model hub repository unless the
    user of the function explicitly and knowingly enables it.
    """
    tokenizer = AutoTokenizer.from_pretrained(
        model_name_or_path,
        trust_remote_code=trust_remote_code  # This now defaults to False
    )

    model = AutoModelForCausalLM.from_pretrained(
        model_name_or_path,
        trust_remote_code=trust_remote_code  # This now defaults to False
    )

    return model, tokenizer

Payload

your-hf-username/malicious-model-repo

Cite this entry

@misc{vaitp:cve202658116,
  title        = {{RCE in LLaMA-Factory via malicious model path due to trust_remote_code=True.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-58116},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-58116/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::