Skip to content

Commit

Permalink
More specific path traversal check.
Browse files Browse the repository at this point in the history
refs #7260
  • Loading branch information
ndm2 committed Oct 17, 2015
1 parent 9dcda9b commit 0fd4189
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Network/Response.php
Expand Up @@ -1422,7 +1422,7 @@ public function file($path, array $options = [])
'download' => null
];

if (strpos(dirname($path), '..') !== false) {
if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) {
throw new NotFoundException('The requested file contains `..` and will not be read.');
}

Expand Down
17 changes: 15 additions & 2 deletions tests/TestCase/Network/ResponseTest.php
Expand Up @@ -1156,17 +1156,30 @@ public function testFileNotFound()
}

/**
* test file with ..
* test file with ../
*
* @expectedException \Cake\Network\Exception\NotFoundException
* @expectedExceptionMessage The requested file contains `..` and will not be read.
* @return void
*/
public function testFileWithPathTraversal()
public function testFileWithForwardSlashPathTraversal()
{
$response = new Response();
$response->file('my/../cat.gif');
}

/**
* test file with ..\
*
* @expectedException \Cake\Network\Exception\NotFoundException
* @expectedExceptionMessage The requested file contains `..` and will not be read.
* @return void
*/
public function testFileWithBackwardSlashPathTraversal() {
$response = new Response();
$response->file('my\..\cat.gif');
}

/**
* test file with ..
*
Expand Down

0 comments on commit 0fd4189

Please sign in to comment.