GHSA-V66G-P9X6-V98P

Vulnerability from github – Published: 2024-10-07 14:43 – Updated: 2025-03-06 18:11
VLAI?
Summary
PhpSpreadsheet has an Unauthenticated Cross-Site-Scripting (XSS) in sample file
Details

Summary

One of the sample scripts in PhpSpreadsheet is susceptible to a cross-site scripting (XSS) vulnerability due to improper handling of input where a number is expected leading to formula injection.

Details

The following code in 45_Quadratic_equation_solver.php concatenates the user supplied parameters directly into spreadsheet formulas. This allows an attacker to take control over the formula and output unsanitized data into the page, resulting in JavaScript execution.

$discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')';
$discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula);

$r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')';
$r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))';

PoC

  1. Access 45_Quadratic_equation_solver.php in a browser
  2. Enter any valid values for for b and c, and enter the following for a
1) & ("1)),1)&char(60)&char(105)&char(109)&char(103)&char(32)&char(115)&char(114)&char(99)&char(61)&char(120)&char(32)&char(111)&char(110)&char(101)&char(114)&char(114)&char(111)&char(114)&char(61)&char(97)&char(108)&char(101)&char(114)&char(116)&char(40)&char(41)&char(62)&POWER(((1") &n("1")&(1
  1. Press submit and observe that JavaScript is executed.

exploit-phpspreadsheet

Impact

The impact of this vulnerability on the project is expected to be relatively low since these are sample files that should not be included when the library is used properly (e.g., through composer). However, at least two instances of popular WordPress plugins have unintentionally exposed this file by including the entire git repository. Since these files also serve as reference points for developers using the library, addressing this issue can enhance security for users.

A solution to fix the vulnerability is proposed below, and a request for a CVE assignment has been made to facilitate responsible disclosure of the security issue to the affected WordPress plugins.

Remediation

A quick and easy solution to prevent this attack is to force the parameters to be numerical values:

if (isset($_POST['submit'])) {
    $_POST['A'] = floatval($_POST['A']);
    $_POST['B'] = floatval($_POST['B']);
    $_POST['C'] = floatval($_POST['C']);
    if ($_POST['A'] == 0) {

Thank you for your time!

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "phpoffice/phpspreadsheet"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "2.2.0"
            },
            {
              "fixed": "2.3.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "phpoffice/phpspreadsheet"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "1.29.2"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "phpoffice/phpspreadsheet"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "2.0.0"
            },
            {
              "fixed": "2.1.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "phpoffice/phpexcel"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "last_affected": "1.8.2"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2024-45060"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-79"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2024-10-07T14:43:30Z",
    "nvd_published_at": "2024-10-07T21:15:17Z",
    "severity": "MODERATE"
  },
  "details": "### Summary\nOne of the sample scripts in PhpSpreadsheet is susceptible to a cross-site scripting (XSS) vulnerability due to improper handling of input where a number is expected leading to formula injection.\n\n### Details\n\nThe following [code](https://github.com/PHPOffice/PhpSpreadsheet/blob/d50b8b5de7e30439fb57eae7df9ea90e79fa0f2d/samples/Basic/45_Quadratic_equation_solver.php#L56) in `45_Quadratic_equation_solver.php` concatenates the user supplied parameters directly into spreadsheet formulas. This allows an attacker to take control over the formula and output unsanitized data into the page, resulting in JavaScript execution.\n```\n$discriminantFormula = \u0027=POWER(\u0027 . $_POST[\u0027B\u0027] . \u0027,2) - (4 * \u0027 . $_POST[\u0027A\u0027] . \u0027 * \u0027 . $_POST[\u0027C\u0027] . \u0027)\u0027;\n$discriminant = Calculation::getInstance()-\u003ecalculateFormula($discriminantFormula);\n\n$r1Formula = \u0027=IMDIV(IMSUM(-\u0027 . $_POST[\u0027B\u0027] . \u0027,IMSQRT(\u0027 . $discriminant . \u0027)),2 * \u0027 . $_POST[\u0027A\u0027] . \u0027)\u0027;\n$r2Formula = \u0027=IF(\u0027 . $discriminant . \u0027=0,\"Only one root\",IMDIV(IMSUB(-\u0027 . $_POST[\u0027B\u0027] . \u0027,IMSQRT(\u0027 . $discriminant . \u0027)),2 * \u0027 . $_POST[\u0027A\u0027] . \u0027))\u0027;\n```\n\n\n### PoC\n1. Access `45_Quadratic_equation_solver.php` in a browser\n2. Enter any valid values for for `b` and `c`, and enter the following for `a`\n\n```\n1) \u0026 (\"1)),1)\u0026char(60)\u0026char(105)\u0026char(109)\u0026char(103)\u0026char(32)\u0026char(115)\u0026char(114)\u0026char(99)\u0026char(61)\u0026char(120)\u0026char(32)\u0026char(111)\u0026char(110)\u0026char(101)\u0026char(114)\u0026char(114)\u0026char(111)\u0026char(114)\u0026char(61)\u0026char(97)\u0026char(108)\u0026char(101)\u0026char(114)\u0026char(116)\u0026char(40)\u0026char(41)\u0026char(62)\u0026POWER(((1\") \u0026n(\"1\")\u0026(1\n```\n\n3. Press submit and observe that JavaScript is executed.\n\n![exploit-phpspreadsheet](https://user-images.githubusercontent.com/1211162/297062610-0cdb26d1-2b47-46e2-bd31-189b0694186d.png)\n\n### Impact\n\nThe impact of this vulnerability on the project is expected to be relatively low since these are sample files that should not be included when the library is used properly (e.g., through composer). However, at least two instances of popular WordPress plugins have unintentionally exposed this file by including the entire git repository. Since these files also serve as reference points for developers using the library, addressing this issue can enhance security for users.\n\nA solution to fix the vulnerability is proposed below, and a request for a CVE assignment has been made to facilitate responsible disclosure of the security issue to the affected WordPress plugins.\n\n### Remediation\n\nA quick and easy solution to prevent this attack is to force the parameters to be numerical values:\n\n```php\nif (isset($_POST[\u0027submit\u0027])) {\n    $_POST[\u0027A\u0027] = floatval($_POST[\u0027A\u0027]);\n    $_POST[\u0027B\u0027] = floatval($_POST[\u0027B\u0027]);\n    $_POST[\u0027C\u0027] = floatval($_POST[\u0027C\u0027]);\n    if ($_POST[\u0027A\u0027] == 0) {\n```\n\nThank you for your time!",
  "id": "GHSA-v66g-p9x6-v98p",
  "modified": "2025-03-06T18:11:24Z",
  "published": "2024-10-07T14:43:30Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-v66g-p9x6-v98p"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2024-45060"
    },
    {
      "type": "WEB",
      "url": "https://github.com/PHPOffice/PhpSpreadsheet/commit/3990173db1207767139e63d33783beafada57007"
    },
    {
      "type": "WEB",
      "url": "https://github.com/PHPOffice/PhpSpreadsheet/commit/bc74f3aa1d76f191c6c7c3631e286abb25c38759"
    },
    {
      "type": "WEB",
      "url": "https://github.com/PHPOffice/PhpSpreadsheet/commit/fb42a103f14cfce258c836b31f4a71f1fb1a9747"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/PHPOffice/PhpSpreadsheet"
    },
    {
      "type": "WEB",
      "url": "https://github.com/PHPOffice/PhpSpreadsheet/blob/d50b8b5de7e30439fb57eae7df9ea90e79fa0f2d/samples/Basic/45_Quadratic_equation_solver.php#L56"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N",
      "type": "CVSS_V3"
    },
    {
      "score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N",
      "type": "CVSS_V4"
    }
  ],
  "summary": "PhpSpreadsheet has an Unauthenticated Cross-Site-Scripting (XSS) in sample file"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.


Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…