cf-analytics — telemetry ingest Worker
Cloudflare Worker that accepts schema-1 telemetry pings from
SourceBans++ panels at
https://cf-analytics-telemetry.sbpp.workers.dev/v1/ping, validates with
Zod, strips IP-bearing headers by construction, and writes
to Workers Analytics Engine.
This repo is the consumer half of sbpp/sourcebans-pp#1126.
Implementation is tracked in #1.
Endpoint contract
| Method |
Path |
Behaviour |
POST |
/v1/ping |
Validate body against the schema dispatched on body.schema. On success: writeDataPoint to AE, return 204 No Content. On schema mismatch / parse error: 400. |
GET |
/healthz |
200 OK, body ok (plain text). For uptime monitoring. |
* |
* |
404, no body. The path is not echoed. |
No CORS, no OPTIONS handling. Edge rate limit returns 429 before the
Worker is invoked (see below).
Request body (schema 1)
The wire schema is defined jointly by
sbpp/sourcebans-pp#1126
and this repo's schema/1.lock.json. The lock file
is the positional source of truth for the AE blob/double/bit layout; the
panel issue is the source of truth for the wire field set.
{
"schema": 1,
"instance_id": "8f6c5b…",
"panel": {
"version": "2.0.0",
"git": "abc1234",
"dev": false,
"theme": "default",
"region": "eu",
"exported_30d": true
},
"env": {
"php": "8.2",
"sapi": "fpm-fcgi",
"db_engine": "mariadb",
"db_version": "10.11",
"web_server": "litespeed",
"os_family": "linux",
"memory_limit_mb": 256,
"max_execution_time": 30,
"disable_functions_count": 7,
"zts": false,
"php_64bit": true,
"open_basedir_set": true,
"allow_url_fopen": true,
"opcache_loaded": true,
"suhosin_loaded": false,
"posix_available": true,
"host_panel_cpanel": true,
"host_panel_plesk": false,
"host_panel_directadmin": false,
"docroot_user_home": true,
"sapi_per_user": true
},
"scale": {
"admins": 12,
"servers_enabled": 7,
"bans_active": 2847,
"bans_total": 18394,
"comms_active": 412,
"comms_total": 5108,
"submissions_30d": 23,
"protests_30d": 0,
"bans_30d": 311,
"admins_active_30d": 5,
"ban_history_months": 74,
"web_bans_majority_30d": false,
"games": {
"tf": true,
"cstrike": false,
"csgo": true,
"garrysmod": false,
"left4dead2": false,
"other": true
},
"perms": {
"web_groups": true,
"server_groups": true,
"overrides": false,
"immunity": true
}
},
"features": {
"submit": true,
"protest": true,
"comms": true,
"kickit": false,
"exportpublic": false,
"publiccomments": false,
"steamlogin": true,
"normallogin": true,
"groupbanning": false,
"friendsbanning": false,
"adminrehashing": true,
"smtp_configured": true,
"steam_api_key_set": true,
"geoip_present": true
}
}
Only schema and instance_id are required. Every other field is
.optional() in the validator (forward-compat optionality rule). Unknown
top-level keys pass through and are captured into the extras blob.
Response
204 No Content on success — no body.
400 { "error": "schema_not_supported" } for unknown / missing / non-numeric schema.
400 { "error": "schema_invalid" } for shape mismatches inside a known schema.
400 { "error": "invalid_json" } for malformed JSON bodies.
404 (no body) for everything else.
429 from Cloudflare's edge for rate-limited clients (the Worker isn't invoked).
Privacy / anonymity contract
The Worker MUST NOT persist or log any of the following, full stop. This is
the load-bearing trust contract from
sbpp/sourcebans-pp#1126:
CF-Connecting-IP / CF-Connecting-IPv6 header values
X-Forwarded-For / X-Real-IP header values
True-Client-IP (Enterprise plan; banned to be safe)
CF-Pseudo-IPv4 header value
request.cf.city, request.cf.latitude, request.cf.longitude,
request.cf.region, request.cf.regionCode, request.cf.postalCode,
request.cf.metroCode, request.cf.timezone
- TLS fingerprints
request.cf.colo (the edge node id) is allowed — it identifies our edge, not
the client.
panel.region is not a geolocation of the request. The panel derives it from
its own configured config.timezone and sends only the continent code (af,
as, eu, na, oc, sa) or omits it; the Worker never reads
request.cf.timezone or any other request.cf location field to fill it.
The Worker is structured so the AE data point is built only from the
validated body. Headers and request.cf are never read on the ingest path.
That makes "no IP data path" the default, not an opt-in. The IP-stripping
middleware (src/strip-ip.ts) is a guard rail that
documents the contract and exposes a test helper (assertNoIpFields) that
the IP-leak test in test/ip-leak.test.ts calls on
every captured writeDataPoint argument.
No Logpush. Turning on Logpush would re-introduce the IP-leak surface;
adding it later requires re-deriving this contract against the new sink.
On dropping scale.* bucketing (privacy trade-off)
Schema-1 ships raw integer counts (e.g. bans_active: 2847) rather than the
bucketed strings ("1k-9.9k") originally proposed in
sbpp/sourcebans-pp#1126.
Raw counts combined with panel.theme, panel.git, and env.* produce a
higher-resolution per-install fingerprint than buckets would. The trade-off
is acceptable for this iteration because:
- The data lives only in AE, never in logs, extracts, or row-granularity exports.
- The IP-stripping contract is unaffected.
- Access to AE is roadmap-decision-only — there is no public dashboard, no
anonymous extract, no row-level API.
Any future change that exposes row-level data (public stats page,
downloadable extracts, etc.) reopens this decision and requires a privacy
review before shipping. The original bucketing rationale is preserved in
sbpp/sourcebans-pp#1126's history.
Schema evolution rules
There is no auto-update for self-hosted SourceBans++ installs. Old panels
keep sending old payloads forever. The Worker accepts every schema version
it has ever shipped, in parallel with whatever the latest panel sends.
Three evolution axes (see CONTRIBUTING.md for the
edit policy):
- Additive — panel adds a new optional field within a schema version.
Schema number stays at 1. The Worker's
.passthrough() validator keeps
the unknown key in the parsed payload, and mapDataPoint puts it in the
extras JSON blob. Once promoted to a typed slot, the field appends to
lock.blobs / lock.doubles at the next free position. Until promotion,
queries reach it via json_extract(blob<extras>, '$.new_field').
- Slot exhaustion. Schema-1 reserves 20 blob slots and 20 double slots.
Currently 12/20 blobs and 16/20 doubles are committed, and 39/53 bits of
panel_features_bits. Once an addition
would push past the cap, the field lives permanently in extras until a
schema bump. We never reshuffle existing slot positions — AE indexes
are positional, and historical rows already use the current layout.
- Subtractive / repurposing. Bumps the schema number. The panel sends
schema: 2, the Worker dispatches to a separate validator + writer.
Both schemas write to the same AE dataset, distinguished by the schema
double. Schema-1 validators are kept indefinitely — the long-tail of
un-upgraded installs is exactly the dataset we exist to capture.
AE layout
Positions in the table below are the contract. Never reorder them. The
JSON block between the markers is byte-equal to
schema/1.lock.json; the layout test in
test/layout.test.ts parses this block and asserts
deep-equality both directions.
{
"blobs": [
"instance_id",
"panel.version",
"panel.git",
"panel.theme",
"env.php",
"env.sapi",
"env.os_family",
"env.web_server",
"env.db_engine",
"env.db_version",
"extras",
"panel.region"
],
"doubles": [
"schema",
"panel_features_bits",
"env.memory_limit_mb",
"env.max_execution_time",
"env.disable_functions_count",
"scale.admins",
"scale.servers_enabled",
"scale.bans_active",
"scale.bans_total",
"scale.comms_active",
"scale.comms_total",
"scale.submissions_30d",
"scale.protests_30d",
"scale.bans_30d",
"scale.admins_active_30d",
"scale.ban_history_months"
],
"bits": [
"panel.dev",
"features.submit",
"features.protest",
"features.comms",
"features.kickit",
"features.exportpublic",
"features.publiccomments",
"features.steamlogin",
"features.normallogin",
"features.groupbanning",
"features.friendsbanning",
"features.adminrehashing",
"features.smtp_configured",
"features.steam_api_key_set",
"features.geoip_present",
"env.zts",
"env.php_64bit",
"env.open_basedir_set",
"env.allow_url_fopen",
"env.opcache_loaded",
"env.suhosin_loaded",
"env.posix_available",
"env.host_panel_cpanel",
"env.host_panel_plesk",
"env.host_panel_directadmin",
"env.docroot_user_home",
"env.sapi_per_user",
"scale.games.tf",
"scale.games.cstrike",
"scale.games.csgo",
"scale.games.garrysmod",
"scale.games.left4dead2",
"scale.games.other",
"scale.perms.web_groups",
"scale.perms.server_groups",
"scale.perms.overrides",
"scale.perms.immunity",
"scale.web_bans_majority_30d",
"panel.exported_30d"
]
}
Reading the layout
blobs[i] is AE's blob{i+1} column (AE columns are 1-indexed in SQL).
blobs[0] = "instance_id" therefore queries as blob1.
doubles[i] is AE's double{i+1} column.
indexes[0] is AE's index1 column. The Worker indexes by
panel.version, which gives bounded cardinality and is the field most
queries filter on.
bits[i] is bit i (LSB = 0) of the panel_features_bits double.
39 booleans pack into one double (under the 53-bit safe-integer
ceiling), leaving 4/20 doubles free for future scale dimensions.
- Missing typed strings →
null in the corresponding blob. Missing scale
numbers → null in the corresponding double (so analysts can distinguish
"not sent" from "zero"). Missing booleans → 0 bits in
panel_features_bits. The panel_features_bits double is always present.
extras (blob11) is null when there are no unknown top-level keys,
otherwise a JSON-stringified object of every unknown top-level key. AE
stores nothing rather than {} so analysts don't have to coalesce empty
objects out. It is no longer the last blob: slots promoted after it (e.g.
panel.region) append behind it, because positions never move.
- Nested objects flatten to dotted names:
scale.games.tf reads
payload.scale.games.tf. Rows written before a slot existed read as
null (doubles / blobs) or 0 (bits), the same as "not sent".
featureFlag(name) SQL macro for AE
Once a feature is in lock.bits, queries against AE can extract any
individual feature flag from the panel_features_bits double:
-- featureFlag(name): treats double2 as the packed bitfield and returns 1
-- when bit at lock.bits.indexOf(name) is set, 0 otherwise.
--
-- Replace <bit_index> with the 0-based position of `<name>` in lock.bits.
-- e.g. "features.submit" lives at index 1, so featureFlag("features.submit")
-- is `(double2 >> 1) & 1`.
SELECT
blob2 AS panel_version,
((toUInt64(double2) >> 0) & 1) AS panel_dev,
((toUInt64(double2) >> 1) & 1) AS feature_submit,
((toUInt64(double2) >> 4) & 1) AS feature_kickit,
((toUInt64(double2) >> 14) & 1) AS feature_geoip_present,
count() AS pings
FROM telemetry
WHERE timestamp > now() - INTERVAL 7 DAY
GROUP BY panel_version, panel_dev, feature_submit, feature_kickit, feature_geoip_present
ORDER BY pings DESC;
The bit index for a feature name is its 0-based position in lock.bits. To
look up the position programmatically, see
src/lock.ts's bitIndex() helper.
Deriving host_kind query-time
The env.*