Miggo Logo

CVE-2021-29440:
Grav's Twig processing allowing dangerous PHP functions by default

8.5

CVSS Score
3.1

Basic Information

EPSS Score
0.95228%
Published
4/16/2021
Updated
1/29/2023
KEV Status
No
Technology
TechnologyPHP

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:H/I:H/A:H
Package NameEcosystemVulnerable VersionsFirst Patched Version
getgrav/gravcomposer<= 1.7.101.7.11

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability stems from Grav's Twig environment configuration allowing unrestricted PHP function calls through undefined function resolution. The key function Grav\Common\Twig\Twig::registerUndefinedFunctionCallback (or its containing initialization method) created a bridge between Twig templates and PHP functions without security checks. During exploitation, this function would appear in stack traces as the entry point enabling arbitrary PHP function execution through Twig templates. The SonarSource blog post explicitly shows this unsafe callback registration in Twig.php, making it the primary vulnerable function.

Vulnerable functions

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

WAF Protection Rules

WAF Rule

### Imp**t Twi* pro**ssin* o* st*ti* p***s **n ** *n**l** in t** *ront m*tt*r *y *ny **ministr*tiv* us*r *llow** to *r**t* or **it p***s. *s t** Twi* pro**ssor runs uns*n**ox**, t*is ****vior **n ** us** to **in *r*itr*ry *o** *x**ution *n* *l*v*t*

Reasoning

T** vuln*r**ility st*ms *rom *r*v's Twi* *nvironm*nt *on*i*ur*tion *llowin* unr*stri*t** `P*P` *un*tion **lls t*rou** un***in** *un*tion r*solution. T** k*y *un*tion `*r*v\*ommon\Twi*\Twi*::r**ist*rUn***in***un*tion**ll***k` (or its *ont*inin* initi*