fix: 修复高危接口访问与会话安全问题
This commit is contained in:
1 parent
ca4a5f4e4e
commit
8523e7142c
12 files changed
+161
-36
No files matched your search
@@ -4,14 +4,14 @@ declare (strict_types = 1);
|
||||
namespace app\tools\controller;
|
||||
|
||||
// 引用控制器基类
|
||||
use app\BaseController;
|
||||
use app\AdminToolsBase;
|
||||
|
||||
// 引用PhpSpreadsheet类
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
class File extends BaseController
|
||||
class File extends AdminToolsBase
|
||||
{
|
||||
/**
|
||||
* 获取文件信息并保存
|
||||
@@ -28,6 +28,26 @@ class File extends BaseController
|
||||
*/
|
||||
public function saveFileInfo($file, $list = array(), $isSave = false)
|
||||
{
|
||||
if ($file === null || !$file->isValid()) {
|
||||
return ['msg' => '上传文件无效', 'val' => 0];
|
||||
}
|
||||
|
||||
$extension = strtolower($file->getOriginalExtension());
|
||||
$allowedExtensions = ['jpg', 'jpeg', 'png', 'xls', 'xlsx'];
|
||||
if (!in_array($extension, $allowedExtensions, true)) {
|
||||
return ['msg' => '文件格式必须为 jpg、jpeg、png、xls 或 xlsx', 'val' => 0];
|
||||
}
|
||||
|
||||
if ($file->getSize() > 10 * 1024 * 1024) {
|
||||
return ['msg' => '文件不能超过 10MiB', 'val' => 0];
|
||||
}
|
||||
|
||||
$directory = trim((string) ($list['serurl'] ?? ''), '/\\');
|
||||
if ($directory === '' || !preg_match('/^[A-Za-z0-9][A-Za-z0-9_\\/-]{0,99}$/', $directory)) {
|
||||
return ['msg' => '上传目录不合法', 'val' => 0];
|
||||
}
|
||||
$list['serurl'] = $directory;
|
||||
|
||||
$hash = $file->hash('sha1');
|
||||
$f = new \app\system\model\Fields;
|
||||
$serFile = $f::where('hash', $hash)->find();
|
||||
|
||||
Reference in new issue
Block a user