Security Digest · Vulnerability record

CVE-2024-34359: llama-cpp-python vulnerable to Remote Code Execution by Server-Side Template Injection in Model Metadata

llama-cpp-python is the Python bindings for llama.cpp.

CVSS 9.7 Critical EPSS 26.0% · p98

Should you act?

High exploit likelihood

EPSS ranks it in the top 5% of all CVEs for likely exploitation in the next 30 days. This signal is computed from CISA KEV, EPSS and CVSS data; it is not an editorial verdict.

  • Not in CISA KEV, but CISA’s SSVC assessment records a public proof-of-concept, so attack code exists.
  • EPSS 26.0%, percentile 98: FIRST’s model estimates a 26.0% chance of exploitation activity in the next 30 days, higher than 98% of all scored CVEs (very high). EPSS is a probability, not a verdict.
  • Needs a user to click or open something. Phishing makes that realistic, but it is not wormable.
  • Only applies if your dependency tree includes llama-cpp-python (PyPI) >= 0.2.30, <= 0.2.71, fixed in 0.2.72. Check your lockfile, including transitive dependencies.

What it is

llama-cpp-python is the Python bindings for llama.cpp. 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 llamachatformat.Jinja2ChatFormatter.tochathandler() to construct the self.chathandler 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 remote code execution by a carefully constructed payload.

From the GitHub advisory

Description

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 llamachatformat.Jinja2ChatFormatter.tochathandler() to construct the self.chathandler 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.

Source-to-Sink

llama.py -> class Llama -> init:

In llama.py, llama-cpp-python defined the fundamental class for model initialization parsing (Including NUMA, LoRa settings, loading tokenizers, and stuff ). In our case, we will be focusing on the parts where it processes metadata; it first checks if chatformat and chathandler are None and checks if the key tokenizer.chattemplate exists in the metadata dictionary self.metadata. If it exists, it will try to guess the chat format from the metadata. If the guess fails, it will get the value of chattemplate directly from self.metadata.self.metadata is set during class initialization and it tries to get the metadata by calling the model's metadata() method, after that, the chattemplate is parsed into llamachatformat.Jinja2ChatFormatter as params which furthermore stored the tochathandler() as chathandler

Weakness type: CWE-76.

Product: llama-cpp-python (PyPI) · Assigned by: GitHub_M · Published: 2024-05-10

Affected and fixed versions

EcosystemPackageVulnerableFirst fixed
PyPIllama-cpp-python>= 0.2.30, <= 0.2.710.2.72
VendorProductAffected versions (per CVE record)
abetlenllama-cpp-python>= 0.2.30, <= 0.2.71

Severity scores

Scored byCVSSScoreVector
GitHub_M3.19.7 CriticalCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H
GitHub3.19.6 CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H
  • Attack vector: network (remotely reachable)
  • Attack complexity: low
  • Privileges required: none (no login)
  • User interaction: required (a user must click/open something)
  • Scope: changed (can affect other components)

CVSS measures how bad a flaw is if exploited, not how likely exploitation is. Read it next to the exploitation data below.

Exploitation and urgency

  • CISA KEV: not listed (no confirmed in-the-wild exploitation known to CISA).
  • CISA SSVC assessment: exploitation poc, automatable no, technical impact total.
  • FIRST EPSS (model of 2026-10-21): 26.00% probability of exploitation activity in the next 30 days; percentile 98.

Timeline

  • — CVE record published by GitHub_M
  • — GitHub-reviewed advisory GHSA-56xg-wfcc-g829 published (critical)
  • — CVE record last updated

Sources and references

Original sources first. Version and fix details should always be confirmed against the vendor or project advisory.

Vulnerability records

  1. GitHub Advisory GHSA-56xg-wfcc-g829 github.com
  2. CVE.org record CVE-2024-34359 cve.org
  3. NVD entry CVE-2024-34359 nvd.nist.gov

Other references from the CVE record and advisory

  1. github.com github.com
  2. github.com github.com

Critical PyPI advisories · Today’s Security Digest