CVE-2024-45046: PhpSpreadsheet HTML writer Cross-Site Scripting Vulnerability

phpoffice/phpspreadsheet Updated 02 Oct 2025

Summary

29/08/2024
Yes i
Moderate
5.4

CVE-2024-45046: PhpSpreadsheet HTML writer is vulnerable to Cross-Site Scripting via style information. Affects phpoffice/phpspreadsheet across 2 version ranges.

< 1.29.1 >= 2.0.0, < 2.1.0

Fixed in 1.29.1 or 2.1.0, depending on the release line you run. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

PhpSpreadsheet is a PHP library for reading and writing spreadsheet files. It provides functionality to handle various spreadsheet formats and perform operations on them. The library is widely used in PHP applications for manipulating spreadsheet data. However, a vulnerability has been discovered in the HTML writer component of PhpSpreadsheet, which allows for Cross-Site Scripting (XSS) attacks.

Vulnerability Detail

The vulnerability exists in the \PhpOffice\PhpSpreadsheet\Writer\Html class, which is responsible for generating HTML output from spreadsheet data. The class does not properly sanitize styling information, such as font names, allowing an attacker to inject arbitrary JavaScript code into the generated HTML. This can lead to the execution of malicious scripts in the context of the user's browser, potentially leading to session hijacking or other forms of attack.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 1.29.1 1.29.1
    composer require phpoffice/phpspreadsheet:1.29.1
  • >= 2.0.0, < 2.1.0 2.1.0
    composer require phpoffice/phpspreadsheet:2.1.0

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

If updating the package is not immediately possible, a temporary workaround is to manually sanitize the styling information before generating the HTML output. This can be done by using a library or function that properly sanitizes user input, such as the htmlspecialchars function in PHP. Here's an example of how to apply this workaround:

<?php

require 'vendor/autoload.php';

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
$spreadsheet = $reader->load(__DIR__ . '/book.xlsx');

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet);

// Sanitize styling information
$writer->setUseInlineCss(true);
$writer->setCssStylesheet('');

print($writer->generateHTMLAll());

By setting the setUseInlineCss method to true and providing an empty CSS stylesheet, the styling information is effectively sanitized, preventing the XSS vulnerability.

Conclusion

The PhpSpreadsheet HTML writer component is vulnerable to Cross-Site Scripting (XSS) attacks due to improper sanitization of styling information. Developers should update to version 2.1.0 or later of the phpoffice/phpspreadsheet package to fix the vulnerability. A temporary workaround is available by manually sanitizing the styling information before generating the HTML output. It is recommended to regularly check for vulnerabilities in your application using tools like Vulert.

See every vulnerability recorded for phpoffice/phpspreadsheet →

Share this vulnerability

FAQ

PhpSpreadsheet is a PHP library for reading and writing spreadsheet files. It provides functionality to handle various spreadsheet formats and perform operations on them.

The vulnerability allows an attacker to inject arbitrary JavaScript code into the generated HTML, potentially leading to session hijacking or other forms of attack.

To fix this vulnerability, update to version 2.1.0 or later of the phpoffice/phpspreadsheet package.

Yes, a temporary workaround is to manually sanitize the styling information before generating the HTML output.

Yes, you can use Vulert's playground (https://vulert.com/scanner) to check if your application is affected by this vulnerability. Vulert monitors and alerts in real-time for open-source vulnerabilities, using just the composer.lock file.

Related vulnerabilities

Recent vulnerabilities recorded for phpoffice/phpspreadsheet.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 1.29.1 1.29.1
    composer require phpoffice/phpspreadsheet:1.29.1
  • >= 2.0.0, < 2.1.0 2.1.0
    composer require phpoffice/phpspreadsheet:2.1.0

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback