CVE-2026-40296

CVE-2026-40296 is a medium-severity cross-site scripting (XSS) vulnerability in phpoffice/phpspreadsheet (composer), affecting versions >= 4.0.0, <= 5.6.0. It is fixed in 5.7.0, 3.10.5, 2.4.5, 2.1.16, 1.30.4.

Summary

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.

Reporter

Keyvan Hardani

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.

Untrusted input is rendered as active markup in a victim's browser, which can run script in their session. Typical impact: session or credential theft, and actions taken as the user.

CVE-2026-40296 has a CVSS score of 5.4 (Medium). The vector is network-reachable, low privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (5.7.0, 3.10.5, 2.4.5, 2.1.16, 1.30.4); upgrading removes the vulnerable code path.

Affected versions

phpoffice/phpspreadsheet (>= 4.0.0, <= 5.6.0) phpoffice/phpspreadsheet (>= 3.3.0, <= 3.10.4) phpoffice/phpspreadsheet (>= 2.2.0, <= 2.4.4) phpoffice/phpspreadsheet (>= 2.0.0, <= 2.1.15) phpoffice/phpspreadsheet (<= 1.30.3)

Security releases

phpoffice/phpspreadsheet → 5.7.0 (composer) phpoffice/phpspreadsheet → 3.10.5 (composer) phpoffice/phpspreadsheet → 2.4.5 (composer) phpoffice/phpspreadsheet → 2.1.16 (composer) phpoffice/phpspreadsheet → 1.30.4 (composer)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

See it in your environment

Remediation advice

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.

Frequently Asked Questions

  1. What is CVE-2026-40296? CVE-2026-40296 is a medium-severity cross-site scripting (XSS) vulnerability in phpoffice/phpspreadsheet (composer), affecting versions >= 4.0.0, <= 5.6.0. It is fixed in 5.7.0, 3.10.5, 2.4.5, 2.1.16, 1.30.4. Untrusted input is rendered as active markup in a victim's browser, which can run script in their session.
  2. How severe is CVE-2026-40296? CVE-2026-40296 has a CVSS score of 5.4 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which versions of phpoffice/phpspreadsheet are affected by CVE-2026-40296? phpoffice/phpspreadsheet (composer) versions >= 4.0.0, <= 5.6.0 is affected.
  4. Is there a fix for CVE-2026-40296? Yes. CVE-2026-40296 is fixed in 5.7.0, 3.10.5, 2.4.5, 2.1.16, 1.30.4. Upgrade to this version or later.
  5. Is CVE-2026-40296 exploitable, and should I be worried? Whether CVE-2026-40296 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether CVE-2026-40296 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix CVE-2026-40296?
    • Upgrade phpoffice/phpspreadsheet to 5.7.0 or later
    • Upgrade phpoffice/phpspreadsheet to 3.10.5 or later
    • Upgrade phpoffice/phpspreadsheet to 2.4.5 or later
    • Upgrade phpoffice/phpspreadsheet to 2.1.16 or later
    • Upgrade phpoffice/phpspreadsheet to 1.30.4 or later

Other vulnerabilities in phpoffice/phpspreadsheet

CVE-2026-40902CVE-2026-40863CVE-2026-34084CVE-2026-40296CVE-2026-35453

Stop the waste.
Protect your environment with Kodem.