Skip to main content
Vulnerability Database/CVE-2024-56409

CVE-2024-56409: PhpSpreadsheet XSS Vulnerability

CVE-2024-56409 is a reflected cross-site scripting vulnerability in PhpOffice PhpSpreadsheet affecting the Currency.php file. Attackers can exploit this flaw to execute malicious scripts. This article covers technical details, affected versions, impact assessment, and available patches.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-56409 Overview

CVE-2024-56409 is a reflected cross-site scripting (XSS) vulnerability [CWE-79] in PhpSpreadsheet, a widely used PHP library for reading and writing spreadsheet files. The flaw resides in the Currency.php sample script located at /vendor/phpoffice/phpspreadsheet/samples/Wizards/NumberFormat/Currency.php. Unsanitized user input echoed back into the HTML response allows an attacker to inject arbitrary JavaScript that executes in a victim's browser. The vulnerability affects PhpSpreadsheet versions prior to 3.7.0, 2.3.5, 2.1.6, and 1.29.7. Patches are available in all four maintained release branches.

Critical Impact

Attackers can execute arbitrary JavaScript in a victim's browser session, enabling session hijacking, credential theft, and unauthorized actions when a user is tricked into visiting a crafted URL.

Affected Products

  • PhpSpreadsheet versions prior to 1.29.7 (1.x branch)
  • PhpSpreadsheet versions prior to 2.1.6 and 2.3.5 (2.x branches)
  • PhpSpreadsheet versions prior to 3.7.0 (3.x branch)

Discovery Timeline

  • 2025-01-03 - CVE-2024-56409 published to NVD
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-56409

Vulnerability Analysis

The vulnerability is a reflected XSS flaw in a sample script shipped with the PhpSpreadsheet library. The Currency.php wizard sample accepts user-supplied input through HTTP parameters and reflects values back into the rendered HTML without encoding. When the sample scripts are exposed to the web via a reachable /vendor/phpoffice/phpspreadsheet/samples/ path, an attacker can craft a URL containing malicious JavaScript. A victim who clicks the link executes the attacker's script in the context of the hosting origin.

The reflected injection runs with the same origin as the vulnerable host. Attackers can read cookies not protected by HttpOnly, exfiltrate session tokens, perform CSRF-style actions on behalf of the user, or deliver secondary payloads.

Root Cause

The root cause is missing output encoding on request parameters inside the sample script. Values received from the HTTP request are inserted directly into HTML markup rather than being escaped with a function such as htmlspecialchars(). This classic [CWE-79] pattern turns any reflected parameter into a script injection sink.

Attack Vector

Exploitation requires network access to the vulnerable sample endpoint and user interaction. The attacker crafts a URL targeting /vendor/phpoffice/phpspreadsheet/samples/Wizards/NumberFormat/Currency.php with a malicious payload embedded in a reflected parameter. The victim is lured via phishing, chat, or a malicious link. On click, the injected JavaScript executes in the victim's browser under the vulnerable site's origin.

php
// Patch excerpt: samples/Engineering/Convert-Online.php
     $quantity = $_POST['quantity'];
     $fromUnit = $_POST['fromUnit'];
     $toUnit = $_POST['toUnit'];
-    if (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
+    if (!is_numeric($quantity)) {
+        $helper->log('Quantity is not numeric');
+    } elseif (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
         /** @var float|string */
         $result = ConvertUOM::CONVERT($quantity, $fromUnit, $toUnit);
 
-        echo "{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}", PHP_EOL;
+        $helper->log("{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}");
     } else {
-        echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
+        $helper->log('Please enter quantity and select From Unit and To Unit');
     }

Source: PHPOffice/PhpSpreadsheet commit 700a803. The patch replaces direct echo of user-controlled input with structured logging and adds input type validation, breaking the reflected sink pattern used by the sample scripts.

Detection Methods for CVE-2024-56409

Indicators of Compromise

  • Web server access logs showing requests to /vendor/phpoffice/phpspreadsheet/samples/Wizards/NumberFormat/Currency.php containing URL-encoded <script>, onerror=, onload=, or javascript: strings.
  • Requests to any file under /vendor/phpoffice/phpspreadsheet/samples/ from external IP addresses, since sample scripts should not be exposed in production.
  • Outbound browser requests from internal users to attacker-controlled domains following clicks on PhpSpreadsheet sample URLs.

Detection Strategies

  • Inventory web-facing hosts for exposed vendor/phpoffice/phpspreadsheet/samples/ paths using authenticated vulnerability scanners or manual HTTP probes.
  • Deploy web application firewall (WAF) rules that flag reflected XSS patterns in query strings and POST bodies targeting PHP sample scripts.
  • Use software composition analysis (SCA) tooling to identify PhpSpreadsheet versions below 1.29.7, 2.1.6, 2.3.5, and 3.7.0 across code repositories and build artifacts.

Monitoring Recommendations

  • Alert on HTTP 200 responses from /samples/ paths within the PhpSpreadsheet directory, which indicates sample scripts are reachable to the internet.
  • Monitor browser Content Security Policy (CSP) violation reports for inline script executions originating from pages that render reflected parameters.
  • Correlate suspicious outbound requests from endpoints with recent user clicks on URLs containing the vulnerable path pattern.

How to Mitigate CVE-2024-56409

Immediate Actions Required

  • Upgrade PhpSpreadsheet to a patched release: 3.7.0, 2.3.5, 2.1.6, or 1.29.7 depending on the branch in use.
  • Remove or block web access to the vendor/phpoffice/phpspreadsheet/samples/ directory on all production and staging hosts.
  • Audit application dependency manifests (composer.json, composer.lock) to confirm the upgrade propagates to all deployments.

Patch Information

The fix is delivered in the merge commit 700a80346be269af668914172bc6f4521982d0b4 and documented in GitHub Security Advisory GHSA-j2xg-cjcx-4677. The patch replaces reflected echo calls in sample scripts with safe logging helpers and adds input validation. Update via Composer with composer update phpoffice/phpspreadsheet.

Workarounds

  • Deny HTTP access to the vendor/ directory at the web server level using Apache Require all denied or Nginx location ~ ^/vendor/ { deny all; }.
  • Delete the samples/ directory from production deployments since it is intended for development reference only.
  • Deploy a strict Content Security Policy (CSP) that disallows inline scripts and restricts script sources to trusted origins.
bash
# Nginx configuration example to block vendor path exposure
location ~* /vendor/ {
    deny all;
    return 404;
}

# Composer upgrade command
composer require phpoffice/phpspreadsheet:^3.7.0

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.