Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit 83cf33b

Browse files
committed
Merge pull request #15 from butonic/prevent_php_from_loading_external_resources
prevent php from loading external resources
2 parents 38b2ad8 + f39c3d7 commit 83cf33b

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎library/ZendSearch/Lucene/Document/AbstractOpenXML.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ protected function extractMetaData(\ZipArchive $package)
6767
// Data holders
6868
$coreProperties = array();
6969

70+
// Prevent php from loading remote resources
71+
$loadEntities = libxml_disable_entity_loader(true);
72+
7073
// Read relations and search for core properties
7174
$relations = simplexml_load_string($package->getFromName("_rels/.rels"));
75+
76+
// Restore entity loader state
77+
libxml_disable_entity_loader($loadEntities);
78+
7279
foreach ($relations->Relationship as $rel) {
7380
if ($rel["Type"] == self::SCHEMA_COREPROPERTIES) {
7481
// Found core properties! Read in contents...

‎library/ZendSearch/Lucene/Document/Docx.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ private function __construct($fileName, $storeContent)
6060
if ($relationsXml === false) {
6161
throw new RuntimeException('Invalid archive or corrupted .docx file.');
6262
}
63+
64+
// Prevent php from loading remote resources
65+
$loadEntities = libxml_disable_entity_loader(true);
66+
6367
$relations = simplexml_load_string($relationsXml);
68+
69+
// Restore entity loader state
70+
libxml_disable_entity_loader($loadEntities);
71+
6472
foreach($relations->Relationship as $rel) {
6573
if ($rel ["Type"] == AbstractOpenXML::SCHEMA_OFFICEDOCUMENT) {
6674
// Found office document! Read in contents...

‎library/ZendSearch/Lucene/Document/Pptx.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ private function __construct($fileName, $storeContent)
8080
if ($relationsXml === false) {
8181
throw new RuntimeException('Invalid archive or corrupted .pptx file.');
8282
}
83+
84+
// Prevent php from loading remote resources
85+
$loadEntities = libxml_disable_entity_loader(true);
86+
8387
$relations = simplexml_load_string($relationsXml);
88+
89+
// Restore entity loader state
90+
libxml_disable_entity_loader($loadEntities);
91+
8492
foreach ($relations->Relationship as $rel) {
8593
if ($rel["Type"] == AbstractOpenXML::SCHEMA_OFFICEDOCUMENT) {
8694
// Found office document! Search for slides...

‎library/ZendSearch/Lucene/Document/Xlsx.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ private function __construct($fileName, $storeContent)
8989
if ($relationsXml === false) {
9090
throw new RuntimeException('Invalid archive or corrupted .xlsx file.');
9191
}
92+
93+
// Prevent php from loading remote resources
94+
$loadEntities = libxml_disable_entity_loader(true);
95+
9296
$relations = simplexml_load_string($relationsXml);
97+
98+
// Restore entity loader state
99+
libxml_disable_entity_loader($loadEntities);
100+
93101
foreach ($relations->Relationship as $rel) {
94102
if ($rel["Type"] == AbstractOpenXML::SCHEMA_OFFICEDOCUMENT) {
95103
// Found office document! Read relations for workbook...

0 commit comments

Comments
 (0)