mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-28 03:51:21 +08:00
feat: 安全性提升
This commit is contained in:
parent
f4412bb086
commit
e4c1807f76
@ -10,7 +10,7 @@ import { isEmpty } from '@webapi/utils/check';
|
||||
// 检查是否使用默认Token
|
||||
export const CheckDefaultTokenHandler: RequestHandler = async (_, res) => {
|
||||
const webuiToken = await WebUiConfig.GetWebUIConfig();
|
||||
if (webuiToken.token.startsWith('napcat')) {
|
||||
if (webuiToken.defaultToken) {
|
||||
return sendSuccess(res, true);
|
||||
}
|
||||
return sendSuccess(res, false);
|
||||
|
||||
@ -65,6 +65,10 @@ const checkSameTypeExists = async (pathToCheck: string, isDirectory: boolean): P
|
||||
|
||||
// 获取目录内容
|
||||
export const ListFilesHandler: RequestHandler = async (req, res) => {
|
||||
const webuiToken = await WebUiConfig.GetWebUIConfig();
|
||||
if (webuiToken.defaultToken) {
|
||||
return sendError(res, '默认密码禁止使用');
|
||||
}
|
||||
try {
|
||||
const requestPath = (req.query['path'] as string) || (isWindows ? 'C:\\' : '/');
|
||||
const normalizedPath = normalizePath(requestPath);
|
||||
|
||||
@ -47,7 +47,7 @@ export const CreateTerminalHandler: RequestHandler = async (req, res) => {
|
||||
if (isMacOS) {
|
||||
return sendError(res, 'MacOS不支持终端');
|
||||
}
|
||||
if ((await WebUiConfig.GetWebUIConfig()).token.startsWith('napcat')) {
|
||||
if ((await WebUiConfig.GetWebUIConfig()).defaultToken) {
|
||||
return sendError(res, '该密码禁止创建终端');
|
||||
}
|
||||
try {
|
||||
|
||||
@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import { loadConfig, OneBotConfig } from '@/onebot/config/config';
|
||||
import { webUiPathWrapper } from '@/webui';
|
||||
import { WebUiConfig, webUiPathWrapper } from '@/webui';
|
||||
import { WebUiDataRuntime } from '@webapi/helper/Data';
|
||||
import { sendError, sendSuccess } from '@webapi/utils/response';
|
||||
import { isEmpty } from '@webapi/utils/check';
|
||||
@ -47,6 +47,10 @@ export const OB11SetConfigHandler: RequestHandler = async (req, res) => {
|
||||
if (isEmpty(req.body.config)) {
|
||||
return sendError(res, 'config is empty');
|
||||
}
|
||||
const webuiToken = await WebUiConfig.GetWebUIConfig();
|
||||
if (webuiToken.defaultToken) {
|
||||
return sendError(res, '默认密码禁止写入配置');
|
||||
}
|
||||
// 写入配置
|
||||
try {
|
||||
// 解析并加载配置
|
||||
|
||||
@ -18,6 +18,7 @@ const WebUiConfigSchema = Type.Object({
|
||||
loginRate: Type.Number({ default: 10 }),
|
||||
autoLoginAccount: Type.String({ default: '' }),
|
||||
theme: themeType,
|
||||
defaultToken: Type.Boolean({ default: true }),
|
||||
});
|
||||
|
||||
export type WebUiConfigType = Static<typeof WebUiConfigSchema>;
|
||||
@ -88,7 +89,7 @@ export class WebUiConfigWrapper {
|
||||
if (currentConfig.token !== oldToken) {
|
||||
throw new Error('旧 token 不匹配');
|
||||
}
|
||||
await this.UpdateWebUIConfig({ token: newToken });
|
||||
await this.UpdateWebUIConfig({ token: newToken, defaultToken: false });
|
||||
}
|
||||
|
||||
// 获取日志文件夹路径
|
||||
|
||||
Loading…
Reference in New Issue
Block a user