diff options
author | Steve Clay <steve@mrclay.org> | 2013-07-11 13:24:01 -0400 |
---|---|---|
committer | Paweł Sroka <srokap@gmail.com> | 2013-11-04 03:34:21 +0100 |
commit | d53447f7e6b3277f3249d9a70e56ec01a90c3a60 (patch) | |
tree | a61fa62cef82fef01254849bbbd70dbf149e854a /engine/classes/ElggAutoP.php | |
parent | 550ef1fe32fc8da940c42359f7a6347e65138c85 (diff) | |
download | elgg-d53447f7e6b3277f3249d9a70e56ec01a90c3a60.tar.gz elgg-d53447f7e6b3277f3249d9a70e56ec01a90c3a60.tar.bz2 |
Disable loading external entities during XML parsing
Diffstat (limited to 'engine/classes/ElggAutoP.php')
-rw-r--r-- | engine/classes/ElggAutoP.php | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/engine/classes/ElggAutoP.php b/engine/classes/ElggAutoP.php index 71536c433..05842d1b2 100644 --- a/engine/classes/ElggAutoP.php +++ b/engine/classes/ElggAutoP.php @@ -110,12 +110,19 @@ class ElggAutoP { // http://www.php.net/manual/en/domdocument.loadhtml.php#95463 libxml_use_internal_errors(true); + // Do not load entities. May be unnecessary, better safe than sorry + $disable_load_entities = libxml_disable_entity_loader(true); + if (!$this->_doc->loadHTML("<html><meta http-equiv='content-type' " . "content='text/html; charset={$this->encoding}'><body>{$html}</body>" . "</html>")) { + + libxml_disable_entity_loader($disable_load_entities); return false; } + libxml_disable_entity_loader($disable_load_entities); + $this->_xpath = new DOMXPath($this->_doc); // start processing recursively at the BODY element $nodeList = $this->_xpath->query('//body[1]'); @@ -135,9 +142,16 @@ class ElggAutoP { // re-parse so we can handle new AUTOP elements + // Do not load entities. May be unnecessary, better safe than sorry + $disable_load_entities = libxml_disable_entity_loader(true); + if (!$this->_doc->loadHTML($html)) { + libxml_disable_entity_loader($disable_load_entities); return false; } + + libxml_disable_entity_loader($disable_load_entities); + // must re-create XPath object after DOM load $this->_xpath = new DOMXPath($this->_doc); |