GitHub Advisoryadvisory · Packagist
GHSA-6wpp-88cp-7q68 PhpSpreadsheet has XSS via NumberFormat @ Text Substitution in HTML Writer
MEDIUM
Official page ↗
- Aliases
- CVE-2026-35453
- Ecosystem
- Packagist
- Packages
- phpoffice/phpspreadsheet
- Severity
- Moderate
- CVSS vector
- 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
- Weaknesses
- CWE-79, CWE-80
- Reviewed
- 2026-04-28
Affected packages
• Packagist phpoffice/phpspreadsheet: >= 4.0.0, < 5.7.0 → fixed in 5.7.0
• Packagist phpoffice/phpspreadsheet: >= 3.3.0, < 3.10.5 → fixed in 3.10.5
• Packagist phpoffice/phpspreadsheet: >= 2.2.0, < 2.4.5 → fixed in 2.4.5
• Packagist phpoffice/phpspreadsheet: >= 2.0.0, < 2.1.16 → fixed in 2.1.16
• Packagist phpoffice/phpspreadsheet: < 1.30.4 → fixed in 1.30.4
Description
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`
```php
$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`
```php
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
getActiveSheet();
$payload = '';
$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.
``` html
Untitled Spreadsheet
[..SNIP..]
```
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.
Related
Alias · CVE (1)
- CVE-2026-35453 PhpSpreadsheet is a library for reading and writing spreadsheet files. vulnerability