From 52b6627ebdab3e4eacc33409e2e697b4f5822d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 2 Feb 2026 16:17:03 +0800 Subject: [PATCH] Validate pluginId and use localStorage token Return a 400 error when the /call-plugin/:pluginId route is requested without a pluginId to avoid calling getPluginExports with an undefined id (packages/napcat-plugin-builtin/index.ts). Update the dashboard UI to read the auth token from localStorage (same-origin) instead of relying on a URL parameter; a comment about legacy webui_token in the URL was added while the implementation currently prefers localStorage.getItem('token') (packages/napcat-plugin-builtin/webui/dashboard.html). --- packages/napcat-plugin-builtin/index.ts | 8 ++++++++ packages/napcat-plugin-builtin/webui/dashboard.html | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/napcat-plugin-builtin/index.ts b/packages/napcat-plugin-builtin/index.ts index 9c0c9b7c..701fd1c9 100644 --- a/packages/napcat-plugin-builtin/index.ts +++ b/packages/napcat-plugin-builtin/index.ts @@ -134,6 +134,14 @@ const plugin_init: PluginModule['plugin_init'] = async (ctx) => { ctx.router.get('/call-plugin/:pluginId', (req, res) => { const { pluginId } = req.params; + if (!pluginId) { + res.status(400).json({ + code: -1, + message: 'Plugin ID is required' + }); + return; + } + // 使用 getPluginExports 获取其他插件的导出模块 const targetPlugin = ctx.getPluginExports(pluginId); diff --git a/packages/napcat-plugin-builtin/webui/dashboard.html b/packages/napcat-plugin-builtin/webui/dashboard.html index b0a3f2b2..aa39dbf8 100644 --- a/packages/napcat-plugin-builtin/webui/dashboard.html +++ b/packages/napcat-plugin-builtin/webui/dashboard.html @@ -279,9 +279,10 @@