Skip to content

Commit

Permalink
Fix a security issue on filesystem loader (possibility to load a temp…
Browse files Browse the repository at this point in the history
…late outside a configured directory)
  • Loading branch information
fabpot committed Jul 13, 2022
1 parent ae39480 commit f800934
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 @@ -221,9 +221,9 @@ protected function findTemplate($name)
}

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 @@ -31,6 +31,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 @@ -62,6 +63,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 f800934

Please sign in to comment.