diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index b2890b7f1..26bfb83be 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -1336,7 +1336,7 @@ class CakeResponse { 'download' => null ); - if (strpos($path, '..') !== false) { + if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) { throw new NotFoundException(__d( 'cake_dev', 'The requested file contains `..` and will not be read.' diff --git a/lib/Cake/Test/Case/Network/CakeResponseTest.php b/lib/Cake/Test/Case/Network/CakeResponseTest.php index 801f08664..a811b89e5 100644 --- a/lib/Cake/Test/Case/Network/CakeResponseTest.php +++ b/lib/Cake/Test/Case/Network/CakeResponseTest.php @@ -1170,6 +1170,7 @@ class CakeResponseTest extends CakeTestCase { * test file with .. * * @expectedException NotFoundException + * @expectedExceptionMessage The requested file contains `..` and will not be read. * @return void */ public function testFileWithPathTraversal() { @@ -1177,6 +1178,19 @@ class CakeResponseTest extends CakeTestCase { $response->file('my/../cat.gif'); } +/** + * Although unlikely, a file may contain dots in its filename. + * This should be allowed, as long as the dots doesn't specify a path (../ or ..\) + * + * @expectedException NotFoundException + * @execptedExceptionMessageRegExp #The requested file .+my/Some..cat.gif was not found or not readable# + * @return void + */ + public function testFileWithDotsInFilename() { + $response = new CakeResponse(); + $response->file('my/Some..cat.gif'); + } + /** * testFile method *