Skip to content

fix(bot-detection): respect trackOnlyCategories in generic isBot() fallback #666

Description

@aditya3799

Description

In detectBot(), when a User-Agent is not matched by literal/regex patterns in ua-patterns.ts or by isAIBot(), it falls back to isBot() from ua-parser-js.

Currently, this generic fallback branch hardcodes action: BotAction.BLOCK instead of routing through getAction(BotCategory.UNKNOWN_BOT, config):

if (isBot(userAgent)) {
    return {
        isBot: true,
        category: BotCategory.UNKNOWN_BOT,
        name,
        action: BotAction.BLOCK,   // ignores config.trackOnlyCategories
        confidence: 70,
        reason: "general_bot_pattern",
    };
}

As a result, configuring trackOnlyCategories: [BotCategory.UNKNOWN_BOT] does not apply to traffic detected via this fallback, and action: "block" is returned instead of "track_only".

Example:
A User-Agent like PowerShell/7.1.0 (which is recognized as a CLI tool by ua-parser-js's isBot() but is not present in ua-patterns.ts or isAIBot()):

detectBot("PowerShell/7.1.0", {
  trackOnlyCategories: [BotCategory.UNKNOWN_BOT],
});
Expected: action: "track_only"
Actual: action: "block"
Proposed Fix
Route the generic isBot() fallback through getAction():
action: getAction(BotCategory.UNKNOWN_BOT, config),

I have verified the fix and tests locally and can open a PR once this issue is accepted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions