usd-2019-0046 | PhpSpreadsheet <1.8.0
Advisory ID: usd-2019-0046
CVE Number: CVE-2019-12331
Affected Product: PhpSpreadsheet
Affected Version: <1.8.0
Vulnerability Type: XML External Entity (XXE)
Security Risk: High
Vendor URL: https://phpspreadsheet.readthedocs.io/
Vendor Status: Fixed
The XmlScanner decodes the sheet1.xml from an .xlsx to utf-8 if something else than „UTF-8“ is declared in the header.
This was a security measurement to prevent CVE-2018-19277. But the fix is not sufficient. By double encode the xml payload to utf-7
it is possible to bypass the check for the string ‚<!ENTITY‘. Furthermore, even though the entity loader gets disabled by calling libxml_disable_entity_loader() before
the security check, which only uses regexp, it gets enabled again before the xml is parsed with simplexml_load_string().
This leads to an enabled entity loader while parsing the .xml, no matter which PHP version is used.
Even though this example uses Reader\Xlsx.php, all readers which directly feed the returned xml from the XmlScanner::load() method to simplexml_load_string()
should be vulnerable (xml, ods, html, gnumeric).
Proof of Concept (PoC)
Put the content into sheet1.xml and repack a .xlsx file:
When loading the .xlsx the library tries to load ext.dtd from http://127.0.0.1.8080.
Fix the call to libxml_disable_entity_loader() and set the encoding from the xml file after the encoding to the correct value.
- 2019-05-27 Daniel Hoffmann discovered the bug
- 2019-05-27 First contact attempt using firstname.lastname@example.org
- 2019-06-17 Second contact attempt using email@example.com
- 2019-06-17 Github Issue: https://github.com/PHPOffice/PhpSpreadsheet/issues/1014
- 2019-07-09 Vendor releases fix: https://github.com/PHPOffice/PhpSpreadsheet/commit/0e6238c69e863b58aeece61e48ea032696c6dccd
- 2019-10-21 First Published
This security vulnerability was found by Daniel Hoffmann of usd AG.