Merge branch '2.x' into 3.x

* 2.x:
  Fix a security issue on filesystem loader (possibility to load a template outside a configured directory)
This commit is contained in:
Fabien Potencier
2022-09-28 10:36:55 +02:00
2 changed files with 7 additions and 2 deletions
+2 -2
View File
@@ -183,9 +183,9 @@ class FilesystemLoader implements LoaderInterface
}
try {
$this->validateName($name);
list($namespace, $shortname) = $this->parseName($name);
$this->validateName($shortname);
} catch (LoaderError $e) {
if (!$throw) {
return null;
+5
View File
@@ -32,6 +32,7 @@ class FilesystemTest extends TestCase
public function testSecurity($template)
{
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
$loader->addPath(__DIR__.'/../Fixtures', 'foo');
try {
$loader->getCacheKey($template);
@@ -63,6 +64,10 @@ class FilesystemTest extends TestCase
['filters\\\\..\\\\..\\\\AutoloaderTest.php'],
['filters\\//../\\/\\..\\AutoloaderTest.php'],
['/../AutoloaderTest.php'],
['@__main__/../AutoloaderTest.php'],
['@foo/../AutoloaderTest.php'],
['@__main__/../../AutoloaderTest.php'],
['@foo/../../AutoloaderTest.php'],
];
}