Miggo Logo

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

9.7

CVSS Score
3.1

Basic Information

EPSS Score
0.97809%
Published
5/13/2024
Updated
5/28/2024
KEV Status
No
Technology
TechnologyPython

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H
Package NameEcosystemVulnerable VersionsFirst Patched Version
llama-cpp-pythonpip>= 0.2.30, <= 0.2.710.2.72

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The core vulnerability stems from two key functions: 1) Jinja2ChatFormatter's constructor creates an unsafe template rendering environment by using the default jinja2.Environment rather than a sandboxed version, allowing template code execution. 2) Llama's constructor loads untrusted chat_template values from model metadata and feeds them directly into the vulnerable Jinja2ChatFormatter. The combination allows attackers to inject malicious Jinja2 templates through model files, which get rendered with full code execution capabilities. The commit diff confirms the fix replaces jinja2.Environment with ImmutableSandboxedEnvironment in Jinja2ChatFormatter.init, directly addressing the insecure function.

Vulnerable functions

Only Mi**o us*rs **n s** t*is s**tion

WAF Protection Rules

WAF Rule

## **s*ription `ll*m*-*pp-pyt*on` **p*n*s on *l*ss `Ll*m*` in `ll*m*.py` to lo** `.**u*` ll*m*.*pp or L*t*n*y M***in* L**rnin* Mo**ls. T** `__init__` *onstru*tor *uilt in t** `Ll*m*` t*k*s s*v*r*l p*r*m*t*rs to *on*i*ur* t** lo**in* *n* runnin* o* t

Reasoning

T** *or* vuln*r**ility st*ms *rom two k*y *un*tions: *) Jinj*****t*orm*tt*r's *onstru*tor *r**t*s *n uns*** t*mpl*t* r*n**rin* *nvironm*nt *y usin* t** ****ult jinj**.*nvironm*nt r*t**r t**n * s*n**ox** v*rsion, *llowin* t*mpl*t* *o** *x**ution. *) L