⚠️

سلب مسئولیت و اخلاق حرفه‌ای

این مطالب صرفاً برای اهداف آموزشی، پژوهشی و افزایش آگاهی امنیتی ارائه شده‌اند. هرگونه استفاده غیرمجاز، غیرقانونی یا سوءاستفاده از اطلاعات، ابزارها و روش‌های مطرح‌شده، کاملاً بر عهده مخاطب است. نویسنده و منتشرکننده هیچ مسئولیتی در قبال خسارات، آسیب‌ها یا پیامدهای ناشی از استفاده نادرست از این مطالب نخواهند داشت.

CVE-2026-139989: Jinja2 Template Injection Enables RCE in languagemodels 1.0.0 | Alireza Bolbolabadi - Red Team Security
LOADING

CVE-2026-139989: Jinja2 Template Injection Enables RCE in languagemodels 1.0.0

Executive summary

CVE-2026-139989 is a high-impact template injection vulnerability in jncraton languagemodels 1.0.0. The flaw affects the loading of Hugging Face models through Config.use_hf_model: a model repository can include a malicious chat_template in tokenizer_config.json, and the package may render that template with an unsandboxed Jinja2 environment. Because the template can reach Python modules such as os, loading the model can result in arbitrary command execution under the permissions of the application process.

The vulnerability is classified as CWE-1336, Improper Neutralization of Special Elements Used in a Template Engine. Published scoring rates it as high: 7.8 under CVSS 3.1 and 8.5 under CVSS 4.0. The supplied sources do not provide evidence of exploitation in the wild or a public proof-of-concept, but the attack path is direct once a victim loads an attacker-controlled model.

Technical analysis

The affected flow begins when languagemodels obtains the chat_template value from a Hugging Face model's tokenizer_config.json. The package passes this externally supplied content into Jinja2 for rendering. In the vulnerable configuration, the Jinja2 environment is not sufficiently restricted, allowing a template to access sensitive Python execution paths and ultimately the os module.

This creates a supply-chain execution path:

  1. An attacker controls or publishes a Hugging Face model repository.

  1. The attacker places a malicious Jinja2 expression in the repository's tokenizer_config.json chat_template field.

  1. A victim application selects that model and invokes Config.use_hf_model or an API that performs the same loading operation.

  1. The package renders the template without adequate sandboxing.

  1. The injected expression executes commands with the privileges of the Python process.

Although the payload is hosted remotely, exploitation is not a conventional network attack. The victim must cause the package to retrieve and load the malicious model. This distinction explains why cvefeed.io lists the vulnerability as not remotely exploitable while the NVD description refers to remote attackers: control of an external model repository is sufficient, but interaction with the affected software is required.

The vulnerability's security significance comes from the combination of code execution and the apparent difficulty of recognizing malicious template content. Users selecting a model commonly focus on its model files and intended functionality rather than manually inspecting a chat template. The attack also inherits the privileges of the affected process, so credentials, network access, and other resources available to that process may be exposed.

Affected systems

  • Vendor: jncraton

  • Product: languagemodels

  • Affected version: 1.0.0

  • Fixed release referenced by the advisory material: 1.0.1

  • Weakness: CWE-1336 — Improper Neutralization of Special Elements Used in a Template Engine

  • Affected operation: Loading a Hugging Face model through Config.use_hf_model or equivalent functionality

  • Potential impact: Arbitrary operating-system command execution with the victim process privileges

The supplied records name only version 1.0.0 as affected. They do not provide a complete affected-version range, and the cvefeed.io product table notes that exact version mapping is not represented there.

Exploitability assessment

The prerequisites are limited. An attacker needs control of a model repository, while the victim needs to load that model through the affected package. No prior compromise of the victim's host or network is described. Once the template is rendered, the published technical analysis indicates that arbitrary commands can run.

The impact depends on the execution context. A package used in a restricted evaluation environment presents a smaller but still meaningful risk if that environment exposes credentials or network services. A service handling sensitive data or privileged cloud credentials could experience a substantially larger compromise. No evidence of active exploitation is present in the provided context, so the rating reflects the vulnerability's technical impact and realistic model-loading workflow rather than confirmed campaign activity.

Mitigation

The available advisories identify an upstream fix and reference version 1.0.1. The following measures address the known vulnerable path:

  1. Upgrade languagemodels to 1.0.1 or a later release containing the upstream correction. The referenced fix commit is 48f4257a0d20a82075d2847a51036a3c8a2a0a13.

  1. Audit model identifiers used by applications, then inspect each model's tokenizer_config.json for unexpected chat_template content. Treat model-repository configuration as executable, untrusted input rather than passive metadata.

  1. Reject templates that require access to Python internals or sensitive modules, including references involving os, class, mro, globals, imports, or unexpected attribute traversal.

  1. Where application requirements permit, render templates in a constrained Jinja2 environment that does not expose unrestricted Python capabilities. The supplied references do not confirm whether the upstream patch uses this approach, so it should be independently verified in the deployed version.

  1. Run model-loading workloads with least privilege and strong isolation, such as a separate low-privilege process or a constrained container with minimal filesystem and network permissions.

  1. Monitor model-loading activity for unexpected subprocess creation and review newly introduced model sources before approval.

Expert insight

The central security failure is the conflation of model metadata with trusted code. Chat templates are designed to be programmable, but their deployment model matters: rendering an expression supplied by a model repository is safe only when the environment is explicitly constrained. In this case, the combination of attacker-controlled template content, unrestricted Jinja2 capabilities, and ordinary model-loading behavior creates a direct code-execution path.

This case also illustrates why version-only remediation should be combined with artifact governance. A patched library can prevent the known path, but applications that permit unrestricted template evaluation elsewhere may retain the same architectural risk. Fixed-version verification, model provenance controls, template validation, and restricted execution should therefore be treated as complementary layers.

منابع

·
← اخبار