mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Reject file paths containing ..
.
Paths containing `..` are generally up to no good. Throw an exception, as developers can use realpath() if they really need to get relative paths. Fixes #3370
This commit is contained in:
parent
2333c3d535
commit
6f68049bf5
2 changed files with 18 additions and 0 deletions
|
@ -1259,6 +1259,13 @@ class CakeResponse {
|
||||||
'download' => null
|
'download' => null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (strpos($path, '..') !== false) {
|
||||||
|
throw new NotFoundException(__d(
|
||||||
|
'cake_dev',
|
||||||
|
'The requested file contains `..` and will not be read.'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_file($path)) {
|
if (!is_file($path)) {
|
||||||
$path = APP . $path;
|
$path = APP . $path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1075,6 +1075,17 @@ class CakeResponseTest extends CakeTestCase {
|
||||||
$response->file('/some/missing/folder/file.jpg');
|
$response->file('/some/missing/folder/file.jpg');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test file with ..
|
||||||
|
*
|
||||||
|
* @expectedException NotFoundException
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFileWithPathTraversal() {
|
||||||
|
$response = new CakeResponse();
|
||||||
|
$response->file('my/../cat.gif');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testFile method
|
* testFile method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue