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

Open Beginner friendly
#666 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
security

Research direction

Start at detectBot() and the generic isBot() fallback, alongside ua-patterns.ts and isAIBot(), then compare its action handling with getAction(). Done means trackOnlyCategories applies to UNKNOWN_BOT detections, including the PowerShell example, with the expected track_only action; verify this with the relevant tests.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
1.2k
Forks
216
Avg merge
14h 53m
Merged PRs (30d)
154

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databuddy-analytics/Databuddy

All issues in databuddy-analytics/Databuddy

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.