Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
* 1.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 9170edf + 35f3035 commit d6ea14a
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 @@ -206,9 +206,9 @@ protected function findTemplate($name, $throw = true)
}

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

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

$this->validateName($shortname);
} catch (LoaderError $e) {
if (!$throw) {
return false;
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 d6ea14a

Please sign in to comment.