fix: 修复正常网页访问被误判为可疑请求的问题

- 排除正常的应用路径(/api/admin/, /api/, /chat/, /gallery/, /settings/等)
- 避免正常的网页访问被标记为可疑请求
- 只对真正可疑的路径(如/.env, /wp-admin等)进行标记
This commit is contained in:
Your Name 2025-12-29 16:28:17 +08:00
parent 1f213bb92d
commit a9236cdc3b

View File

@ -42,6 +42,23 @@ export function isSuspiciousRequest(request: Request): {
const pathname = url.pathname; const pathname = url.pathname;
const method = request.method; const method = request.method;
// 排除正常的应用路径(避免误报)
const allowedPaths = [
"/api/admin/", // 管理后台API(正常功能)
"/api/", // 所有API路径(正常功能)
"/chat/", // 聊天页面
"/gallery/", // 相册页面
"/settings/", // 设置页面
"/login", // 登录页面
"/register", // 注册页面
];
// 如果是正常的应用路径,不标记为可疑
const isAllowedPath = allowedPaths.some(allowed => pathname.startsWith(allowed));
if (isAllowedPath) {
return { suspicious: false };
}
// 检查可疑路径 // 检查可疑路径
for (const pattern of SUSPICIOUS_PATHS) { for (const pattern of SUSPICIOUS_PATHS) {
if (pathname.includes(pattern)) { if (pathname.includes(pattern)) {
@ -120,3 +137,4 @@ export async function validateRequestBody(