mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fix path traversal check for Windows based systems
On Windows based systems, both, backward as well as forward
slashes are supported as path separators, thus checking for `DS`
only, would allow to slip in `../` fragments.
refs #5905, cad57dcc28
This commit is contained in:
parent
daa795dfd3
commit
8fe953548c
2 changed files with 15 additions and 3 deletions
|
@ -1337,7 +1337,7 @@ class CakeResponse {
|
||||||
'download' => null
|
'download' => null
|
||||||
);
|
);
|
||||||
|
|
||||||
if (strpos($path, '..' . DS) !== false) {
|
if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) {
|
||||||
throw new NotFoundException(__d(
|
throw new NotFoundException(__d(
|
||||||
'cake_dev',
|
'cake_dev',
|
||||||
'The requested file contains `..` and will not be read.'
|
'The requested file contains `..` and will not be read.'
|
||||||
|
|
|
@ -1167,17 +1167,29 @@ class CakeResponseTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test file with ..
|
* test file with ../
|
||||||
*
|
*
|
||||||
* @expectedException NotFoundException
|
* @expectedException NotFoundException
|
||||||
* @expectedExceptionMessage The requested file contains `..` and will not be read.
|
* @expectedExceptionMessage The requested file contains `..` and will not be read.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testFileWithPathTraversal() {
|
public function testFileWithForwardSlashPathTraversal() {
|
||||||
$response = new CakeResponse();
|
$response = new CakeResponse();
|
||||||
$response->file('my/../cat.gif');
|
$response->file('my/../cat.gif');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test file with ..\
|
||||||
|
*
|
||||||
|
* @expectedException NotFoundException
|
||||||
|
* @expectedExceptionMessage The requested file contains `..` and will not be read.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFileWithBackwardSlashPathTraversal() {
|
||||||
|
$response = new CakeResponse();
|
||||||
|
$response->file('my\..\cat.gif');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Although unlikely, a file may contain dots in its filename.
|
* 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 ..\)
|
* This should be allowed, as long as the dots doesn't specify a path (../ or ..\)
|
||||||
|
|
Loading…
Add table
Reference in a new issue