Skip to content

Commit c13ca94

Browse files
Merge branch '3.4'
* 3.4: fixed CS fixed CS [Security] Namespace generated CSRF tokens depending of the current scheme ensure that submitted data are uploaded files [Console] remove dead code bumped Symfony version to 3.3.13 updated VERSION for 3.3.12 updated CHANGELOG for 3.3.12 bumped Symfony version to 2.8.31 updated VERSION for 2.8.30 updated CHANGELOG for 2.8.30 bumped Symfony version to 2.7.38 updated VERSION for 2.7.37 updated CHANGELOG for 2.7.37 [Security] Validate redirect targets using the session cookie domain prevent bundle readers from breaking out of paths
2 parents f3d0f0e + 2d4d349 commit c13ca94

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

Data/Bundle/Reader/JsonBundleReader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public function read($path, $locale)
3030
{
3131
$fileName = $path.'/'.$locale.'.json';
3232

33+
// prevent directory traversal attacks
34+
if (dirname($fileName) !== $path) {
35+
throw new ResourceBundleNotFoundException(sprintf('The resource bundle "%s" does not exist.', $fileName));
36+
}
37+
3338
if (!file_exists($fileName)) {
3439
throw new ResourceBundleNotFoundException(sprintf(
3540
'The resource bundle "%s" does not exist.',

Data/Bundle/Reader/PhpBundleReader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public function read($path, $locale)
3030
{
3131
$fileName = $path.'/'.$locale.'.php';
3232

33+
// prevent directory traversal attacks
34+
if (dirname($fileName) !== $path) {
35+
throw new ResourceBundleNotFoundException(sprintf('The resource bundle "%s" does not exist.', $fileName));
36+
}
37+
3338
if (!file_exists($fileName)) {
3439
throw new ResourceBundleNotFoundException(sprintf(
3540
'The resource bundle "%s/%s.php" does not exist.',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Foo":"Bar"}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
return array(
13+
'Foo' => 'Bar',
14+
);

Tests/Data/Bundle/Reader/JsonBundleReaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,12 @@ public function testReadFailsIfInvalidJson()
6969
{
7070
$this->reader->read(__DIR__.'/Fixtures/json', 'en_Invalid');
7171
}
72+
73+
/**
74+
* @expectedException \Symfony\Component\Intl\Exception\ResourceBundleNotFoundException
75+
*/
76+
public function testReaderDoesNotBreakOutOfGivenPath()
77+
{
78+
$this->reader->read(__DIR__.'/Fixtures/json', '../invalid_directory/en');
79+
}
7280
}

Tests/Data/Bundle/Reader/PhpBundleReaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,12 @@ public function testReadFailsIfNotAFile()
6161
{
6262
$this->reader->read(__DIR__.'/Fixtures/NotAFile', 'en');
6363
}
64+
65+
/**
66+
* @expectedException \Symfony\Component\Intl\Exception\ResourceBundleNotFoundException
67+
*/
68+
public function testReaderDoesNotBreakOutOfGivenPath()
69+
{
70+
$this->reader->read(__DIR__.'/Fixtures/php', '../invalid_directory/en');
71+
}
6472
}

0 commit comments

Comments
 (0)