Skip to content

Commit 77752bf

Browse files
committed
Fix possibility for spoofed files to pass validation.
Use `is_uploaded_file` to prevent crafty requests that contain bogus files from getting through.
1 parent 455db38 commit 77752bf

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Validation/Validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ public static function uploadedFile($file, array $options = [])
10291029
if (isset($options['types']) && !static::mimeType($file, $options['types'])) {
10301030
return false;
10311031
}
1032-
return true;
1032+
return is_uploaded_file($file['tmp_name']);
10331033
}
10341034

10351035
/**

tests/TestCase/Validation/ValidationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Cake\Validation\Validation;
2222
use Locale;
2323

24+
require_once __DIR__ . '/stubs.php';
25+
2426
/**
2527
* Test Case for Validation Class
2628
*

tests/TestCase/Validation/stubs.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 3.2.5
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
namespace Cake\Validation {
16+
/**
17+
* Use namespace injection to overwrite is_uploaded_file()
18+
* during tests.
19+
*
20+
* @param string $filename The file to check.
21+
* @return bool Whether or not the file exists.
22+
*/
23+
function is_uploaded_file($filename)
24+
{
25+
return file_exists($filename);
26+
}
27+
}
28+

0 commit comments

Comments
 (0)