[ PROMPT_NODE_23996 ]
Bot Management API 参考
[ SKILL_DOCUMENTATION ]
# 智能体管理 API
## Workers: BotManagement 接口
typescript
interface BotManagement {
score: number; // 1-99 (企业版), 若未计算则为 0
verifiedBot: boolean; // 是否为已验证智能体
staticResource: boolean; // 是否为静态资源
ja3Hash: string; // JA3 指纹 (企业版, 仅限 HTTPS)
ja4: string; // JA4 指纹 (企业版, 仅限 HTTPS)
jsDetection?: {
passed: boolean; // 通过 JS 检测 (若已启用)
};
detectionIds: number[]; // 启发式检测 ID
corporateProxy?: boolean; // 来自企业代理 (企业版)
}
// 已弃用: 请改用 botManagement.score
// request.cf.clientTrustScore (旧版,与 botManagement.score 重复)
// 通过 request.cf 访问
import type { IncomingRequestCfProperties } from '@cloudflare/workers-types';
export default {
async fetch(request: Request): Promise {
const cf = request.cf as IncomingRequestCfProperties | undefined;
const botMgmt = cf?.botManagement;
if (!botMgmt) return fetch(request);
if (botMgmt.verifiedBot) return fetch(request); // 允许已验证智能体
if (botMgmt.score === 1) return new Response('Blocked', { status: 403 });
if (botMgmt.score < 30) return new Response('Challenge required', { status: 429 });
return fetch(request);
}
};
## WAF 字段参考
txt
# 评分字段
cf.bot_management.score # 0-99 (0 = 未计算)
cf.bot_management.verified_bot # 布尔值
cf.bot_management.static_resource # 布尔值
cf.bot_management.ja3_hash # 字符串 (企业版)
cf.bot_management.ja4 # 字符串 (企业版)
cf.bot_management.detection_ids # 数组
cf.bot_management.js_detection.passed # 布尔值
cf.bot_management.corporate_proxy # 布尔值 (企业版)
cf.verified_bot_category # 字符串
# Workers 等效项
request.cf.botManagement.score
request.cf.botManagement.verifiedBot
request.cf.botManagement.ja3Hash
request.cf.botManagement.ja4
request.cf.botManagement.jsDetection.passed
request.cf.verifiedBotCategory
## JA4 信号 (企业版)
typescript
import type { IncomingRequestCfProperties } from '@cloudflare/workers-types';
interface JA4Signals {
// 比率 (0.0-1.0)
heuristic_ratio_1h?: number; // 被启发式标记的比例
browser_ratio_1h?: number; // 来自真实浏览器的比例
cache_ratio_1h?: num