🌐 AI搜索 & 代理 主页
Skip to content

Commit 2e8acd9

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

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
@@ -183,9 +183,9 @@ protected function findTemplate(string $name, bool $throw = true)
183183
}
184184

185185
try {
186-
$this->validateName($name);
187-
188186
list($namespace, $shortname) = $this->parseName($name);
187+
188+
$this->validateName($shortname);
189189
} catch (LoaderError $e) {
190190
if (!$throw) {
191191
return null;

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)