{"vuln_id":"CVE-2024-34359","aliases":["GHSA-56xg-wfcc-g829"],"description":"llama-cpp-python vulnerable to Remote Code Execution by Server-Side Template Injection in Model Metadata","published_at":"2024-05-13T14:10:18Z","modified_at":"2026-11-16T15:19:29Z","first_seen_at":"2026-11-21T19:15:20.316028Z","severity":"critical","severity_source":"ghsa","cvss_score":9.6,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H","cwe":["CWE-76"],"vendor":null,"product":null,"kev":{"is_kev":false,"date_added":null,"due_date":null,"ransomware":false},"epss":0.26001,"epss_percentile":0.98015,"nvd_status":null,"enriched_at":null,"links":{"nvd":"https://nvd.nist.gov/vuln/detail/CVE-2024-34359"},"matched_alias":null,"items":[{"id":2582,"source":{"id":"ghsa","name":"GitHub Security Advisories"},"title":"GHSA-56xg-wfcc-g829 / CVE-2024-34359: llama-cpp-python vulnerable to Remote Code Execution by Server-Side Template Injection in Model Metadata","summary":"llama-cpp-python vulnerable to Remote Code Execution by Server-Side Template Injection in Model Metadata\n\n## Description\n\n`llama-cpp-python` depends on class `Llama` in `llama.py` to load `.gguf` llama.cpp or Latency Machine Learning Models. The `__init__` constructor built in the `Llama` takes several parameters to configure the loading and running of the model. Other than `NUMA, LoRa settings`, `loading tokenizers,` and `hardware settings`, `__init__` also loads the `chat template` from targeted `.gguf` 's Metadata and furtherly parses it to `llama_chat_format.Jinja2ChatFormatter.to_chat_handler()` to construct the `self.chat_handler` for this model. Nevertheless, `Jinja2ChatFormatter` parse the `chat template` within the Metadate with sandbox-less `jinja2.Environment`, which is furthermore rendered in `__call__` to construct the `prompt` of interaction. This allows `jinja2` Server Side Template Injection which leads to RCE by a carefully constructed payload.\n\n## Source-to-Sink\n\n### `llama.py` -> `class Llama` -> `__init__`:\n\n```python\nclass Llama:\n    \"\"\"High-level Python wrapper for a llama.cpp model.\"\"\"\n\n    __backend_initialized = False\n\n    def __init__(\n        self,\n        model_path: str,\n\t\t# lots of params; Ignoring\n    ):\n \n        self.verbose = verbose\n\n        set_verbose(verbose)\n\n        if not Llama.__backend_initialized:\n            with suppress_stdout_stderr(disable=verbose):\n                llama_cpp.llama_backend_init()\n            Llama.__backend_initialized = True\n\n\t\t# Ignoring lines of unrelated codes.....\n\n        try:\n            self.metadata = self._model.metadata()\n        except Exception as e:\n            self.metadata = {}\n            if self.verbose:\n                print(f\"Failed to load metadata: {e}\", file=sys.stderr)\n\n        if self.verbose:\n            print(f\"Model metadata: {self.metadata}\", file=sys.stderr)\n\n        if (\n            self.chat_format is None\n            and self.chat_handler is None\n            and \"tokenizer.chat_template\" in self.metadata\n        ):\n            chat_format = llama_chat_format.guess_chat_format_from_gguf_metadata(\n                self.metadata\n            )\n\n            if chat_format is not None:\n                self.chat_format = chat_format\n                if self.verbose:\n                    print(f\"Guessed chat format: {chat_format}\", file=sys.stderr)\n            else:\n                template = self.metadata[\"tokenizer.chat_template\"]\n                try:\n                    eos_token_id = int(self.metadata[\"tokenizer.ggml.eos_token_id\"])\n                except:\n                    eos_token_id = self.token_eos()\n                try:\n                    bos_token_id = int(self.metadata[\"tokenizer.ggml.bos_token_id\"])\n                except:\n                    bos_token_id = self.token_bos()\n\n                eos_token = self._model.token_get_text(eos_token_id)\n                bos_token = self._model.token_get_text(bos_token_id)\n\n                if self.verbose:\n                    print(f\"Using gguf chat template: {template}\", file=sys.stderr)\n                    pri\n\nAffected packages: pip:llama-cpp-python\nPatched: llama-cpp-python 0.2.72","url":"https://github.com/advisories/GHSA-56xg-wfcc-g829","published_at":"2024-05-13T14:10:18Z","updated_at":"2026-11-16T15:19:29Z","fetched_at":"2026-11-21T19:15:18.416951Z","severity":"critical","cvss_score":9.6,"epss":0.26001,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":"llama-cpp-python","vuln_id":"CVE-2024-34359","vuln_ids":["CVE-2024-34359","GHSA-56XG-WFCC-G829"],"tags":["ghsa","pip","CWE-76"],"cluster_id":2612,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/2582","html":"https://vulnwatch.ve1ve2.com/item/2582"}}]}