fix: 修复高危接口访问与会话安全问题

This commit is contained in:
biss committed 2026-10-04 17:35:13 +08:00
1 parent ca4a5f4e4e
commit 8523e7142c
12 files changed
+161 -36

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
<?php
namespace app;
/**
* Shared base controller for utility endpoints that must never be exposed to
* student or anonymous sessions.
*/
abstract class AdminToolsBase extends ToolsBase
{
protected $middleware = [
'online',
'login',
'admin_only',
];
}
+2 -1
View File
@@ -14,6 +14,7 @@ abstract class ToolsBase extends BaseController
* @var array
*/
protected $middleware = [
'online'
'online',
'login',
];
}
+33 -2
View File
@@ -28,7 +28,11 @@ class YanZheng
session('onlineCategory', 'admin');
session('user_id', $userinfo->id);
session('username', $username);
session('password', $password);
// Never retain the clear-text password in the session. The stored
// password hash also makes a session invalid as soon as the user
// changes their password.
session('auth_hash', $userinfo->password);
session('password', null);
// 跳转到首页
$data = ['msg' => '验证成功', 'val' => 1, 'url' =>'/'];
} else {
@@ -64,7 +68,8 @@ class YanZheng
session('onlineCategory', 'student');
session('user_id', $userinfo->id);
session('username', $username);
session('password', $password);
session('auth_hash', $userinfo->password);
session('password', null);
// 跳转到首页
$data = ['msg' => '验证成功', 'val' => 1, 'url' =>'\\studentSearchChengji\\index\\index'];
} else {
@@ -75,4 +80,30 @@ class YanZheng
return $data;
}
/**
* Validate an existing login without needing to keep its clear-text
* password in session storage.
*/
public static function validateSession(string $category, int $userId, ?string $authHash): bool
{
if ($userId <= 0 || empty($authHash)) {
return false;
}
$model = $category === 'admin'
? \app\admin\model\Admin::class
: ($category === 'student' ? \app\student\model\Student::class : null);
if ($model === null) {
return false;
}
$user = $model::where('id', $userId)
->where('status', 1)
->field('password')
->find();
return $user !== null && hash_equals((string) $user->password, $authHash);
}
}
Loaded 3 of 12 files, more files were not shown because too many files have changed in this diff. Show more