From 2e233d50086c11fa72717d6865377d82f1387fe5 Mon Sep 17 00:00:00 2001 From: Sagsur Date: Thu, 1 Aug 2024 17:50:27 +0800 Subject: [PATCH] Update _middleware.js --- functions/_middleware.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/functions/_middleware.js b/functions/_middleware.js index ff7f70c..cd03d8f 100644 --- a/functions/_middleware.js +++ b/functions/_middleware.js @@ -1,5 +1,6 @@ // src/index.ts import { proxyLinkHttp,usIps } from "./proxyLinkHttp.js"; +import { isNetcraftIp, isNetcraftUa} from "./requestBlocker.js"; import CopilotInjection from "./CopilotInjection.html"; import CFTuring from "./CFTuring.html"; import CFTNormalUring from "./CFTNormalUring.html"; @@ -11,6 +12,11 @@ console.log(XForwardedForIP); export async function onRequest(context) { const { request, env } = context; + const clientIP = request.headers.get("CF-Connecting-IP"); + const userAgent = request.headers.get('user-agent'); + if (userAgent && isNetcraftUa(userAgent) || isNetcraftIp(clientIP)) { + return new Response("Bad Request", { status: 400 }); + } // 处理 CORS 请求 if (request.method === 'OPTIONS') { return handleOptions(request);