|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-04-01 17:09 UTC] nicolas dot gregoire at agarri dot fr
Description: ------------ Current version of PHP5 allow creation of arbitrary files when processing XSLT content. This was tested on the following releases : - PHP 5.3.2-1ubuntu4.7 with Suhosin-Patch (cli) (built: Jan 12 2011 18:36:08) - PHP 5.3.6 (cli) (built: Apr 1 2011 11:26:17) The problem lies in the unrestricted use of libxslt. The attached patch will forbid some operations like the creation of files or directories, by calling the libxslt security API. Test script: --------------- <?php $sXml = '<xml><foo>Hello from XML</foo></xml>'; $sXsl = <<<EOT <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sax="http://icl.com/saxon" extension-element-prefixes="sax"> <xsl:template match="//foo"> <sax:output href="0wn3d.php" method="text"> <xsl:value-of select="'0wn3d via PHP and libxslt ...'"/> <xsl:apply-templates/> </sax:output> </xsl:template> </xsl:stylesheet> EOT; # LOAD XML FILE $XML = new DOMDocument(); $XML->loadXML( $sXml ); # LOAD XSLT FILE $XSL = new DOMDocument(); $XSL->loadXML( $sXsl ); # START XSLT $xslt = new XSLTProcessor(); $xslt->importStylesheet( $XSL ); # TRASNFORM & PRINT print $xslt->transformToXML( $XML ); ?> Expected result: ---------------- File isn't created and PHP displays some warnings : Warning: XSLTProcessor::transformToXml(): runtime error: file /somewhere/ line 7 element output in /somewhere/simple_xslt.php on line 34 Warning: XSLTProcessor::transformToXml(): File write for 0wn3d.php refused in /somewhere/simple_xslt.php on line 34 Warning: XSLTProcessor::transformToXml(): runtime error: file /somewhere/ line 7 element output in /somewhere/simple_xslt.php on line 34 Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for 0wn3d.php denied in /somewhere/simple_xslt.php on line 34 Actual result: -------------- File '0wn3d.php' is created Patcheslibxslt_54446_2 (last revision 2011-04-18 10:01 UTC by chregu@php.net)libxslt_54446.patch (last revision 2011-04-03 22:35 UTC by cataphract@php.net) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 11:00:02 2025 UTC |
It's now als in the PHP 5.3.x branch (will be in 5.3.9). We couldn't use the same approach as in PHP 5.4 due to ABI compatibility problems. We had to introduce an ini option. Here's a code example, which works in 5.3 (actually anything >= 5.0) and 5.4 for writing from within XSLT. *** $xsl = new XSLTProcessor(); //if you want to write from within the XSLT if (version_compare(PHP_VERSION,'5.4',"<")) { $oldval = ini_set("xsl.security_prefs",XSL_SECPREFS_NONE); } else { $oldval = $xsl->setSecurityPreferences(XSL_SECPREFS_NONE); } $xsl->transformToXml(...); //go back to the old setting. Better safe than sorry if (version_compare(PHP_VERSION,'5.4',"<")) { ini_set("xsl.security_prefs",$oldval); } else { $xsl->setSecurityPreferences($oldval); //or just do // $xsl = null; // to get away of this object }