fix(安全): 限制改密与存储配置接口的请求方法

背景与目的:方法覆盖可使非 POST 请求进入原有写入分支,需要与已升级组件的表单令牌防护共同约束后台写操作。

主要改动:两个接口按 ThinkPHP 解析后的方法仅允许 GET 和 POST,其余方法返回 HTTP 405 与 Allow 响应头,覆盖表单及请求头方法覆盖。

影响范围与兼容性:保留 GET 表单、合法 POST、令牌字段及请求头兼容;存储配置继续优先执行演示环境拦截,不调整权限和成功响应。

验证入口及实际结果:在临时应用中复用 check-form-token.php,加载本项目控制器与已安装依赖,以内存会话和 SQLite 验证,178/178 通过;PHP 语法与差异检查通过。未进行浏览器或真实服务验收。
This commit is contained in:
邹景立 2026-10-19 09:35:16 +08:00
parent e83db02808
commit 404434bb6c
2 changed files with 8 additions and 0 deletions

View File

@ -31,6 +31,7 @@ use think\admin\Storage;
use think\admin\storage\AliossStorage;
use think\admin\storage\QiniuStorage;
use think\admin\storage\TxcosStorage;
use think\exception\HttpException;
/**
* 系统参数配置.
@ -133,6 +134,9 @@ class Config extends Controller
if (!$this->request->isGet() && RuntimeService::check('demo')) {
$this->error('演示环境禁止修改系统配置!');
}
if (!in_array($this->request->method(), ['GET', 'POST'], true)) {
throw new HttpException(405, 'Method Not Allowed', null, ['Allow' => 'GET, POST']);
}
$this->_applyFormToken();
if ($this->request->isGet()) {
$this->type = input('type', 'local');

View File

@ -29,6 +29,7 @@ use think\admin\service\AdminService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\HttpException;
/**
* 系统用户管理.
@ -90,6 +91,9 @@ class User extends Controller
*/
public function pass()
{
if (!in_array($this->request->method(), ['GET', 'POST'], true)) {
throw new HttpException(405, 'Method Not Allowed', null, ['Allow' => 'GET, POST']);
}
$this->_applyFormToken();
if ($this->request->isGet()) {
$this->verify = false;