Skip to content

Commit

Permalink
security #cve- Fix a security issue on filesystem loader (possibility…
Browse files Browse the repository at this point in the history
… to load a template outside a configured directory) (fabpot)

This PR was merged into the 1.x branch.
  • Loading branch information
fabpot committed Sep 28, 2022
2 parents ae39480 + f800934 commit 35f3035
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 35f3035

Please sign in to comment.