From fbd34b3d148b7fcb919517a484291b93f3a74f18 Mon Sep 17 00:00:00 2001 From: Canglan Date: Sat, 10 Oct 2026 15:55:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=B8=8E=E7=8F=AD=E4=B8=BB=E4=BB=BB=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit upgrade.php 原来无任何校验,任何人可访问执行;现要求登录且拥有系统升级权限(manage_upgrade,默认仅班主任): 页面未授权跳登录页,POST 请求未授权返回 403 JSON。 --- upgrade.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/upgrade.php b/upgrade.php index 5c3da63..812b8e9 100644 --- a/upgrade.php +++ b/upgrade.php @@ -4,8 +4,26 @@ * * 读取 VERSION 文件确定目标版本,自动检测数据库当前版本, * 依次执行增量 SQL 升级脚本。 + * + * 仅限班主任(拥有系统升级权限 manage_upgrade)使用。 */ +// 登录与权限校验:仅班主任(系统升级权限)可访问与执行 +require_once __DIR__ . '/frontend/config.php'; + +if (!isset($_SESSION['user_id']) + || ($_SESSION['user_type'] ?? '') !== 'admin' + || !has_perm('manage_upgrade')) { + if ($_SERVER['REQUEST_METHOD'] === 'POST' || isset($_GET['action'])) { + header('Content-Type: application/json; charset=utf-8'); + http_response_code(403); + echo json_encode(['success' => false, 'error' => '未授权:仅班主任(系统升级权限)可执行升级操作']); + exit(); + } + header('Location: /index.php'); + exit(); +} + // =========================================== // 辅助函数 // ===========================================