craftcms/cms: Twig "create()" blocklist case-sensitivity bypass
What fixes it
- 4.18.8craftcms/cms, composerGitHub
composer require "craftcms/cms:^4.18.8" - 5.11.0craftcms/cms, composerGitHub
composer require "craftcms/cms:^5.11.0"
A fixed version on one release line is not the upgrade target for every line. Check your exact version and any vendor backports.
Description
The blocklist guarding Craft’s Twig create() function — introduced in 5.10.6 as the fix for 1369 — tests attacker-controlled class names with case-sensitive string prefix/suffix checks, while PHP class resolution is case-insensitive.
Passing the class name in lowercase (create("splfileobject", …)) bypasses both checks and instantiates SplFileObject, restoring arbitrary local file read and write from any template-execution context. File write escalates to remote code execution by writing a PHP file into the webroot and requesting it over HTTP.
Two independent defects combine in Extension::createFunction() (src/web/twig/Extension.php:1543-1574, 5.10.13.2):
str_starts_with(ltrim($class, '\\'), 'Spl')(:1564) andstr_ends_with(rtrim($class, '\\'), 'Iterator')(:1568) are case-sensitive;Craft::createObject()resolves"splfileobject"toSplFileObjectregardless.- When the
Splprefix check was added in 5.10.6,SplFileObjectwas simultaneously *removed* from the surviving case-insensitiveis_a()blocklist (:1550-1562), so no case-insensitive check covers it at all.
This is a regression of the original 1369 fix: the proper case name is blocked, the lowercase name is not.
Impact
An attacker with template-execution rights (e.g., a Control Panel administrator in the default configuration) can:
- Read any file the web user can read, including
.env→ theft ofCRAFT_SECURITY_KEYand database credentials (Craft’s canonical privilege-escalation chain). - Write any file the web user can write; demonstrated end-to-end: PHP shell written into the webroot → HTTP-triggered code execution as the web user.
- Defeat the blocklist as a security boundary for any other consumer of
create().
Report ID: 1681
Text from GitHub Advisory Database
Affected versions 2
- craftcms/cms, composer>= 4.0.0, < 4.18.8GitHub
- craftcms/cms, composer>= 5.0.0, < 5.11.0GitHub