Packing 79,463 CNAME-Cloaked sGTM Domains Into a

2026-12-01来源 dev.toEnglish

While auditing 2,328 live European websites from Frankfurt on Google Consent Mode v2 (gcs/gcd transitions across Cold Load -> Reject All -> Accept All), one recurring pattern stood out:

Sites paying for server-side Google Tag Manager (sGTM) — often hosted on Stape or Cloud Run behind a custom subdomain like sgtm.example.com or metrics.example.com — were still losing tracking hits because their custom subdomain had already landed on public CNAME-cloaking and DNS ad-blocker lists.

I wanted to build an instant, zero-login checker that runs entirely at the edge on Cloudflare Workers with < 5ms cold start and lookup latency, zero external DNS queries, and zero database round-trips.

Here is how we packed 79,463 domains across 5 major filter lists into a compact Worker bundle.

1. The 5 Blocklists We Indexed

Ad-blocker and DNS filter maintainers actively sweep CNAME-cloaked first-party tracking proxies. Merging and deduplicating the 5 most widely deployed lists (used by AdGuard, Brave, NextDNS, Pi-hole, and uBlock Origin) yields 79,463 unique indexed domains:

Blocklist Source Raw Entries Indexed sGTM / Proxy Domains
AdGuard CNAME-Cloaked Trackers (stape_justdomains) 69,332 49,569
HaGeZi Multi Normal DNS Blocklist 179,620 23,077
AdGuard DNS Filter (AdguardSDNSFilter) 195,395 21,827
EasyPrivacy 47,855 4,409
1Hosts (Lite) 202,954 1,335

(A single domain can appear in multiple lists — e.g. both adguard_cname and hagezi_multi.)

2. Why a Naive JSON Object Blows Up Cloudflare Worker Cold Starts

Dropping a raw JSON map of 79,463 domain strings -> list arrays into a Cloudflare Worker causes two immediate problems:

  1. Bundle size & memory: Plain JSON with list names repeated 79k times quickly balloons past multi-megabyte Worker size limits.
  2. Cold-start CPU: Parsing a massive JSON object or building a new Set(...) on every isolate boot burns tens of milliseconds of startup CPU before the first request is even served.

Our Fix: Bitmask Buckets + Front-Coded Blocks + Lazy Binary Search

Instead of storing an array of list names per domain, we assign each of the 5 lists a single bit (1 << 0 through 1 << 4), group domains by their 5-bit mask (1..31), sort each bucket lexicographically, and front-code adjacent entries in fixed-size blocks separated by blank lines:

analytics.chimar.com Lityskydive.nl # shares 11-char prefix ("analytics.c") + "ityskydive.nl" Mur.cz # shares 12-char prefix ("analytics.ci") + "ur.cz" 

Because every block starts with one unencoded header domain, the Worker never decompresses the whole index at startup:

  1. At request time, it binary-searches only the block headers inside each bitmask bucket (zero heap allocations for untouched blocks).
  2. Only the single candidate block that could contain the target domain is decoded sequentially.
  3. For any queried hostname like collect.sgtm.brand.de, we walk parent suffixes (collect.sgtm.brand.de -> sgtm.brand.de -> brand.de) so wildcard/parent rules match immediately:
const parts = host.split("."); let matchedRule: string | null = null; let matchedMask = 0; for (let i = 0; i <= parts.length - 2; i++) { const candidate = parts.slice(i).join("."); const mask = lookupDomainBitmask(candidate); if (mask !== 0) { matchedRule = candidate; matchedMask = mask; break; } } 

Result: < 5ms cold start and lookup latency inside a standard Cloudflare Worker, with zero external API calls.

3. Catching "Not Listed Yet" Subdomains With Giveaway-Prefix Heuristics

Even if a brand-new sgtm.example.com subdomain hasn't been scraped into adguard_cname yet, filter-list maintainers regularly sweep obvious tracking prefixes. Alongside exact blocklist matching, we check subdomain labels against high-risk giveaway prefixes (sgtm, ssgtm, sst, gtm, tagging, metrics, analytics, telemetry, tracking, collect, pixel, stats) and surface a HIGH / MEDIUM / LOW heuristic risk rating.

If you're deploying server-side GTM:

  • Prefer A/AAAA records or Same-Origin routing over CNAMEs whenever your DNS host supports it.
  • Pick a neutral subdomain instead of sgtm.* or metrics.*.
  • Pair Custom Loader with request-path encoding so /g/collect isn't trivially pattern-matched.

Try It Live (Free, No Login)

If you've run into interesting edge cases with CNAME-cloaking detection or Cloudflare Worker static-index packing, I'd love to hear how you approached it in the comments!

原文:https://www.a8q9.cn/en/article/packing-79-463-cname-cloaked-sgtm-domains-into-a-5ms-cloudflare-worker-blocklist-95566d.html

相关文章