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 · GitHub Advisory
Share

Severity by source

GitHub Advisory 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 GitHub Advisory.

CVSS VectorGitHub Advisory

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

Lifecycle Timeline

3
Source Code Evidence Fetched
Jul 24, 2026 - 02:39 vuln.today
Analysis Generated
Jul 24, 2026 - 02:39 vuln.today
CVE Published
Apr 28, 2026 - 22:57 nvd
MEDIUM 5.4

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

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

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.

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

Share

CVE-2026-40296 vulnerability details – vuln.today

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