Skip to content

Commit 46a848c

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: fixed tests Disallow viewing dot-files in Profiler
2 parents f37096c + 11105f3 commit 46a848c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function isRootFormProvider()
162162
*/
163163
public function testIsRootForm($expected, FormView $formView)
164164
{
165-
$this->assertSame($expected, $this->extension->isRootForm($formView));
165+
$this->assertSame($expected, twig_is_root_form($formView));
166166
}
167167

168168
protected function renderForm(FormView $view, array $vars = array())

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function openAction(Request $request)
385385

386386
$filename = $this->baseDir.DIRECTORY_SEPARATOR.$file;
387387

388-
if (preg_match("'(^|[/\\\\])\.\.?([/\\\\]|$)'", $file) || !is_readable($filename)) {
388+
if (preg_match("'(^|[/\\\\])\.'", $file) || !is_readable($filename)) {
389389
throw new NotFoundHttpException(sprintf('The file "%s" cannot be opened.', $file));
390390
}
391391

src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController;
1616
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
17+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1718
use Symfony\Component\HttpKernel\Profiler\Profile;
1819
use Symfony\Component\HttpFoundation\Request;
1920

@@ -46,6 +47,42 @@ public function getEmptyTokenCases()
4647
);
4748
}
4849

50+
/**
51+
* @dataProvider getOpenFileCases
52+
*/
53+
public function testOpeningDisallowedPaths($path, $isAllowed)
54+
{
55+
$urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock();
56+
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
57+
$profiler = $this
58+
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
59+
->disableOriginalConstructor()
60+
->getMock();
61+
62+
$controller = new ProfilerController($urlGenerator, $profiler, $twig, array(), 'bottom', null, __DIR__.'/../..');
63+
64+
try {
65+
$response = $controller->openAction(Request::create('/_wdt/open', Request::METHOD_GET, array('file' => $path)));
66+
$this->assertEquals(200, $response->getStatusCode());
67+
$this->assertTrue($isAllowed);
68+
} catch (NotFoundHttpException $e) {
69+
$this->assertFalse($isAllowed);
70+
}
71+
}
72+
73+
public function getOpenFileCases()
74+
{
75+
return array(
76+
array('README.md', true),
77+
array('composer.json', true),
78+
array('Controller/ProfilerController.php', true),
79+
array('.gitignore', false),
80+
array('../TwigBundle/README.md', false),
81+
array('Controller/../README.md', false),
82+
array('Controller/./ProfilerController.php', false),
83+
);
84+
}
85+
4986
/**
5087
* @dataProvider provideCspVariants
5188
*/

0 commit comments

Comments
 (0)