﻿# GGUF chat templates and the llama-cpp-python CVE-2024-34359 boundary

Understand the affected llama-cpp-python versions, metadata-to-Jinja rendering path and sandbox correction without treating every GGUF runtime as equivalent.

Author: Retrivium editorial team
Updated: 2026-11-05
Canonical URL: https://retrivium.ai/journal/llama-cpp-python-gguf-chat-template-cve-2024-34359/
Language: en

A GGUF file is more than a collection of numerical weights: its metadata can influence the code path used to prepare a conversation. CVE-2024-34359 documents a historical boundary failure in llama-cpp-python. The lesson concerns the model loader and renderer actually used, rather than a blanket assertion that every GGUF file or every llama.cpp deployment executes Python.

## Identify the affected interpreter path

The [maintainer advisory](https://github.com/advisories/GHSA-56xg-wfcc-g829) lists llama-cpp-python versions 0.2.30 through 0.2.71 as affected and 0.2.72 as patched. It describes a model metadata chat template reaching an unsandboxed Jinja environment, allowing server-side template injection and code execution when the relevant chat path rendered it.

For an inventory, record the Python package version, artifact revision, selected chat handler and effective template source. A filename ending in GGUF does not identify those dependencies. Equally, a vulnerability in this wrapper should not be reassigned to an unrelated runtime without evidence of the same execution path.

## Inspect what the correction changes

The [linked project commit](https://github.com/abetlen/llama-cpp-python/commit/b454f40a9a1787b2b5659cd2cb00819d983185df) replaces the ordinary Jinja environment with ImmutableSandboxedEnvironment in the chat formatter. This is a specific renderer change, not a conversion of all model metadata into inert text or a demonstration that arbitrary artifacts are safe.

An acceptance record should connect the deployed image to the resolved package and formatter, instead of relying on a dependency declaration that may differ from the running installation. Preserve a harmless conversation fixture with the approved model and template so that an update can also be checked for formatting regressions. These are proposed review steps; we did not load a malicious model or execute the advisory's demonstration.

## Separate restricted access from resource budgets

The [Jinja sandbox documentation](https://jinja.palletsprojects.com/en/stable/sandbox/) explains controls over attributes, calls and mutable objects. It also warns that templates can raise exceptions and consume substantial CPU or memory. Restricting access to Python internals and bounding rendering work are therefore distinct requirements.

For a serving design, consider exception handling and explicit resource limits alongside artifact approval. A template that cannot invoke a forbidden method can still produce an unusable request or excessive output. Successful token generation from one approved conversation does not establish either property for every input.

## Keep disclosure evidence separate from incident evidence

This advisory establishes an affected version range, mechanism and correction. It does not supply a count of compromised deployments or prove that a particular provider experienced exploitation. A published proof of concept also does not establish that the ordinary upstream model used as its starting point was malicious.

For related background, [template and tool-parser compatibility](/journal/vllm-tool-parser-template-contract/) describes conversation preparation, while [prompt-token accounting](/journal/provider-prompt-token-template-accounting/) explains why the effective template belongs in reproducibility records. Here the additional concern is who controls the template interpreted by the serving process.

## Sources

- [Maintainer advisory and affected versions](https://github.com/advisories/GHSA-56xg-wfcc-g829).
- [Project renderer correction](https://github.com/abetlen/llama-cpp-python/commit/b454f40a9a1787b2b5659cd2cb00819d983185df).
- [Jinja sandbox security considerations](https://jinja.palletsprojects.com/en/stable/sandbox/).
