Bug #67350 [Com]: An XML DTD with an external parameter failes to include the subset

From: Date: Wed, 04 Jun 2014 13:06:09 +0000
Subject: Bug #67350 [Com]: An XML DTD with an external parameter failes to include the subset
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186054@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67350&edit=1 ID: 67350 Comment by: ant-dani-2 at hotmail dot com Reported by: rjlaustin at teksavvy dot com Summary: An XML DTD with an external parameter failes to include the subset Status: Open Type: Bug Package: DOM XML related Operating System: Linux PHP Version: 5.4.28 Block user comment: N Private report: N New Comment: If you look at http://uk.php.net/libxml.constants, you'll see that LIBXML_DTDLOAD is described as "Load the external subset". The "subset" is (as far as I know) any entity with an external DTD. DOCTYPE is the set. And I can say I do have evidence. I was trying to embed the XHTML 1.0 Transitional DTD, with the intent of having several (unique id) HTML nodes that define different webpage layouts. This would (and did) allow me to focus solely on the code behaviour, without my eyes bleeding from seeing mixed PHP/HTML. Everything was working fine on windows, but validation always failed on Linux. Looked on Apache's error log, and saw warnings about "declaration not found for element ..." The 'head' of my layout.xml is: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE layout [ <!ELEMENT layout (html?)> <!ENTITY % html SYSTEM "xhtml/xhtml1-transitional.dtd"> %html; ]> Previous Comments: ------------------------------------------------------------------------ [2014-06-03 15:10:56] rjlaustin at teksavvy dot com Thanks. I should have looked up XXE (which meant nothing to me) which I have now done, and I have read what the OWASP site has to say about the vulnerability. Point 1. What I observe is this: The PHP version 5.5.11 (April 9 2014) for the Mac, as distributed by XAMPP, allows access to an external subset within a DTD WHETHER OR NOT the option LIBXML_DTDLOAD is used on the PHP function call loadXML(). What I don't know is: is that good behaviour or bad behaviour? If the purpose of the LIBXML_DTDLOAD option is to allow external file access, then I would have expected that when that option is absent external file access should NOT be allowed. But that may not be what LIBXML_DTDLOAD is supposed to do. Point 2. What I also observed was this: On the Linux systems that experienced the problem I reported, only the subset of the DTD was not loaded; but the major file, the one named in the DOCTYPE element, was still being happily accessed. The OWASP article on this XXE vulnerability deals exclusively with that access; it doesn't mention the subset access that was what broke for me. If the security patch that you identify as resulting in the behaviour on Linux that broke my code is actually supposed to prevent access to external files named in the DOCTYPE element, it is NOT working. It is allowing those files, but blocking (silently) only their subsets. Blocking subsets while still allowing the main file to be read doesn't make sense to me. Do you, by any chance, have evidence that the security patch of which you write was added to the Linux build at the time when this bug (change in behaviour, if you prefer) first occurred? ------------------------------------------------------------------------ [2014-06-03 10:05:53] ant-dani-2 at hotmail dot com Well, the problem on linux is allowing something like this <!ENTITY % something SYSTEM "/etc/shadow"> let pass through the parser, specially if the web server is running as root. ------------------------------------------------------------------------ [2014-06-03 01:45:43] rjlaustin at teksavvy dot com It is certainly true that I have not set the option 'LIBXML_DTDLOAD' on my loadXML() call, and the documentation for that option ("Load the external subset") could refer to what is now sometimes not working - though I couldn't be sure from those four words alone. However, to try @ant-dani-2's suggestion I would need a machine that displays the problem and I haven't got one. I have an elderly Windows (2000) system (running PHP Version 5.3.1 from November 2009) that probably won't run anything new enough to have the security patch agains XXE Injection that is said to be responsible; and I have a Mac laptop that is now running a very new XAMPP package - but the problem doesn't happen there. It seems odd to me that a security patch would affect some systems in this way and not others - or perhaps the security patch hasn't been applied to all systems? But then, why not? Is security only a problem on Linux systems? And of course the fact that my code has worked for a long time (and still works in places) needs some explaining too - was that itself a bug, or was the LIBXML option setting never really implemented? I would have thought that all PHP systems should behave alike (unless there is a pretty good reason for them not doing so). And if that is so, I think there is a bug here though it may not be what I have complained of. I'm grateful for the suggestion and I'm sorry I cannot actually help by testing it out. If I find myself in position to test and confirm the suggestion I will certainly report the result. ------------------------------------------------------------------------ [2014-06-02 17:24:44] requinix@php.net @rjlaustin, please try @ant-dani-2's suggestion. ------------------------------------------------------------------------ [2014-06-02 15:38:48] ant-dani-2 at hotmail dot com So I found out this is not really a bug, but the result of a security patch agains XXE Injection. If you're just loading a local trusted xml file, don't forget to explicitly tell libxml2 to load the external entities: $xml = new DOMDocument(); $xml->load("your.xml", LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID); This will "fix" your bug. I hope it helps you. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=67350 -- Edit this bug report at https://bugs.php.net/bug.php?id=67350&edit=1

« previous php.bugs (#186054) next »