Skip to content

Commit

Permalink
Merge branch '2.x' into 3.x
Browse files Browse the repository at this point in the history
* 2.x:
  Fix a security issue on filesystem loader (possibility to load a template outside a configured directory)
  • Loading branch information
fabpot committed Sep 28, 2022
2 parents be33323 + d6ea14a commit 2e8acd9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ protected function findTemplate(string $name, bool $throw = true)
}

try {
$this->validateName($name);

list($namespace, $shortname) = $this->parseName($name);

$this->validateName($shortname);
} catch (LoaderError $e) {
if (!$throw) {
return null;
Expand Down
5 changes: 5 additions & 0 deletions tests/Loader/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testGetSourceContext()
public function testSecurity($template)
{
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
$loader->addPath(__DIR__.'/../Fixtures', 'foo');

try {
$loader->getCacheKey($template);
Expand Down Expand Up @@ -63,6 +64,10 @@ public function getSecurityTests()
['filters\\\\..\\\\..\\\\AutoloaderTest.php'],
['filters\\//../\\/\\..\\AutoloaderTest.php'],
['/../AutoloaderTest.php'],
['@__main__/../AutoloaderTest.php'],
['@foo/../AutoloaderTest.php'],
['@__main__/../../AutoloaderTest.php'],
['@foo/../../AutoloaderTest.php'],
];
}

Expand Down

0 comments on commit 2e8acd9

Please sign in to comment.