Skip to content

Commit cdc1852

Browse files
authored
Merge pull request #1427 from troosan/libxml_disable_entity_loader
disable entity loader before parsing XML to avoid XXE injection
2 parents 94cf1ae + 4c4c6f4 commit cdc1852

File tree

6 files changed

+8
-4
lines changed

6 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ v0.15.0 (?? ??? 2018)
3737
- Fix parsing of Heading and Title formating @troosan @gthomas2 #465
3838
- Fix Dateformat typo, fix hours casing, add Month-Day-Year formats @ComputerTinker #591
3939
- Fix missing column width in ODText writer @potofcoffee #413
40+
- Disable entity loader before parsing XML to avoid XXE injection @Tom4t0 #1427
4041

4142
### Changed
4243
- Remove zend-stdlib dependency @Trainmaster #1284

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"require-dev": {
6767
"ext-zip": "*",
6868
"ext-gd": "*",
69-
"phpunit/phpunit": "^4.8.36 || ^5.0",
69+
"phpunit/phpunit": "^4.8.36 || ^7.0",
7070
"squizlabs/php_codesniffer": "^2.9",
7171
"friendsofphp/php-cs-fixer": "^2.2",
7272
"phpmd/phpmd": "2.*",

phpunit.xml.dist

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
convertNoticesToExceptions="true"
77
convertWarningsToExceptions="true"
88
processIsolation="false"
9-
stopOnFailure="false"
10-
syntaxCheck="false">
9+
stopOnFailure="false">
1110
<testsuites>
1211
<testsuite name="PhpWord Test Suite">
1312
<directory>./tests/PhpWord</directory>
@@ -22,7 +21,7 @@
2221
</whitelist>
2322
</filter>
2423
<logging>
25-
<log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" />
24+
<log type="coverage-html" target="./build/coverage" />
2625
<log type="coverage-clover" target="./build/logs/clover.xml" />
2726
</logging>
2827
</phpunit>

src/PhpWord/Shared/Html.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static function addHtml($element, $html, $fullHTML = false, $preserveWhit
7171
}
7272

7373
// Load DOM
74+
libxml_disable_entity_loader(true);
7475
$dom = new \DOMDocument();
7576
$dom->preserveWhiteSpace = $preserveWhiteSpace;
7677
$dom->loadXML($html);

src/PhpWord/TemplateProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function __construct($documentTemplate)
113113
*/
114114
protected function transformSingleXml($xml, $xsltProcessor)
115115
{
116+
libxml_disable_entity_loader(true);
116117
$domDocument = new \DOMDocument();
117118
if (false === $domDocument->loadXML($xml)) {
118119
throw new Exception('Could not load the given XML document.');

tests/PhpWord/_includes/XmlDocument.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ public function getFileDom($file = 'word/document.xml')
7676
$this->file = $file;
7777

7878
$file = $this->path . '/' . $file;
79+
libxml_disable_entity_loader(false);
7980
$this->dom = new \DOMDocument();
8081
$this->dom->load($file);
82+
libxml_disable_entity_loader(true);
8183

8284
return $this->dom;
8385
}

0 commit comments

Comments
 (0)