mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
Fix a security issue on filesystem loader (possibility to load a template outside a configured directory)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user