GHSA-cjcc-p67m-7qxm Unsafe Reflection in base Component class in yiisoft/yii2
Yii2 supports attaching Behaviors to Components by setting properties having the format `'as <behaviour-name>'`.Internally this is done using the `__set()` magic method. If the value passed to this method is not an instance of the `Behavior` class, a new object is instantiated using `Yii::createObject($value)`. However, there is no validation check that verifies that `$value` is a valid `Behavior` class name or configuration. An attacker that can control the content of the $value variable can then instantiate arbitrary classes, passing parameters to their constructors and then invoking setter methods.ImpactWith some effort malicious code can be injected executed which might be anything ranging from deleting files to dropping database tablesPatchesNot yet patched.WorkaroundsNo Work around availableReferencesReported [Here](https://huntr.com/bounties/4fbdd965-02b6-42e4-b57b-f98f93415b8f?token=3bcfc5266870680af19a26170b8dbf3750e3b593ce192da8eaa6a03f96b99b52c419e15768c56f23991dc50003aa1a9e3cb3f1f9321e18bd506d68a9f937cd5b7ca90fb47967df22c8768c0c48f7206f36b583464af7e44bf93eecc5398a2764b98e02cf8e280397785106db16e4197951554eb9b9c46649f4339e2f413cf6a0197ab2e0)in case the link is dead, here is the full descriptionDescriptionYii2 supports attaching Behaviors to Components by setting properties having the format  `'as <behaviour-name>'`.Internally this is done using the  `__set()`  magic method. If the value passed to this method is not an instance of the Behavior class, a new object is instantiated using  `Yii::createObject($value)`. However, there is no validation check that verifies that  `$value`  is a valid Behavior class name or configuration. An attacker that can control the content of the  `$value`  variable can then instantiate arbitrary classes, passing parameters to their constructors and then invoking setter methods.Depending on the installed dependencies various kind of attacks are possible.Proof of ConceptA PoC application was created using  `composer create-project`, as specified in the  [getting started](https://www.yiiframework.com/doc/guide/2.0/en/start-installation).Yii JSON parser was enabled in the configuration:A vulnerable controller was added:Executing phpinfo()Following command stores the content of  `phpinfo()`  inside info.html:It leverages the fact that  `GuzzleHttp\Psr7\FnStream`  class executes  `call_user_func($this->_fn_close)`  inside  `__destruct()`. This class is a default dependency.Executing arbitrary MySQL queries (blind execution)If the application is connected to a MySQL database it is possible to exploit the  `PDO`  class to execute arbitrary SQL queries:Notice that the server will always return a 500 Internal Server Error (because the instantiated class is not a Behavior), however the query is executed, even if we can't receive any output from it. If the query fails we might see a PDO error message (i.e. "Table 'test.foo' doesn't exist"), depending on the app configuration.ImpactIt is not trivial to exploit this bug, because it depends on peculiar characteristics of the target application. However, it looks that there is at least one very popular product built on Yii2 that is severely affected by this vulnerability (allowing to an anonymous user to gain admin access, with an easy exploit).The consequences of the exploitation could vary from retrieving sensitive information to DoS or unauthorized access.Occurrences[Component.php L191](https://github.com/yiisoft/yii2/blob/2.0.48/framework/base/Component.php#L191)
CVSS v3.1 score: 8.1