In PHP, one can pass optional arguments to various XML parsers, one of them being LIBXML_NOENT
. The documentation has this to say about it:
LIBXML_NOENT (integer)
Substitute entities
Substitute entities
isn't very informative (what entities? when are they substituted?). But I think it's fair to assume that NOENT
is short for NO_ENTITIES
or NO_EXTERNAL_ENTITIES
, so to me it seems to be a fair assumption that this flag disables the parsing of (external) entities.
But that is indeed not the case:
$xml = '<!DOCTYPE root [<!ENTITY c PUBLIC "bar" "/etc/passwd">]>
<test>&c;</test>';
$dom = new DOMDocument();
$dom->loadXML($xml, LIBXML_NOENT);
echo $dom->textContent;
The result is that the content of /etc/passwd is echoed. Without the LIBXML_NOENT
argument this is not the case.
For non-external entities, the flag doesn't seem to have any effect. Example:
$xml = '<!DOCTYPE root [<!ENTITY c "TEST">]>
<test>&c;</test>';
$dom = new DOMDocument();
$dom->loadXML($xml);
echo $dom->textContent;
The result of this code is "TEST", with and without LIBXML_NOENT
.
The flag doesn't seem to have any effect on pre-defined entities such as <
.
So my questions are:
- What exactly does the
LIBXML_NOENT
flag do? - Why is it called
LIBXML_NOENT
? What is it short for, and wouldn'tLIBXML_ENT
orLIBXML_PARSE_EXTERNAL_ENTITIES
be a better fit? - Is there a flag that actually prevents the parsing of all entities?