Fix a security issue on filesystem loader (possibility to load a template outside a configured directory)

This commit is contained in:
Fabien Potencier
2022-07-13 14:52:38 +02:00
parent ae39480f01
commit f8009347c4
2 changed files with 7 additions and 2 deletions
+2 -2
View File
@@ -221,9 +221,9 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
}
try {
$this->validateName($name);
list($namespace, $shortname) = $this->parseName($name);
$this->validateName($shortname);
} catch (LoaderError $e) {
if (!$throw) {
return false;
+5
View File
@@ -31,6 +31,7 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase
public function testSecurity($template)
{
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
$loader->addPath(__DIR__.'/../Fixtures', 'foo');
try {
$loader->getCacheKey($template);
@@ -62,6 +63,10 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase
['filters\\\\..\\\\..\\\\AutoloaderTest.php'],
['filters\\//../\\/\\..\\AutoloaderTest.php'],
['/../AutoloaderTest.php'],
['@__main__/../AutoloaderTest.php'],
['@foo/../AutoloaderTest.php'],
['@__main__/../../AutoloaderTest.php'],
['@foo/../../AutoloaderTest.php'],
];
}