From ab30155733bbebe9455d9f9a80385ef2399e61e6 Mon Sep 17 00:00:00 2001 From: "Edgeshot@27" Date: Sat, 22 Aug 2026 22:59:58 +0530 Subject: [PATCH] fix(shared): respect trackOnlyCategories in generic isBot() fallback --- .../bot-detection/__tests__/detector.test.ts | 15 +++++++++++++++ .../shared/src/utils/bot-detection/detector.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/utils/bot-detection/__tests__/detector.test.ts b/packages/shared/src/utils/bot-detection/__tests__/detector.test.ts index 5fb2574b5..5660ac761 100644 --- a/packages/shared/src/utils/bot-detection/__tests__/detector.test.ts +++ b/packages/shared/src/utils/bot-detection/__tests__/detector.test.ts @@ -262,6 +262,21 @@ describe("detectBot", () => { expect(custom.action).toBe(BotAction.BLOCK); }); }); + + describe("Generic isBot() fallback — config should still apply", () => { + it("respects trackOnlyCategories for bots only caught by ua-parser-js's generic isBot()", () => { + const genericBotUA = "PowerShell/7.1.0"; + + const result = detectBot(genericBotUA, { + trackOnlyCategories: [BotCategory.UNKNOWN_BOT], + }); + + expect(result.isBot).toBe(true); + expect(result.category).toBe(BotCategory.UNKNOWN_BOT); + expect(result.reason).toBe("general_bot_pattern"); + expect(result.action).toBe(BotAction.TRACK_ONLY); + }); + }); }); describe("matchCategory", () => { diff --git a/packages/shared/src/utils/bot-detection/detector.ts b/packages/shared/src/utils/bot-detection/detector.ts index 5c32fd9c2..9b9eb5779 100644 --- a/packages/shared/src/utils/bot-detection/detector.ts +++ b/packages/shared/src/utils/bot-detection/detector.ts @@ -151,7 +151,7 @@ function detect( isBot: true, category: BotCategory.UNKNOWN_BOT, name, - action: BotAction.BLOCK, + action: getAction(BotCategory.UNKNOWN_BOT, config), confidence: 70, reason: "general_bot_pattern", };