PhpSpreadsheet CVE-2026-40296
MEDIUMSeverity by source
AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
Network delivery via file upload, low complexity bypass, low-privilege file submitter, victim interaction required, scope changes to browser; confidentiality and integrity limited to session-class XSS impact.
Primary rating from GitHub Advisory.
CVSS VectorGitHub Advisory
Lifecycle Timeline
3DescriptionGitHub Advisory
It was discovered that there is a way to bypass HTML escaping in the HTML writer using custom number format codes.
The Problem
In Writer/Html.php around line 1592, the code checks if the formatted cell data equals the original data to decide whether to apply htmlspecialchars():
if ($cellData === $origData) {
$cellData = htmlspecialchars($cellData, ...);
}When a cell has a custom number format containing @ (text placeholder) with any additional literal characters, the formatter replaces @ with the cell value and adds the extra characters. This makes $cellData !== $origData, so htmlspecialchars() is skipped entirely.
Even a single trailing space in the format (@ ) is enough to bypass the escape.
Proof of Concept
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Html;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// XSS payload with malicious number format
$sheet->setCellValueExplicit('A1', '<img src=x onerror=alert(document.cookie)>', DataType::TYPE_STRING);
$sheet->getStyle('A1')->getNumberFormat()->setFormatCode('. @');
$writer = new Html($spreadsheet);
$writer->save('output.html');The generated HTML contains:
<td>. <img src=x onerror=alert(document.cookie)></td>The XSS payload is completely unescaped.
Tested Bypass Formats
| Format Code | Result | Escaped? |
|---|---|---|
General (default) | Original value | YES (safe) |
. @ | . + value | NO (XSS!) |
@ (trailing space) | value + | NO (XSS!) |
x@ | x + value | NO (XSS!) |
This was tested with PhpSpreadsheet 4.5.0 and confirmed the XSS executes in the browser.
Impact
Any application that:
- Accepts uploaded XLSX files from users
- Converts them to HTML using PhpSpreadsheet's HTML writer
- Displays the HTML to other users
...is vulnerable to stored XSS. The attacker embeds the payload in a cell value and sets a custom number format in the XLSX file's xl/styles.xml.
Suggested Fix
Always apply htmlspecialchars() regardless of whether formatting changed the value:
// Instead of conditional escaping:
$cellData = htmlspecialchars($cellData, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');Or escape AFTER formatting, not conditionally based on equality.
Reporter
Keyvan Hardani
AnalysisAI
Stored XSS in PhpSpreadsheet's HTML writer (Writer/Html.php) allows an attacker who can supply a crafted XLSX file to inject arbitrary HTML into rendered output, executing JavaScript in victims' browsers. The root cause is a faulty identity-check gate at line ~1592 that skips htmlspecialchars() whenever a custom number format transforms cell data - a condition trivially triggered by adding any literal character (even a trailing space) to a format code containing the @ text placeholder. A detailed proof-of-concept is publicly available in the GitHub Security Advisory; the vulnerability is confirmed in PhpSpreadsheet versions across the 2.x, 3.x, and 4.x/5.x release lines, with patches released in 2.1.16, 2.4.5, 3.10.5, and 5.7.0. No active exploitation has been confirmed (not in CISA KEV), and the 0.03% EPSS score reflects low opportunistic exploitation probability at this time.
Technical ContextAI
PhpSpreadsheet (composer package phpoffice/phpspreadsheet) is the dominant PHP library for reading and writing spreadsheet files. Its HTML writer renders spreadsheet cells as HTML table cells. The vulnerability resides in Writer/Html.php, where the logic compares $cellData (after number formatting is applied) to $origData (the raw cell value) to decide whether to HTML-encode the output. When a cell's NumberFormat uses the @ text placeholder combined with any additional literal characters - such as '. @', '@ ', or 'x@' - the number formatter substitutes @ with the cell value and appends/prepends the literals, making $cellData !== $origData. This inequality causes the htmlspecialchars() call to be bypassed entirely. An attacker controls both the cell value (the XSS payload) and the format code (set in xl/styles.xml within the XLSX ZIP archive), making the bypass fully under their control. CWE-79 (Improper Neutralization of Input During Web Page Generation) precisely describes the root cause: HTML output is assembled from user-controlled input without guaranteed encoding.
RemediationAI
Upgrade to the vendor-patched release corresponding to your installed branch: 5.7.0 (for 4.0.0-5.6.0 installs), 3.10.5 (for 3.3.0-3.10.4), 2.4.5 (for 2.2.0-2.4.4), or 2.1.16 (for 2.0.0-2.1.15). All four fixes are confirmed in the GitHub advisory at https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-hrmw-qprp-wgmc. Update via Composer: composer update phpoffice/phpspreadsheet. If an immediate upgrade is not possible, the most effective compensating control is to strip or whitelist number format codes from untrusted XLSX files before passing them to the HTML writer - reject or sanitize any format code containing @ combined with additional literal characters. Alternatively, disable the HTML writer output pathway for untrusted uploads entirely and render spreadsheet data through a different, non-HTML mechanism until patched. Note that sanitizing cell values without also sanitizing format codes is insufficient, because the format code itself controls whether encoding is skipped.
In PHP versions 7.1.x below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 in certain configurations of FPM setup it
sapi/cgi/cgi_main.c in PHP before 5.3.12 and 5.4.x before 5.4.2, when configured as a CGI script (aka php-cgi), does not
(1) boardData102.php, (2) boardData103.php, (3) boardDataJP.php, (4) boardDataNA.php, and (5) boardDataWW.php in Netgear
The '/common/download_agent_installer.php' script in the Quest KACE System Management Appliance 8.0.318 is accessible by
ProjectSend versions prior to r1720 are affected by an improper authentication vulnerability. Rated critical severity (C
Roundcube Webmail contains a critical PHP object deserialization vulnerability (CVE-2025-49113, CVSS 9.9) that allows au
Util/PHP/eval-stdin.php in PHPUnit before 4.8.28 and 5.x before 5.6.3 allows remote attackers to execute arbitrary PHP c
Palo Alto Networks PAN-OS management web interface contains an authentication bypass allowing unauthenticated attackers
Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re
Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re
The get_referers function in /opt/ws/bin/sblistpack in Sophos Web Appliance before 3.7.9.1 and 3.8 before 3.8.1.1 allows
The Backup Migration plugin for WordPress is vulnerable to Remote Code Execution in all versions up to, and including, 1
Same weakness CWE-79 – Cross-site Scripting (XSS)
View allShare
External POC / Exploit Code
Leaving vuln.today
GHSA-hrmw-qprp-wgmc