Files
ukmesh/anubis/botPolicy.yaml
gadgethd 631de62849 fix(anubis): allow the cookie-free analytics beacon (#258)
The Umami tracker posts events with credentials:omit by design, so it cannot carry the Anubis auth cookie and its beacons were being answered with the challenge page instead of the collect API.

Allow only the two exact paths the tracker uses (/_stats/script.js and /_stats/api/send). Everything else keeps the existing bot policy.
2026-11-20 03:00:00 +00:00

159 lines
6.3 KiB
YAML

## Anubis bot policy — shared across all protected services
##
## Rule evaluation: first match wins within the bots section.
## Thresholds apply after all WEIGH rules have accumulated.
bots:
# -- Analytics endpoints: never challenge ----------------------------------
# The cookie-free Umami tracker posts with credentials:"omit" by design, so
# it can never carry the Anubis auth cookie. These two paths are the only
# ones it needs, and both are inert for normal browsing.
- name: allow-analytics-beacon
path_regex: ^/_stats/(script\.js|api/send)$
action: ALLOW
# ── WebSocket paths: always allow, no challenge ────────────────────────────
# Upgrade requests to /ws must bypass the challenge gate. By the time the
# browser JS opens the WebSocket, the page-load challenge is already solved
# and the cookie is set. This ALLOW ensures reconnects and edge-cases are
# safe regardless. Bots do not open WebSocket connections.
- name: websocket-paths
path_regex: ^/ws(/.*)?$
action: ALLOW
# ── PWA shell: service worker and manifest must never be challenged ────────
# An HTML challenge returned for /sw.js breaks registration and update,
# stranding clients on a stale app cache after a deploy.
- name: allow-pwa-shell
path_regex: ^/(sw\.js|sw-runtime\.js|manifest\.json|workbox-[^/]+\.js)$
action: ALLOW
# ── Terrain tile paths: always allow, no challenge ─────────────────────────
# Static elevation tiles are public read-only data (no sensitive content).
# Bypassing Anubis here lets Cloudflare cache them without cookie headers
# in the request, which is required for CDN caching to work correctly.
- name: terrain-tile-paths
path_regex: ^/terrain-tiles/
action: ALLOW
# ── Link-preview bots: allow so shared links render embeds ────────────────
# Discordbot/LinkedInBot UAs contain "Mozilla", which otherwise trips the
# generic-browser WEIGH rule (+10 -> challenge they cannot solve).
# These agents only fetch public pages for unfurling; UA-only ALLOW is fine.
# NOTE: AI-search carve-out (OAI-SearchBot etc.) intentionally not enabled;
# see FIX-PACK section 2.2 in ~/.review-notes/nemesh-seo-2026-10-11/ to enable.
- name: allow-link-preview-bots
user_agent_regex: >-
(?i)Discordbot|LinkedInBot|Slackbot|Twitterbot|TelegramBot|WhatsApp|facebookexternalhit|Facebot|Pinterestbot|redditbot
action: ALLOW
# ── IndexNow key file: always allow ───────────────────────────────────────
# Search engines fetch /assets/<32-hex>.txt from arbitrary IPs/UAs to verify
# site ownership for IndexNow submissions; those fetchers carry "Mozilla"
# in the UA and would otherwise be challenged (returning HTML instead of
# the key, which fails verification with a 422). Static file, exact pattern.
- name: allow-indexnow-key
path_regex: ^/(assets/)?[0-9a-f]{32}\.txt$
action: ALLOW
# ── Google tooling: GSC URL Inspection, Rich Results test, PageSpeed Insights ──
# These fetchers run from Google infra but not necessarily from the published
# googlebot IP ranges, so the UA+IP-gated googlebot allow rule can miss them.
- name: allow-google-tools
user_agent_regex: >-
(?i)Google-InspectionTool|Chrome-Lighthouse|Google-PageSpeedInsights|Google-Structured-Data-Testing-Tool|Google-Site-Verification
action: ALLOW
# ── Built-in deny rules for pathological bots ──────────────────────────────
- import: (data)/bots/_deny-pathological.yaml
- import: (data)/bots/aggressive-brazilian-scrapers.yaml
# ── Block AI/LLM crawlers aggressively ────────────────────────────────────
- import: (data)/meta/ai-block-aggressive.yaml
# ── Allow known good search crawlers ──────────────────────────────────────
# Covers: Google, Apple, Bing, DuckDuckGo, Qwant, Internet Archive,
# Kagi, Marginalia, Mojeek, CommonCrawl, Yandex
- import: (data)/crawlers/_allow-good.yaml
# ── Allow common maintenance routes ───────────────────────────────────────
# Covers: /.well-known/, /robots.txt, /sitemap.xml, /favicon.*
- import: (data)/common/keep-internet-working.yaml
# ── Deny additional hostile SEO/scraper bots ──────────────────────────────
- name: deny-semrush
user_agent_regex: SemrushBot
action: DENY
- name: deny-ahrefsbot
user_agent_regex: AhrefsBot
action: DENY
- name: deny-majestic
user_agent_regex: MJ12bot
action: DENY
- name: deny-dotbot
user_agent_regex: DotBot
action: DENY
- name: deny-petalbot
user_agent_regex: PetalBot
action: DENY
- name: deny-uptimerobot-scrape
# UptimeRobot monitoring is fine; this pattern targets known abusive variants
user_agent_regex: "(?i)zgrab|masscan|nuclei|nmap"
action: DENY
# ── Generic browser: add weight, challenge via thresholds ─────────────────
- name: generic-browser
user_agent_regex: >-
Mozilla|Opera
action: WEIGH
weight:
adjust: 10
dnsbl: false
status_codes:
CHALLENGE: 200
DENY: 200
store:
backend: memory
parameters: {}
thresholds:
- name: minimal-suspicion
expression: weight <= 0
action: ALLOW
- name: mild-suspicion
expression:
all:
- weight > 0
- weight < 10
action: CHALLENGE
challenge:
algorithm: metarefresh
difficulty: 1
- name: moderate-suspicion
expression:
all:
- weight >= 10
- weight < 20
action: CHALLENGE
challenge:
algorithm: fast
difficulty: 2
- name: mild-proof-of-work
expression:
all:
- weight >= 20
- weight < 30
action: CHALLENGE
challenge:
algorithm: fast
difficulty: 4
- name: extreme-suspicion
expression: weight >= 30
action: CHALLENGE
challenge:
algorithm: fast
difficulty: 6