Skip to main content

PhpSpreadsheet CVE-2026-40296

MEDIUM
Cross-site Scripting (XSS) (CWE-79)
2026-04-28 https://github.com/PHPOffice/PhpSpreadsheet GHSA-hrmw-qprp-wgmc
5.4
CVSS 3.1 · Vendor: https://github.com/PHPOffice/PhpSpreadsheet
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Upload crafted XLSX with XSS payload cell
  2. Delivery
    Embed custom @ number format in xl/styles.xml
  3. Exploit
    Application passes file to PhpSpreadsheet HTML writer
  4. Execution
    Equality check skips htmlspecialchars()
  5. Persist
    Unescaped payload written to HTML output
  6. Impact
    Victim 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.

This Month Plan within 30 days. Why: MEDIUM severity (CVSS 4.0-6.9).
Patch available 0.0% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – 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

composer phpoffice/phpspreadsheet fix: 1.30.4, 2.1.16, 2.4.5, 3.10.5, 5.7.0

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

Vendor (https://github.com/PHPOffice/PhpSpreadsheet) PRIMARY 5.4 MEDIUM
AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
vuln.today AI 5.4 MEDIUM

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.

3.1 AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
4.0 AV:N/AC:L/AT:N/PR:L/UI:P/VC:L/VI:L/VA:N/SC:L/SI:L/SA:N

Primary rating from Vendor (https://github.com/PHPOffice/PhpSpreadsheet).

CVSS VectorVendor: https://github.com/PHPOffice/PhpSpreadsheet

Attack Vector
Network
Attack Complexity
Low
Privileges Required
Low
User Interaction
Required
Scope
Changed
Confidentiality
Low
Integrity
Low
Availability
None

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():

php
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

php
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:

html
<td>. <img src=x onerror=alert(document.cookie)></td>

The XSS payload is completely unescaped.

Tested Bypass Formats

Format CodeResultEscaped?
General (default)Original valueYES (safe)
. @. + valueNO (XSS!)
@ (trailing space)value + NO (XSS!)
x@x + valueNO (XSS!)

This was tested with PhpSpreadsheet 4.5.0 and confirmed the XSS executes in the browser.

Impact

Any application that:

  1. Accepts uploaded XLSX files from users
  2. Converts them to HTML using PhpSpreadsheet's HTML writer
  3. 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:

php
// 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

EPSS Score
0.0%
Top 92% exploitable
Prevalence
High
de facto standard PHP spreadsheet library, tens of millions of Composer installs
Threat Intel
1
1 source
Data Quality
4 sources
Confidence: Medium

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.

SignalValue
Severity MEDIUM
CISA KEV No
Public POC No
EPSS 0.0%
Patch available Yes
Active threat No
Deciding rule
MEDIUM severity (CVSS 4.0-6.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision· derived
Scheduled
Exploitation· derived
None
System Exposure· derived
Open
Automatable· derived
No
Human Impact· derived
High

Priority Score

27
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +27
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

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

pkg:composer/phpoffice_phpspreadsheet
pkg:composer/phpoffice_phpspreadsheet
pkg:composer/phpoffice_phpspreadsheet
pkg:composer/phpoffice_phpspreadsheet
pkg:composer/phpoffice_phpspreadsheet

More in PHP

View all
CVE-2019-11043 CRITICAL POC
9.8 Oct 28

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

CVE-2012-1823 CRITICAL POC
9.8 May 11

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

CVE-2016-1555 CRITICAL POC
9.8 Apr 21

(1) boardData102.php, (2) boardData103.php, (3) boardDataJP.php, (4) boardDataNA.php, and (5) boardDataWW.php in Netgear

CVE-2018-11138 CRITICAL POC
9.8 May 31

The '/common/download_agent_installer.php' script in the Quest KACE System Management Appliance 8.0.318 is accessible by

CVE-2024-11680 CRITICAL POC
9.8 Nov 26

ProjectSend versions prior to r1720 are affected by an improper authentication vulnerability. Rated critical severity (C

CVE-2025-49113 CRITICAL POC
9.9 Jun 02

Roundcube Webmail contains a critical PHP object deserialization vulnerability (CVE-2025-49113, CVSS 9.9) that allows au

CVE-2017-9841 CRITICAL POC
9.8 Jun 27

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

CVE-2025-0108 HIGH POC
8.8 Feb 12

Palo Alto Networks PAN-OS management web interface contains an authentication bypass allowing unauthenticated attackers

CVE-2021-25298 HIGH POC
8.8 Feb 15

Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re

CVE-2021-25296 HIGH POC
8.8 Feb 15

Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re

CVE-2013-4983 CRITICAL POC
10.0 Sep 10

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

CVE-2023-6553 CRITICAL POC
9.8 Dec 15

The Backup Migration plugin for WordPress is vulnerable to Remote Code Execution in all versions up to, and including, 1

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy