LLaMA-Factory WebUI Remote Code Execution via Hardcoded `trust_remote_code` (CVE-2026-58116)
by Original disclosure by h3nrrrych4u; PoC by Hunt-Benito · 2026-07-19
- Severity
- Critical
- CVE
- CVE-2026-58116
- Category
- web
- Affected product
- LLaMA-Factory ([hiyouga/LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory)) — WebUI Chat and Training interfaces
- Affected versions
- <= 0.9.5
- Disclosed
- 2026-07-19
- Patch status
- unpatched
Tags
References
- https://nvd.nist.gov/vuln/detail/CVE-2026-58116
- https://www.vulncheck.com/advisories/llama-factory-remote-code-execution-via-webui-model-path
- https://gist.github.com/henrrrychau/08d76ec672f42136bbc1449c4f2973f8
- https://github.com/Hunt-Benito/llama-factory-webui-rce-cve-2026-58116-trust-remote-code-model-path-injection
Archive entry
intelseclab/poc-archiveMetadata
| Field | Value |
|---|---|
| Date Added | 2026-07-19 |
| Last Updated | 2026-07-19 |
| Author / Researcher | Original disclosure by h3nrrrych4u; PoC by Hunt-Benito |
| CVE / Advisory | CVE-2026-58116 |
| Category | web |
| Severity | Critical |
| CVSS Score | 9.8 (CVSS 3.1, AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H) |
| Status | Weaponized — confirmed code execution via the exact sink LLaMA-Factory reaches |
| Tags | llamafactory, llm-training, webui, trust-remote-code, huggingface, transformers, cwe-94, unauthenticated-within-webui, remote-code-execution, ai-supply-chain |
| Related | N/A |
Affected Target
| Field | Value |
|---|---|
| Software / System | LLaMA-Factory (hiyouga/LLaMA-Factory) — WebUI Chat and Training interfaces |
| Versions Affected | <= 0.9.5 |
| Language / Platform | Python, Hugging Face transformers |
| Authentication Required | No additional auth beyond having WebUI access (the WebUI itself is often deployed without further access control) |
| Network Access Required | No — triggered by loading a model, which can be a local action or reachable if the WebUI is exposed |
Summary
LLaMA-Factory’s WebUI hardcodes trust_remote_code=True whenever it loads a model (src/llamafactory/webui/chatter.py:139 and runner.py:175,320). The “Model path” field — fully attacker/user-controlled — flows unvalidated into AutoTokenizer.from_pretrained() / AutoModel.from_pretrained(). Because trust_remote_code=True tells Hugging Face transformers to download and execute arbitrary Python modules declared in a model repository’s config.json (auto_map), simply pointing the WebUI’s Model path at a malicious Hugging Face repository — or any path resolving to one — results in immediate remote code execution as the LLaMA-Factory process, before any model weights are even loaded.
Vulnerability Details
Root Cause
Tracked as CWE-94 (Code Injection). transformers instantiates the config class declared in a model’s auto_map (e.g. AutoConfig.from_pretrained(path, trust_remote_code=True)) as part of parsing config.json — this happens before any model weights are fetched or validated. If that config class’s __init__ executes arbitrary code (which it can, since it’s just a Python module fetched from the specified repository), that code runs unconditionally as soon as the config is read. LLaMA-Factory’s loader (src/llamafactory/model/loader.py) always sets trust_remote_code=True when building the kwargs passed to AutoTokenizer/AutoModel, with no opt-out or warning, so any model path a user or attacker can get the WebUI to load results in code execution.
Attack Vector
- Attacker (or a user tricked into it) sets LLaMA-Factory WebUI’s “Model path” field to a malicious Hugging Face repository ID (or other resolvable path) containing a
config.jsonwith anauto_mappointing to attacker-controlled Python modules. - User clicks “Load Model” in the Chat or Training tab.
- LLaMA-Factory calls
AutoConfig.from_pretrained(malicious_path, trust_remote_code=True). transformersdownloads the attacker’sconfiguration_poc.pyand instantiates the declared config class — executing the attacker’s__init__code immediately, before any weights are loaded.
Impact
Arbitrary remote code execution as the LLaMA-Factory server process, simply by getting a “Model path” value loaded through the WebUI — no separate authentication bypass needed if the WebUI is reachable, and no user interaction beyond a normal “load this model” action, which is exactly what the tool is designed to have users do routinely.
Environment / Lab Setup
Target: A local install of LLaMA-Factory's WebUI (or the sink demonstrated
standalone via transformers, no WebUI required to prove the primitive)
Attacker: Python 3 + transformers + torch (+ huggingface_hub for the --upload path)
Setup Steps
| |
Proof of Concept
See
build_and_verify.pyandpoc-model/(config.json,configuration_poc.py,modeling_poc.py) in this folder — mirrored from Hunt-Benito/llama-factory-webui-rce-cve-2026-58116-trust-remote-code-model-path-injection. Verified before ingestion: read all files in full. The payload is intentionally minimal and harmless —subprocess.check_output(["id"])plus host recon printed to stdout — with an explicit comment marking it as a stand-in for “an actual command in a real engagement.” No obfuscation, no network exfiltration, no destructive behavior. The technique it demonstrates (config-class code execution duringAutoConfig.from_pretrained, before weights load) is a well-documented, realtransformers/trust_remote_codebehavior, and the cited source lines (chatter.py:139,runner.py:175,320) describe LLaMA-Factory’s actual hardcoded-flag pattern.
Step-by-Step Reproduction
Verify the sink locally (no WebUI needed):
| |
End-to-end via a running LLaMA-Factory WebUI:
| |
Exploit Code
| |
Expected Output
[+] PoC model assembled at .../poc-model
[*] Loading config with trust_remote_code=True (this triggers the PoC)...
============================================================
[CVE-2026-58116 PoC] trust_remote_code payload executed!
time : 2026-07-02T...
host : gpu-host-01
user : hbuser
------------------------------------------------------------
uid=1000(hbuser) gid=1000(hbuser) groups=1000(hbuser)
============================================================
[+] Config loaded: PoCConfig (model_type=poc_model)
Detection & Indicators of Compromise
Remediation
| Action | Detail |
|---|---|
| Patch | Upgrade LLaMA-Factory past 0.9.5 once a fixed release removes the hardcoded trust_remote_code=True, or requires explicit opt-in. |
| Workaround | Restrict WebUI “Model path” input to an allowlist of trusted, internally-vetted model repositories; never expose the WebUI to untrusted users; run the WebUI process with minimum filesystem/network privileges. |
| General guidance | Treat trust_remote_code=True as equivalent to running arbitrary code from wherever the model path points — never wire it to unauthenticated or lightly-authenticated user input in any tool that loads Hugging Face models. |
References
- NVD — CVE-2026-58116
- VulnCheck advisory
- Original disclosure (h3nrrrych4u)
- Public PoC — Hunt-Benito/llama-factory-webui-rce-cve-2026-58116-…
Notes
Surfaced via a --days 4 only 2026 CVE discovery sweep on 2026-07-15, held pending verification, and ingested now alongside the other verified findings from this week’s sweeps. Verified before ingestion per this archive’s standing rule: read every file in full (build_and_verify.py, poc-model/config.json, configuration_poc.py, modeling_poc.py) — clean, minimal, and technically consistent with well-documented transformers/trust_remote_code behavior.
| |