mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 03:16:34 +00:00
security #cve- Fix a security issue on filesystem loader (possibility to load a template outside a configured directory) (fabpot)
This PR was merged into the 1.x branch.
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