Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simplexml_load_file(): I/O warning : failed to load external entity "/user-bundle/Resources/config/doctrine/model/User.orm.xml

I have some issue with my production deployment of Symfony2,

I've tried many solutions, but none have worked.

I randomly have this error when accessing my symfony application on production environment:

( ! )   Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: simplexml_load_file(): I/O warning : failed to load external entity    "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml"'    in /home/user/symfony/app/bootstrap.php.cache on line 2998
( ! )   Symfony\Component\Debug\Exception\ContextErrorException: Warning: simplexml_load_file():    I/O warning : failed to load external entity    "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml" in /home/user/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 736
Call Stack
#   Time    Memory  Function    Location
1   0.0000  262880  {main}( )   ../app_dev.php:0
2   0.0015  572736  Symfony\Component\HttpKernel\Kernel->handle( )  ../app_dev.php:79
3   0.1342  4023952 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( )    ../bootstrap.php.cache:2376
( ! )   LogicException: Request stack is empty  in /home/user/symfony/app/bootstrap.php.cache on line 2998
Call Stack
#   Time    Memory  Function    Location
1   0.3330  7110120 Symfony\Component\Debug\ErrorHandler->handleException( )    ../classes.php:0
2   0.3331  7119696 Symfony\Component\Debug\ErrorHandler->handleException( )    ../classes.php:1939

I've tried to upgrade my php version (I was in php 5.4.x and now in 5.6.4),

I've tried to upgrade lixml2 version (i am in 2.8.0 now, but i already tried to upgrade in 2.9.3)

I've constated that the version of libxml used in php is always 2.8.0, but, I haven't found the way to change this ,

I've tried to set the all directory of symfony in chmod 777

My server is a debian 7.5 server.

Maybe someone who knows this error can help me

Here is some links to differents question related to this one:

Random Error, FOSUserBundle Error and Service error

I didn't post in them because they're all outdated

[EDIT]

I found a quick fix, but it's in vendors, so it will be overrided in the first update of the doctrine update:

QuickFix in XmlDriver.php Line 737

$xmlElement = @simplexml_load_file($file);
if(!$xmlElement){
        $xmlData = file_get_contents($file);
        $xmlElement = simplexml_load_string($xmlData);
}
like image 603
PyRowMan Avatar asked Jan 23 '15 10:01

PyRowMan


1 Answers

We got this error after we started using libxml_disable_entity_loader(true); in our code. That code is vital in preventing XXE -attacks(more info of that in here). If you don't have that in your code, it could be that you have installed/updated a bundle which has that line of code in use. Note that libxml_disable_entity_loader() is not thread safe, so if there is one piece of code on one thread that executes that line, everything on that server now has that enabled throughout the process.

The FOS-bundle seems to use xml-definitions, that in return have external entities in them. Nothing major though, but that code prevents the FOS-bundles methods from using those files correctly.

Luckily, our service got that error only in one place, and the fix was obvious: Add a libxml_disable_entity_loader(false); before executing that piece of code where the error comes from, and add libxml_disable_entity_loader(true); right after that piece of code. This way the user bundle could load the xml:s it needed, but security is not compromised.

Example:

libxml_disable_entity_loader(false);
$user = $query->getOneOrNullResult(); // This generates an error if entity loader is disabled
libxml_disable_entity_loader(true);
like image 123
GotBatteries Avatar answered Oct 22 '22 06:10

GotBatteries