GHSA-255j-qw47-wjh5: Craft CMS vulnerable to potential authenticated Remote Code Execution via malicious attached Behavior
Note that attackers must have administrator access to the Craft Control Panel for this to work.Users should update to the patched versions (5.8.21 and 4.16.17) to mitigate the issue.Resources:https://github.com/craftcms/cms/commit/6e608a1a5bfb36943f94f584b7548ca542a86fefhttps://github.com/craftcms/cms/commit/27f55886098b56c00ddc53b69239c9c9192252c7https://github.com/craftcms/cms/commit/ec43c497edde0b2bf2e39a119cded2e55f9fe593https://github.com/craftcms/cms/blob/5.x/CHANGELOG.md#5821---2025-12-04SummaryThis was reported as a vulnerability in Yii framework on August 7th (https://github.com/yiisoft/yii2/security/advisories/GHSA-gcmh-9pjj-7fp4). The Yii framework team denies responsibility for this (placing the onus on application developers) and hence has not (and seemingly will not) provide a fix at the framework level. Hence, I am reporting this to Craft as I found it to affect the latest (`5.6.0`) version of Craft CMS.Leveraging a legitimate but maliciously crafted Yii `Behavior` class, it’s possible to trigger Remote Code Execution (RCE) via Reflection when the tainted `Behavior` is attached to a Yii `Component`, and an event is also fired on the tainted `Component`.DetailsThis vulnerability is inspired by `CVE-2024-4990` but differs because a legitimate Yii `Behavior` class is used to abuse the magic `__set()` and `__get()` methods to trigger an arbitrary PHP callable, ultimately leading to RCE. As such, this bypasses the mitigations implemented for `CVE-2024-4990` and the related `CVE-2024-58136`.Using the `as <behavior>` syntax in JSON POST input, it’s possible to [attach](https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors#attaching-behaviors) `Behavior` classes to Yii `Components`, which was the crux of the vulnerability identified in `CVE-2024-4990`. Fixes for that vulnerability and the related `CVE-2024-58136` ensured that only classes of type `Behavior` could be attached to a `Component`. Craft CMS also implemented additional logic to prevent arbitrary `Behavior` classes from being attached to the vulnerable `Component`.A new vulnerability has been identified that bypasses the fixes for the previous vulnerabilities by using a legitimate but specially crafted `Behavior` class, namely the `yii\behaviors\AttributeTypecastBehavior`. Attaching a `Behavior` of this type allows the attacker to define an arbitrary callable that is triggered if any event is fired on the tainted `Component`.Using a [wildcard](https://www.yiiframework.com/doc/guide/2.0/en/concept-events#wildcard-events) event listener (specified as `on *` in JSON input) allows the attacker to catch any event called on the tainted `Component` and redirect the flow of control to call `self::beforeSave` of the `AttributeTypecastBehavior`, triggering the attacker-defined callable and resulting in RCE.See the commented payload below:This was found to affect two separate controllers/routes in Craft CMS admin functionality, though others may be affected:/index.php?p=admin%2Factions%2Ffields%2Fapply-layout-element-settings/index.php?p=admin%2Factions%2Ffields%2Frender-card-previewPoCInstall Craft CMS via Composer:Use the built-in server to launch Craft CMS:The following HTTP traces show the payload used to trigger the vulnerability on each of the vulnerable routes:**/index.php?p=admin%2Factions%2Ffields%2Fapply-layout-element-settings****/index.php?p=admin%2Factions%2Ffields%2Frender-card-preview**Check the filesystem to confirm the creation of the two files in `/tmp` and hence confirm RCE:ImpactAn attacker with access to Craft CMS admin functionality, specifically the routes listed above, can trigger RCE on the backend server and potentially gain control of the server.
CVSS v4.0: 8.6