CVE-2024-32877: Yiisoft/yii2 Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-qg5r-95m4-mjgj
CVSS 4.2
CWE-79
Published
Advisory Summary

CVE-2024-32877 is a MODERATE (CVSS 4.2) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Yiisoft/yii2 libraries in the Packagist ecosystem. The issue involves reflected cross-site scripting in yiisoft/yii2 debug mode. Remediation is available by upgrading affected packages to version 2.0.49.4.

CVE-2024-32877 at a Glance

CVE Identifier CVE-2024-32877
GHSA Identifier GHSA-qg5r-95m4-mjgj
Severity MODERATE
CVSS v3.1 Base Score 4.2
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Yiisoft/yii2
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 4.2

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:R/S:U/C:L/I:L/A:N).

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

How to Fix CVE-2024-32877

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-32877, 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-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. 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

During the internal penetration testing of our product based on Yii2, we discovered an XSS vulnerability within the framework itself. This issue is relevant for the latest version of Yii2 (2.0.49.3). ### Conditions for vulnerability reproduction * The framework is in debug mode (YII_DEBUG set to true). * The php.ini setting zend.exception_ignore_args is set to Off (default value). * An attacker induces an exception in the application, leading to a stack trace page being displayed. ### Vulnerability description The issue lies in the mechanism for displaying function argument values in the stack trace. The vulnerability manifests when an argument's value exceeds 32 characters. For convenience, argument values exceeding this limit are truncated and displayed with an added "...". The full argument value becomes visible when hovering over it with the mouse, as it is displayed in the title attribute of a span tag. However, the use of a double quote (") allows an attacker to break out of the title attribute's value context and inject their own attributes into the span tag, including malicious JavaScript code through event handlers such as onmousemove. Demonstration example: http://31.184.254.143/about/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%22%20onmousemove=alert(1)%20style=%22width:%20100000px;%20height:%20100000px;%20position:%20absolute;%20top:%20-10000px;%20left:%200;%22 ### Impact of the vulnerability This vulnerability allows an attacker to execute arbitrary JavaScript code in the security context of the victim's site via a specially crafted link. This could lead to the theft of cookies (including httpOnly cookies, which are accessible on the page), content substitution, or complete takeover of user accounts. ### Technical analysis and mitigation suggestion Upon analyzing the framework's source code, it was found that data handling for the title attribute is performed in the file framework/web/ErrorHandler.php. The identified problem is related to changes made in the commit https://github.com/yiisoft/yii2/commit/8cc9aeb2f0b2ffe02fb54a817064e9da75512706 , which led to the disabling of encoding for single and double quotes in the htmlEncode method (https://github.com/yiisoft/yii2/blob/8cc9aeb2f0b2ffe02fb54a817064e9da75512706/framework/web/ErrorHandler.php#L183) due to the addition of the ENT_NOQUOTES flag. To address this issue while preserving the functionality intended by the commit, we suggest modifying the htmlEncode method as follows: return htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8'); This change will effectively prevent the XSS vulnerability while maintaining the targeted functionality of the previous changes. ### Conclusion Based on the above, we strongly recommend implementing the suggested changes to the project's main code as soon as possible to protect framework users from potential attacks. I am ready to provide further information or assistance, including creating a pull request if necessary.

CVE-2024-32877 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.43
< 2.0.49.4
2.0.49.4

References

Frequently Asked Questions

What is CVE-2024-32877?
CVE-2024-32877 is a security vulnerability in Yiisoft/yii2 involving Reflected Cross-site Scripting in yiisoft/yii2 Debug mode under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
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-32877?
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-32877?
CVE-2024-32877 has a CVSS v3.1 base score of 4.2 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2024-32877?
CVE-2024-32877 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check Packagist dependencies for CVE-2024-32877?
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-qg5r-95m4-mjgj",
  "modified" : "2024-07-08T19:06:02Z",
  "published" : "2024-06-02T22:27:54Z",
  "aliases" : [ "CVE-2024-32877" ],
  "summary" : "Reflected Cross-site Scripting in yiisoft/yii2 Debug mode",
  "details" : "During the internal penetration testing of our product based on Yii2, we discovered an XSS vulnerability within the framework itself. This issue is relevant for the latest version of Yii2 (2.0.49.3).\n\n### Conditions for vulnerability reproduction\n\n* The framework is in debug mode (YII_DEBUG set to true).\n* The php.ini setting zend.exception_ignore_args is set to Off (default value).\n* An attacker induces an exception in the application, leading to a stack trace page being displayed.\n\n### Vulnerability description\n\nThe issue lies in the mechanism for displaying function argument values in the stack trace. The vulnerability manifests when an argument's value exceeds 32 characters. For convenience, argument values exceeding this limit are truncated and displayed with an added \"...\". The full argument value becomes visible when hovering over it with the mouse, as it is displayed in the title attribute of a span tag. However, the use of a double quote (\") allows an attacker to break out of the title attribute's value context and inject their own attributes into the span tag, including malicious JavaScript code through event handlers such as onmousemove.\n\nDemonstration example:\nhttp://31.184.254.143/about/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%22%20onmousemove=alert(1)%20style=%22width:%20100000px;%20height:%20100000px;%20position:%20absolute;%20top:%20-10000px;%20left:%200;%22\n\n### Impact of the vulnerability\n\nThis vulnerability allows an attacker to execute arbitrary JavaScript code in the security context of the victim's site via a specially crafted link. This could lead to the theft of cookies (including httpOnly cookies, which are accessible on the page), content substitution, or complete takeover of user accounts.\n\n### Technical analysis and mitigation suggestion\n\nUpon analyzing the framework's source code, it was found that data handling for the title attribute is performed in the file framework/web/ErrorHandler.php. The identified problem is related to changes made in the commit https://github.com/yiisoft/yii2/commit/8cc9aeb2f0b2ffe02fb54a817064e9da75512706 , which led to the disabling of encoding for single and double quotes in the htmlEncode method (https://github.com/yiisoft/yii2/blob/8cc9aeb2f0b2ffe02fb54a817064e9da75512706/framework/web/ErrorHandler.php#L183) due to the addition of the ENT_NOQUOTES flag. To address this issue while preserving the functionality intended by the commit, we suggest modifying the htmlEncode method as follows:\n\n        return htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8');\n\nThis change will effectively prevent the XSS vulnerability while maintaining the targeted functionality of the previous changes.\n\n\n### Conclusion\n\nBased on the above, we strongly recommend implementing the suggested changes to the project's main code as soon as possible to protect framework users from potential attacks. I am ready to provide further information or assistance, including creating a pull request if necessary.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "yiisoft/yii2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.43"
      }, {
        "fixed" : "2.0.49.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/security/advisories/GHSA-qg5r-95m4-mjgj"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-32877"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/commit/62d081f18c3602d09e7d075bba3a0ca5c313f0b4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/commit/8cc9aeb2f0b2ffe02fb54a817064e9da75512706"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/commit/f7baab16e79f2369d4838ab5653c3c07ecf26615"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/yiisoft/yii2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yiisoft/yii2/blob/2.0.49.x/framework/CHANGELOG.md#20494-june-4-2024"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-06-02T22:27:54Z",
    "nvd_published_at" : "2024-05-30T20:15:08Z"
  }
}