From 0d5ed009d7c085327dd52ae58de16bcfe6091aea Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 7 Nov 2024 12:08:05 -0800 Subject: [PATCH] chore: disable remote debugger by default (#17498) --- lib/config.ts | 12 +++++++++++- lib/utils/ofetch.ts | 2 +- lib/utils/request-rewriter/fetch.test.ts | 1 + lib/utils/request-rewriter/fetch.ts | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 1784e1f97f2fc8..86637e3dc38473 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -5,12 +5,14 @@ import { ofetch } from 'ofetch'; let envs = process.env; export type Config = { + // app config disallowRobot: boolean; enableCluster?: string; isPackage: boolean; nodeName?: string; puppeteerWSEndpoint?: string; chromiumExecutablePath?: string; + // network connect: { port: number; }; @@ -20,6 +22,7 @@ export type Config = { ua: string; trueUA: string; allowOrigin?: string; + // cache cache: { type: string; requestTimeout: number; @@ -32,6 +35,7 @@ export type Config = { redis: { url: string; }; + // proxy proxyUri?: string; proxy: { protocol?: string; @@ -43,7 +47,9 @@ export type Config = { }; pacUri?: string; pacScript?: string; + // access control accessKey?: string; + // logging debugInfo: string; loggerLevel: string; noLogfiles?: boolean; @@ -56,6 +62,8 @@ export type Config = { dsn?: string; routeTimeout: number; }; + enableRemoteDebugging?: boolean; + // feed config hotlink: { template?: string; includePaths?: string[]; @@ -78,6 +86,8 @@ export type Config = { promptTitle: string; promptDescription: string; }; + + // Route-specific Configurations bilibili: { cookies: Record; dmImgList?: string; @@ -426,7 +436,6 @@ const calculateValue = () => { requestTimeout: toInt(envs.REQUEST_TIMEOUT, 30000), // Milliseconds to wait for the server to end the response before aborting the request ua: envs.UA ?? (toBoolean(envs.NO_RANDOM_UA, false) ? TRUE_UA : randUserAgent({ browser: 'chrome', os: 'mac os', device: 'desktop' })), trueUA: TRUE_UA, - // cors request allowOrigin: envs.ALLOW_ORIGIN, // cache cache: { @@ -470,6 +479,7 @@ const calculateValue = () => { dsn: envs.SENTRY, routeTimeout: toInt(envs.SENTRY_ROUTE_TIMEOUT, 30000), }, + enableRemoteDebugging: toBoolean(envs.ENABLE_REMOTE_DEBUGGING, false), // feed config hotlink: { template: envs.HOTLINK_TEMPLATE, diff --git a/lib/utils/ofetch.ts b/lib/utils/ofetch.ts index 2a66a6f8cddca6..bb344318369862 100644 --- a/lib/utils/ofetch.ts +++ b/lib/utils/ofetch.ts @@ -3,7 +3,7 @@ import { config } from '@/config'; import logger from '@/utils/logger'; import { register } from 'node-network-devtools'; -process.env.NODE_ENV === 'dev' && register(); +config.enableRemoteDebugging && process.env.NODE_ENV === 'dev' && register(); const rofetch = createFetch().create({ retryStatusCodes: [400, 408, 409, 425, 429, 500, 502, 503, 504], diff --git a/lib/utils/request-rewriter/fetch.test.ts b/lib/utils/request-rewriter/fetch.test.ts index ccb4e448c0d026..e8de9773bc1332 100644 --- a/lib/utils/request-rewriter/fetch.test.ts +++ b/lib/utils/request-rewriter/fetch.test.ts @@ -25,6 +25,7 @@ describe('useCustomHeader', () => { beforeEach(() => { originalEnv = process.env.NODE_ENV || Env.test; + process.env.ENABLE_REMOTE_DEBUGGING = 'true'; }); afterEach(() => { diff --git a/lib/utils/request-rewriter/fetch.ts b/lib/utils/request-rewriter/fetch.ts index 9985701100d0d2..a04d6a0607a7eb 100644 --- a/lib/utils/request-rewriter/fetch.ts +++ b/lib/utils/request-rewriter/fetch.ts @@ -12,7 +12,7 @@ const limiter = new RateLimiterMemory({ }); const limiterQueue = new RateLimiterQueue(limiter, { - maxQueueSize: 5000, + maxQueueSize: 4800, }); export const useCustomHeader = (headers: Headers) => { @@ -57,7 +57,7 @@ const wrappedFetch: typeof undici.fetch = async (input: RequestInfo, init?: Requ request.headers.delete('x-prefer-proxy'); } - useCustomHeader(request.headers); + config.enableRemoteDebugging && useCustomHeader(request.headers); // proxy if (!init?.dispatcher && proxy.dispatcher && (proxy.proxyObj.strategy !== 'on_retry' || isRetry)) {