Skip to content

Commit 35f3035

Browse files
committed
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.
2 parents ae39480 + f800934 commit 35f3035

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Loader/FilesystemLoader.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ protected function findTemplate($name)
221221
}
222222

223223
try {
224-
$this->validateName($name);
225-
226224
list($namespace, $shortname) = $this->parseName($name);
225+
226+
$this->validateName($shortname);
227227
} catch (LoaderError $e) {
228228
if (!$throw) {
229229
return false;

tests/Loader/FilesystemTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testGetSourceContext()
3131
public function testSecurity($template)
3232
{
3333
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
34+
$loader->addPath(__DIR__.'/../Fixtures', 'foo');
3435

3536
try {
3637
$loader->getCacheKey($template);
@@ -62,6 +63,10 @@ public function getSecurityTests()
6263
['filters\\\\..\\\\..\\\\AutoloaderTest.php'],
6364
['filters\\//../\\/\\..\\AutoloaderTest.php'],
6465
['/../AutoloaderTest.php'],
66+
['@__main__/../AutoloaderTest.php'],
67+
['@foo/../AutoloaderTest.php'],
68+
['@__main__/../../AutoloaderTest.php'],
69+
['@foo/../../AutoloaderTest.php'],
6570
];
6671
}
6772

0 commit comments

Comments
 (0)