Skip to content

Commit b5a30be

Browse files
committed
fixed XML decoding attack vector through external entities
1 parent 786d2c1 commit b5a30be

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Mapping/Loader/XmlFileLoader.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,23 @@ protected function parseOptions(\SimpleXMLElement $nodes)
181181
protected function parseFile($file)
182182
{
183183
$internalErrors = libxml_use_internal_errors(true);
184+
$disableEntities = libxml_disable_entity_loader(true);
184185
libxml_clear_errors();
185186

186187
$dom = new \DOMDocument();
187188
$dom->validateOnParse = true;
188-
if (!$dom->load($file, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
189+
if (!$dom->loadXML(file_get_contents($file), LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
190+
libxml_disable_entity_loader($disableEntities);
191+
189192
throw new MappingException(implode("\n", $this->getXmlErrors($internalErrors)));
190193
}
194+
195+
libxml_disable_entity_loader($disableEntities);
196+
191197
if (!$dom->schemaValidate(__DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd')) {
192198
throw new MappingException(implode("\n", $this->getXmlErrors($internalErrors)));
193199
}
200+
194201
$dom->normalizeDocument();
195202

196203
libxml_use_internal_errors($internalErrors);

0 commit comments

Comments
 (0)