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

Commit 2b60157

Browse files
author
MarkBaker
committed
Fix and improve XXE security scanning for XML-based Readers
1 parent d3373c9 commit 2b60157

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Classes/PHPExcel/Reader/Abstract.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ public function canRead($pFilename)
269269
*/
270270
public function securityScan($xml)
271271
{
272+
$pattern = '/encoding="(.*?)"/';
273+
$result = preg_match($pattern, $xml, $matches);
274+
if ($result) {
275+
$charset = $matches[1];
276+
} else {
277+
$charset = 'UTF-8';
278+
}
279+
280+
if ($charset !== 'UTF-8') {
281+
$xml = mb_convert_encoding($xml, 'UTF-8', $charset);
282+
}
283+
272284
$pattern = '/\\0?' . implode('\\0?', str_split('<!DOCTYPE')) . '\\0?/';
273285
if (preg_match($pattern, $xml)) {
274286
throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
**************************************************************************************
2424

2525

26-
Planned for 1.8.2
26+
2018-11-22 (v1.8.2):
27+
- Security (MBaker) - Fix and improve XXE security scanning for XML-based Readers
2728
- Bugfix: (MBaker) - Fix to getCell() method when cell reference includes a worksheet reference
2829
- Bugfix: (ncrypthic) Work Item GH-570 - Ignore inlineStr type if formula element exists
2930
- Bugfix: (hernst42) Work Item GH-709 - Fixed missing renames of writeRelationShip (from _writeRelationShip)

0 commit comments

Comments
 (0)