PhpSpreadsheet CVE-2026-40296
MEDIUMAttack ChainAIDerived
Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain
-
AccessUpload crafted XLSX with XSS payload cell
-
DeliveryEmbed custom @ number format in xl/styles.xml
-
ExploitApplication passes file to PhpSpreadsheet HTML writer
-
ExecutionEquality check skips htmlspecialchars()
-
PersistUnescaped payload written to HTML output
-
ImpactVictim views page, XSS executes in browser
Vulnerability Assessment
| Weakness |
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Output encoding, context-aware escaping
MITRE ATT&CK
2 techniques across 2 tactics: Initial Access, Execution The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up. |
| Exploitation Conditions | Exploitation requires three concurrent application-level conditions: (1) the application accepts XLSX files submitted by potentially untrusted users or from untrusted sources, (2) the application processes those files using PhpSpreadsheet's HTML writer (Writer\Html) to produce HTML output, and (3) the resulting HTML is displayed to other users (stored XSS pathway) or reflected back to the uploader (self-XSS). The CVSS PR:L metric indicates the attacker needs some level of access to submit files - fully anonymous upload endpoints also satisfy this. The CVSS UI:R metric means a victim must view the rendered HTML; the vulnerability does not auto-execute server-side. The bypass is unconditional once the format code satisfies the trigger: any custom number format containing the @ text placeholder plus at least one additional literal character in the XLSX file's xl/styles.xml triggers it. The default 'General' format does NOT trigger the bypass. Applications using PhpSpreadsheet only for non-HTML outputs (XLSX, CSV, PDF) are not affected by this specific vulnerability. |
| Impact | The CVSS 3.1 base score of 5.4 (AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N) accurately reflects the attack surface: network-reachable, low complexity, low-privilege attacker, scope change to victim browser, but limited C/I impact consistent with session-hijacking-class XSS. The EPSS score of 0.03% (8th percentile) signals low automated exploitation probability, likely because exploitation requires a specific application deployment pattern - the application must both accept untrusted XLSX uploads and render the result as HTML for other users. This is a real but conditional attack surface, not a universal exposure. The publicly available proof-of-concept lowers the technical bar significantly; any developer could weaponize this within minutes. KEV absence and low EPSS suggest no mass exploitation currently, but the stored XSS pathway (attacker uploads once, all viewers are affected) elevates business risk beyond what the numeric score implies. The fix versions are confirmed across multiple release branches, making remediation straightforward. This is a genuine priority for any application in the file-upload-to-HTML-rendering deployment pattern, but low risk for applications that only use PhpSpreadsheet for non-HTML output formats. |
| Exploit ScenarioDerived | An attacker uploads a crafted XLSX file to a web application that converts spreadsheets to HTML previews. The XLSX contains a cell with the value '<img src=x onerror=alert(document.cookie)>' and a custom number format of '. @' embedded in xl/styles.xml. When the application renders the spreadsheet as HTML using PhpSpreadsheet's HTML writer, the conditional escape logic is bypassed and the payload is written verbatim into the HTML table cell. Any user who views the preview page executes the attacker's JavaScript in their browser session, enabling cookie theft, session hijacking, or further payload delivery. A working proof-of-concept for this exact scenario is included in the GitHub Security Advisory. |
Get an e-mail when this CVE is exploited, patched or re-scored. Free account.
Alert meAnalysisAIv1 – Jul 24, 2026
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.
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.
Affected Packages
Source: OSV (Open Source Vulnerabilities)
Affects your stack
Affects 1 package in composer
Checking this CVE against your own stacks and servers is part of the Basic plan and up.
Technical ContextAI · show details
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.
Know when PHP gets its next vulnerability
- Watch products and get an email when something new is published
- Check this CVE against your own stack and servers
- Exploit and PoC references, threat intelligence from 22 sources
No credit card · 7-day full trial
Severity 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 Vendor (https://github.com/PHPOffice/PhpSpreadsheet).
CVSS VectorVendor: https://github.com/PHPOffice/PhpSpreadsheet
DescriptionCVE.org
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
Threat Intelligence Overview
How this decision was reached
The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.
What every action level means
SSVC AssessmentENISA
Priority Score
Attack Technique
Cross-Site Scripting occurs when an application accepts untrusted data and sends it to a web browser without proper validation or encoding.
Affected Products (CPE)CVE.org
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
GHSA-hrmw-qprp-wgmc
NVD
CVE.org
EPSS
Exploit-DB