fix: 修复高危接口访问与会话安全问题
This commit is contained in:
1 parent
ca4a5f4e4e
commit
8523e7142c
12 files changed
+161
-36
No files matched your search
@@ -4,12 +4,13 @@ declare (strict_types = 1);
|
||||
namespace app\tools\controller;
|
||||
|
||||
// 引用控制器基类
|
||||
use app\BaseController;
|
||||
use app\ToolsBase;
|
||||
use think\exception\HttpException;
|
||||
// 引用学生数据模型类
|
||||
use \app\tools\model\OneStudentChengji as STUCJ;
|
||||
|
||||
|
||||
class OneStudentChengji extends BaseController
|
||||
class OneStudentChengji extends ToolsBase
|
||||
{
|
||||
// 获取学生历次考试所有学科成绩
|
||||
public function ajaxOldChengji()
|
||||
@@ -29,6 +30,8 @@ class OneStudentChengji extends BaseController
|
||||
,'searchval' => ''
|
||||
], 'POST');
|
||||
|
||||
$this->assertStudentAccess((int) $src['student_id']);
|
||||
|
||||
// 获取学生成绩
|
||||
$stucj = new STUCJ;
|
||||
$khList = $stucj->oldList($src);
|
||||
@@ -47,6 +50,8 @@ class OneStudentChengji extends BaseController
|
||||
'kaohao_id' => '',
|
||||
], 'POST');
|
||||
|
||||
$this->assertKaohaoAccess((int) $src['kaohao_id']);
|
||||
|
||||
// 获取学生成绩
|
||||
$stucj = new STUCJ;
|
||||
$data = $stucj->leiDa($src);
|
||||
@@ -64,6 +69,8 @@ class OneStudentChengji extends BaseController
|
||||
'kaohao_id' => '',
|
||||
], 'POST');
|
||||
|
||||
$this->assertKaohaoAccess((int) $src['kaohao_id']);
|
||||
|
||||
// 获取学生成绩
|
||||
$stucj = new STUCJ;
|
||||
$data = $stucj->yiBiao($src);
|
||||
@@ -81,6 +88,8 @@ class OneStudentChengji extends BaseController
|
||||
'kaohao_id' => '',
|
||||
], 'POST');
|
||||
|
||||
$this->assertKaohaoAccess((int) $src['kaohao_id']);
|
||||
|
||||
// 获取学生成绩
|
||||
$stucj = new STUCJ;
|
||||
$data = $stucj->oneChengji($src);
|
||||
@@ -99,6 +108,8 @@ class OneStudentChengji extends BaseController
|
||||
'kaohao_id' => '',
|
||||
], 'POST');
|
||||
|
||||
$this->assertKaohaoAccess((int) $src['kaohao_id']);
|
||||
|
||||
// 获取学生成绩
|
||||
$stucj = new STUCJ;
|
||||
$data = $stucj->oneDeFenLv($src);
|
||||
@@ -116,6 +127,8 @@ class OneStudentChengji extends BaseController
|
||||
'kaohao_id' => '',
|
||||
], 'POST');
|
||||
|
||||
$this->assertKaohaoAccess((int) $src['kaohao_id']);
|
||||
|
||||
// 获取学生成绩
|
||||
$stucj = new STUCJ;
|
||||
$data = $stucj->oneSubjectWeiZhi($src);
|
||||
@@ -139,6 +152,8 @@ class OneStudentChengji extends BaseController
|
||||
,'searchval' => ''
|
||||
], 'POST');
|
||||
|
||||
$this->assertStudentAccess((int) $src['student_id']);
|
||||
|
||||
$stucj = new STUCJ;
|
||||
$data = $stucj->subjectOldChengji($src);
|
||||
return json($data);
|
||||
@@ -154,6 +169,8 @@ class OneStudentChengji extends BaseController
|
||||
'kaohao_id' => ''
|
||||
], 'POST');
|
||||
|
||||
$this->assertKaohaoAccess((int) $src['kaohao_id']);
|
||||
|
||||
$stucj = new STUCJ;
|
||||
$baogao = $stucj->baogao($src);
|
||||
$data = [
|
||||
@@ -165,4 +182,29 @@ class OneStudentChengji extends BaseController
|
||||
return json($data);
|
||||
}
|
||||
|
||||
private function assertStudentAccess(int $studentId): void
|
||||
{
|
||||
if ($studentId <= 0) {
|
||||
throw new HttpException(422, '学生参数无效');
|
||||
}
|
||||
|
||||
if (session('onlineCategory') === 'student' && $studentId !== (int) session('user_id')) {
|
||||
throw new HttpException(403, '无权访问其他学生的成绩');
|
||||
}
|
||||
}
|
||||
|
||||
private function assertKaohaoAccess(int $kaohaoId): void
|
||||
{
|
||||
if ($kaohaoId <= 0) {
|
||||
throw new HttpException(422, '考号参数无效');
|
||||
}
|
||||
|
||||
$studentId = (int) \app\kaohao\model\Kaohao::where('id', $kaohaoId)->value('student_id');
|
||||
if ($studentId <= 0) {
|
||||
throw new HttpException(404, '成绩记录不存在');
|
||||
}
|
||||
|
||||
$this->assertStudentAccess($studentId);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user