The vulnerability lies in how Yii2 handles the attachment of behaviors when they are defined using a __class array key. The provided commit 40fe496eda529fd1d933b56a1022ec32d3cd0b12 directly patches the __set method in framework/base/Component.php.
The patch changes the condition for attaching a behavior from an array configuration:
Before (vulnerable):
elseif (isset($value['class']) && is_subclass_of($value['class'], Behavior::class, true))
After (patched):
elseif ((isset($value['class']) && is_subclass_of($value['class'], Behavior::class)) || (isset($value['__class']) && is_subclass_of($value['__class'], Behavior::class)))
The __set magic method is the entry point where an attempt to assign a behavior configuration (e.g., $component->behaviorName = ['__class' => 'SomeBehavior'];) is processed. The vulnerability was that if __class was used instead of class, the specific logic for creating and attaching the behavior object might have been bypassed or handled incorrectly, leading to the described mishandling. This function is directly involved in processing the potentially problematic input ($value containing __class) and making decisions based on it. Therefore, yii\base\Component::__set is the function that contains the flawed logic and would be active during the exploitation of this vulnerability.