databuddy-analytics / databuddy-analytics/Databuddy
fix(bot-detection): respect trackOnlyCategories in generic isBot() fallback
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 216
- Avg merge
- 14h 53m
- Merged PRs (30d)
- 154
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- typescript
- Domain
- security
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100