From 404434bb6c1aab2905d398055048cf57ad81fbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Mon, 19 Oct 2026 09:35:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=AE=89=E5=85=A8):=20=E9=99=90=E5=88=B6?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E4=B8=8E=E5=AD=98=E5=82=A8=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E8=AF=B7=E6=B1=82=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 背景与目的:方法覆盖可使非 POST 请求进入原有写入分支,需要与已升级组件的表单令牌防护共同约束后台写操作。 主要改动:两个接口按 ThinkPHP 解析后的方法仅允许 GET 和 POST,其余方法返回 HTTP 405 与 Allow 响应头,覆盖表单及请求头方法覆盖。 影响范围与兼容性:保留 GET 表单、合法 POST、令牌字段及请求头兼容;存储配置继续优先执行演示环境拦截,不调整权限和成功响应。 验证入口及实际结果:在临时应用中复用 check-form-token.php,加载本项目控制器与已安装依赖,以内存会话和 SQLite 验证,178/178 通过;PHP 语法与差异检查通过。未进行浏览器或真实服务验收。 --- app/admin/controller/Config.php | 4 ++++ app/admin/controller/User.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/admin/controller/Config.php b/app/admin/controller/Config.php index c7b100203..28a122145 100644 --- a/app/admin/controller/Config.php +++ b/app/admin/controller/Config.php @@ -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'); diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index d8d62e251..d4f3dc782 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -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;