Skip to content

fix(botManagement): detectionIds default json#3631

Open
thiskevinwang wants to merge 1 commit into
cloudflare:mainfrom
thiskevinwang:kevin/bot-detectionIds
Open

fix(botManagement): detectionIds default json#3631
thiskevinwang wants to merge 1 commit into
cloudflare:mainfrom
thiskevinwang:kevin/bot-detectionIds

Conversation

@thiskevinwang

Copy link
Copy Markdown

What

This aims to resolve a runtime discrepancy in botManagement.detectionIds.

Why

We're observing two different runtime types {} and number[], but expect only number[] based on HTTP Requests Docsarray[int] — as well as the TypeScript types


CloudFlare dashboard logs

own cURL request non bot traffic
CleanShot 2025-02-28 at 09 58 22@2x

@thiskevinwang thiskevinwang requested review from a team as code owners February 28, 2025 15:05
@thiskevinwang thiskevinwang changed the title fix(bot): detectionIds default json fix(botManagement): detectionIds default json Feb 28, 2025
@ketanhwr

Copy link
Copy Markdown
Member

Thanks for your contribution!
Your change makes sense to me logically, but I can see that it'll break an internal test (which might itself be wrong since the start).
cc: @jasnell who might have more context

@danlapid danlapid requested a review from jasnell February 28, 2025 22:30
@kentonv

kentonv commented Mar 5, 2025

Copy link
Copy Markdown
Member

This change seems correct, however, I think this value is only used if your compat date is set before 2023-08-01. I believe this default value is being injected to work around a bug where bot management was previously passing bot management info on every request. If you instead set your compat date to 2023-08-01 or later (or set the compat flag no_cf_botmanagement_default) then I think you won't see this value at all.

Would it make more sense to update your compat date, or set the flag?

@thiskevinwang

Copy link
Copy Markdown
Author

@kentonv Thanks for getting back - The compatibility flag I have is:

# wrangler.toml
compatibility_date = "2024-04-03"

...and to clarify, I'd like to have botManagement.detectionIds present (the account in question is entitled to Bot Management), but the surprise/undocumented {} json value seen by the worker is the problem. (I expect to only be int[])

And neither of the Bot management flags seem appropriate (if i'm reading the docs correctly)

Does this make sense? Does it add some actionable direction to this PR?

@kentonv

kentonv commented Mar 6, 2025

Copy link
Copy Markdown
Member

I see, I think this PR does not actually fix the underlying problem. In this PR you are modifying a placeholder value that is used for compatibility when people don't have bot management enabled at all (and have an old compat date). The problem seems to be that the real bot management service is actually generating {} when this list is empty. That is a bug in the bot management service, not in workerd.

@thiskevinwang

Copy link
Copy Markdown
Author

@kentonv Insightful!

That is a bug in the bot management service, not in workerd.

Would this still be the case given -> I never see occurrences of {} in HTTP Request - BotDetectionIDs log push data?

At any rate - I'll defer to you for closing this PR (it sounds like that is the direction).
And thanks for the feedback here!

@kentonv

kentonv commented Mar 10, 2025

Copy link
Copy Markdown
Member

Maybe @irvinebroque can route this to the right people on bots management to fix things there?

@cysp

cysp commented Jan 30, 2026

Copy link
Copy Markdown

💯 I have just encountered what I assume is this issue when attempting to access .botManagement.detectionIds in a Cloudflare Snippet.
(Acknowledging the comment above indicating that this isn't actually a Workers (or Snippets) bug, but commenting here to help others who have encountered this issue.)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants