From e52531894e2e462f2b5b8dcd8b9c12fe680e8a0b Mon Sep 17 00:00:00 2001 From: DevServer Operations Date: Sun, 29 Nov 2026 12:13:43 +0800 Subject: [PATCH] Account for rejected admin forms and the dedicated HN admin host --- .../V1/Passport/AuthController.php | 2 ++ app/Http/Requests/Passport/AuthLogin.php | 6 +++++ app/Support/XbAdminLogin.php | 22 +++++++++++++++---- docs/maintenance/README.md | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/V1/Passport/AuthController.php b/app/Http/Controllers/V1/Passport/AuthController.php index 0c5809ea..c7e40f1e 100644 --- a/app/Http/Controllers/V1/Passport/AuthController.php +++ b/app/Http/Controllers/V1/Passport/AuthController.php @@ -105,6 +105,7 @@ class AuthController extends Controller $userId = $this->mailLinkService->handleTokenLogin($verify); if (!$userId) { + \App\Support\XbAdminLogin::rejected($request); return response()->json([ 'message' => __('Token error') ], 400); @@ -113,6 +114,7 @@ class AuthController extends Controller $user = \App\Models\User::find($userId); if (!$user) { + \App\Support\XbAdminLogin::rejected($request); return response()->json([ 'message' => __('User not found') ], 400); diff --git a/app/Http/Requests/Passport/AuthLogin.php b/app/Http/Requests/Passport/AuthLogin.php index 6aa832c2..4431dc71 100644 --- a/app/Http/Requests/Passport/AuthLogin.php +++ b/app/Http/Requests/Passport/AuthLogin.php @@ -19,6 +19,12 @@ class AuthLogin extends FormRequest ]; } + protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator) + { + \App\Support\XbAdminLogin::rejected($this, $this->input('email')); + parent::failedValidation($validator); + } + public function messages() { return [ diff --git a/app/Support/XbAdminLogin.php b/app/Support/XbAdminLogin.php index efcb6980..463c846d 100644 --- a/app/Support/XbAdminLogin.php +++ b/app/Support/XbAdminLogin.php @@ -12,10 +12,11 @@ final class XbAdminLogin { private static function begin(Request $request, $user) { - if (!$user || !$user->is_admin) { + $profile = $request->server->get('XB_INSTANCE') ?? config('site.profile'); + $adminHost = $profile === 'hn' && strtolower(explode(':', (string) $request->server->get('HTTP_HOST'))[0]) === 'admin.hardnerd.net'; + if ($user ? !$user->is_admin : !$adminHost) { return null; } - $profile = $request->server->get('XB_INSTANCE') ?? config('site.profile'); $instances = ['dpl' => 'xb-dpl', 'hn' => 'xb-hn', 'fuc-xb-test' => 'xb-fuc']; $instance = $instances[$profile] ?? null; if (!$instance || (!app()->environment('production') && !is_dir('/run/web-admin-login-'.$instance))) { @@ -25,12 +26,25 @@ final class XbAdminLogin return Ticket::begin($instance, $request->server->all()); } - public static function password(Request $request, string $email, callable $verify, callable $issue): array + private static function account($email) { + if (!is_string($email) || $email === '' || strlen($email) > 254) { + return null; + } // Match the account lookup used by this backend, including older releases. $query = method_exists(User::class, 'scopeByEmail') || method_exists(User::class, 'byEmail') ? User::byEmail($email) : User::where('email', $email); - $candidate = $query->first(['id','is_admin']); + return $query->first(['id','is_admin']); + } + + public static function rejected(Request $request, $email = null): void + { + self::handle($request, self::account($email), fn () => [false, null], fn () => null); + } + + public static function password(Request $request, string $email, callable $verify, callable $issue): array + { + $candidate = self::account($email); return self::handle($request, $candidate, $verify, $issue); } diff --git a/docs/maintenance/README.md b/docs/maintenance/README.md index 8038d02f..9b5de4a8 100644 --- a/docs/maintenance/README.md +++ b/docs/maintenance/README.md @@ -30,4 +30,4 @@ ### Web 管理员登录保护 -DPL、HN 和福云按运行实例各自处理管理员密码登录及快捷登录。已验证的管理员快捷登录在生成登录凭据前检查来源 IP。会员的密码和快捷登录沿用原有认证及响应。共享表单中的无效快捷码无法归属到具体账号,按原有认证规则拒绝。管理员来源 IP 在滚动 24 小时内第 7 次失败后封禁 30 天,成功保留失败记录。每个实例向自己的 TeleHub 调用方提交结果、时间与可信来源 IP,目标为管理员私聊。 +DPL、HN 和福云按运行实例各自处理管理员密码登录及快捷登录。已验证的管理员快捷登录在生成登录凭据前检查来源 IP。会员的密码和快捷登录沿用原有认证及响应。HN 已登记的独立管理域名对未知账号或无效快捷码也计入后台失败。共享表单中的无效快捷码无法归属到具体账号,按原有认证规则拒绝。管理员来源 IP 在滚动 24 小时内第 7 次失败后封禁 30 天,成功保留失败记录。每个实例向自己的 TeleHub 调用方提交结果、时间与可信来源 IP,目标为管理员私聊。