CVE-2024-45293: Phpoffice/phpspreadsheet Security Vulnerability Vulnerability

HIGH
Advisory Identifier: GHSA-6hwr-6v2f-3m88
CVSS 7.5
CWE-611
Published
Advisory Summary

CVE-2024-45293 is a HIGH (CVSS 7.5) security vulnerability vulnerability (CWE-611: Improper Restriction of XML External Entity Reference) affecting Phpoffice/phpspreadsheet libraries in the Packagist ecosystem. The issue involves xxe in phpspreadsheet's xlsx reader. Remediation is available by upgrading affected packages to version 2.3.0, 1.29.1, 2.1.1.

CVE-2024-45293 at a Glance

CVE Identifier CVE-2024-45293
GHSA Identifier GHSA-6hwr-6v2f-3m88
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-611: Improper Restriction of XML External Entity Reference
Affected Product Phpoffice/phpspreadsheet
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 7.5

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

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

How to Fix CVE-2024-45293

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

phpoffice/phpspreadsheet fixed: 2.3.0
Upgrade phpoffice/phpspreadsheet to 2.3.0
phpoffice/phpspreadsheet fixed: 1.29.1
Upgrade phpoffice/phpspreadsheet to 1.29.1
phpoffice/phpspreadsheet fixed: 2.1.1
Upgrade phpoffice/phpspreadsheet to 2.1.1
phpoffice/phpexcel fixed: Latest secure release
Upgrade phpoffice/phpexcel to Latest secure release
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 phpoffice/phpspreadsheet

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-45293, inspect your project dependencies for Phpoffice/phpspreadsheet:

inspect dependencies for phpoffice/phpspreadsheet

Analyze the terminal output to locate any version of Phpoffice/phpspreadsheet in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.3.0), 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-611: Improper Restriction of XML External Entity Reference, where the product processes an xml document that can contain xml entities with uris that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output. In Phpoffice/phpspreadsheet, 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

### Summary The security scanner responsible for preventing XXE attacks in the XLSX reader can be bypassed by slightly modifying the XML structure, utilizing white-spaces. On servers that allow users to upload their own Excel (XLSX) sheets, Server files and sensitive information can be disclosed by providing a crafted sheet. ### Details The security scan function in `src/PhpSpreadsheet/Reader/Security/XmlScanner.php` contains a flawed XML encoding check to retrieve the input file's XML encoding in the `toUtf8` function. The function searches for the XML encoding through a defined regex which looks for `encoding="*"` and/or `encoding='*'`, if not found, it defaults to the UTF-8 encoding which bypasses the conversion logic. ``` $patterns = [ '/encoding="([^"]*]?)"/', "/encoding='([^']*?)'/", ]; ``` This logic can be used to pass a UTF-7 encoded XXE payload, by utilizing a whitespace before or after the `=` in the attribute definition. ### PoC Needed: - An Excel sheet (XLSX) with at least one cell containing a value. Unzip the excel sheet, and modify the `xl/SharedStrings.xml` file with the following value (note the space after `encoding=`): ``` <?xml version="1.0" encoding= 'UTF-7' standalone="yes"?> +ADw-!DOCTYPE abc [ ... ]> ``` #### Step-by-step 1. First off, the following string is encoded in base64: ``` <!ENTITY internal 'abc' >" ``` Resulting in: ``` PCFFTlRJVFkgaW50ZXJuYWwgJ2FiYycgID4K ``` 2. The string is used with a parameter entity and the PHP filter wrapper to ultimately define custom entities and call them within the XML. ``` <?xml version="1.0" encoding= 'UTF-7' standalone="yes"?> +ADw-!DOCTYPE foo [ <!ENTITY % xxe SYSTEM "php://filter//resource=data://text/plain;base64,PCFFTlRJVFkgaW50ZXJuYWwgJ2FiYycgID4K" > %xxe;]> <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>&internal;</t></si></sst> ``` When this file is parsed by the library, the value `abc` should be in the original filled cell. With the help of the PHP filter wrapper, this can be escalated to information disclosure/file read. ### Impact Sensitive information disclosure through the XXE on sites that allow users to upload their own excel spreadsheets, and parse them using PHPSpreadsheet's Excel parser.

CVE-2024-45293 Affected Phpoffice/phpspreadsheet Versions

4 component(s)
Fixed Versions:
2.3.01.29.12.1.1
Product / Package Ecosystem Affected Versions Fixed Version
phpoffice/phpspreadsheet
Packagist
≥ 2.2.0
< 2.3.0
2.3.0
phpoffice/phpspreadsheet
Packagist
< 1.29.1
1.29.1
phpoffice/phpspreadsheet
Packagist
≥ 2.0.0
< 2.1.1
2.1.1
phpoffice/phpexcel
Packagist
≤ 1.8.2

References

Frequently Asked Questions

