Skip to content

Commit d6ea14a

Browse files
committed
Merge branch '1.x' into 2.x
* 1.x: Fix a security issue on filesystem loader (possibility to load a template outside a configured directory)
2 parents 9170edf + 35f3035 commit d6ea14a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Loader/FilesystemLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ protected function findTemplate($name, $throw = true)
206206
}
207207

208208
try {
209-
$this->validateName($name);
210-
211209
list($namespace, $shortname) = $this->parseName($name);
210+
211+
$this->validateName($shortname);
212212
} catch (LoaderError $e) {
213213
if (!$throw) {
214214
return false;

tests/Loader/FilesystemTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function testGetSourceContext()
3232
public function testSecurity($template)
3333
{
3434
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
35+
$loader->addPath(__DIR__.'/../Fixtures', 'foo');
3536

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

0 commit comments

Comments
 (0)