mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 12:37:15 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user