What is CVE-2024-45293?
CVE-2024-45293 is a security vulnerability in Phpoffice/phpspreadsheet involving XXE in PHPSpreadsheet's XLSX reader under CWE-611: Improper Restriction of XML External Entity Reference.
Which Phpoffice/phpspreadsheet versions are affected?
Affected versions include releases prior to 2.3.0, 1.29.1, 2.1.1 across affected packages: phpoffice/phpspreadsheet, phpoffice/phpexcel.
What version fixes CVE-2024-45293?
Upgrading to 2.3.0, 1.29.1, 2.1.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is phpoffice/phpspreadsheet affected?
Yes, phpoffice/phpspreadsheet is affected in releases prior to 2.3.0, 1.29.1, 2.1.1. Upgrade your dependency to 2.3.0, 1.29.1, 2.1.1 or later.
Is phpoffice/phpexcel affected?
Yes, phpoffice/phpexcel is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of CVE-2024-45293?
CVE-2024-45293 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2024-45293?
CVE-2024-45293 is classified under CWE-611: Improper Restriction of XML External Entity Reference (The product processes an XML document that can contain XML entities with URIs that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output.).
How can I check Packagist dependencies for CVE-2024-45293?
Run the dependency tree command: 'inspect dependencies for phpoffice/phpspreadsheet'. 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-6hwr-6v2f-3m88",
  "modified" : "2025-03-06T18:14:41Z",
  "published" : "2024-10-07T15:58:52Z",
  "aliases" : [ "CVE-2024-45293" ],
  "summary" : "XXE in PHPSpreadsheet's XLSX reader",
  "details" : "### Summary\nThe security scanner responsible for preventing XXE attacks in the XLSX reader can be bypassed by slightly modifying the XML structure, utilizing white-spaces. On servers that allow users to upload their own Excel (XLSX) sheets, Server files and sensitive information can be disclosed by providing a crafted sheet. \n\n### Details\nThe security scan function in `src/PhpSpreadsheet/Reader/Security/XmlScanner.php` contains a flawed XML encoding check to retrieve the input file's XML encoding in the `toUtf8` function. \n\nThe function searches for the XML encoding through a defined regex which looks for `encoding=\"*\"` and/or `encoding='*'`, if not found, it defaults to the UTF-8 encoding which bypasses the conversion logic. \n\n ```\n$patterns = [\n            '/encoding=\"([^\"]*]?)\"/',\n            \"/encoding='([^']*?)'/\",\n];\n```\n\nThis logic can be used to pass a UTF-7 encoded XXE payload, by utilizing a whitespace before or after the `=` in the attribute definition. \n\n### PoC\n\nNeeded:\n- An Excel sheet (XLSX) with at least one cell containing a value.\n\nUnzip the excel sheet, and modify the `xl/SharedStrings.xml` file with the following value (note the space after `encoding=`):\n\n```\n<?xml version=\"1.0\" encoding= 'UTF-7' standalone=\"yes\"?>\n+ADw-!DOCTYPE abc [ ... ]>\n```\n\n#### Step-by-step\n\n1. First off, the following string is encoded in base64:\n\n```\n<!ENTITY internal 'abc'  >\" \n```\n\nResulting in:\n\n```\nPCFFTlRJVFkgaW50ZXJuYWwgJ2FiYycgID4K\n```\n\n2. The string is used with a parameter entity and the PHP filter wrapper to ultimately define custom entities and call them within the XML.\n\n```\n<?xml version=\"1.0\" encoding= 'UTF-7' standalone=\"yes\"?>\n+ADw-!DOCTYPE foo [ <!ENTITY % xxe SYSTEM \"php://filter//resource=data://text/plain;base64,PCFFTlRJVFkgaW50ZXJuYWwgJ2FiYycgID4K\" > %xxe;]>\n<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"1\" uniqueCount=\"1\"><si><t>&internal;</t></si></sst>\n```\n\nWhen this file is parsed by the library, the value `abc` should be in the original filled cell.\n\nWith the help of the PHP filter wrapper, this can be escalated to information disclosure/file read. \n\n### Impact\nSensitive information disclosure through the XXE on sites that allow users to upload their own excel spreadsheets, and parse them using PHPSpreadsheet's Excel parser.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpoffice/phpspreadsheet"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.2.0"
      }, {
        "fixed" : "2.3.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpoffice/phpspreadsheet"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.29.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpoffice/phpspreadsheet"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.1.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phpoffice/phpexcel"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "1.8.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-6hwr-6v2f-3m88"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-45293"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/commit/3bcd51826b7f089d1641e756c83030c30c3bdb0c"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/commit/7d6cb09f6e8204f65e6dd5a0490f7f45f44bb331"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/commit/949ff63e1f6413e6485f73af012d506aa81384bf"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-611" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-07T15:58:52Z",
    "nvd_published_at" : "2024-10-07T20:15:06Z"
  }
}