Audit E1: what the receiver uses from Cloudflare
Step E1 of Part E, done on 29 Nov 2026 by reading cloudflare/worker.js, cloudflare/telegram.js, cloudflare/core/*.mjs and the bot-side files (titan-v18.8.js, titan-loader-v18.0.js, titan-bootstrap.js, titan-tab.user.js, titan-bcgame-shims.js). No code of the receiver was changed. The audit is a snapshot of the code at the time; branch 2 re-checks it against the code it adapts.
1. How the receiver is built
Section titled “1. How the receiver is built”worker.jsexports a defaultfetch(the front door,handle()) and the classStatsHub, the one Durable Object. The front door only checks origin and posting key, then forwards to the hub ashttps://hub/.... Everything stateful is inStatsHub.- There is one hub object, named by
idFromName('titan')(a working name that stays inside the code until the rename, backlog N-01). - The hub keeps most data in memory and writes behind, as E.4 and E.5 assumed.
2. Cloudflare-only things, and what answers each
Section titled “2. Cloudflare-only things, and what answers each”| Used | Where | Node replacement | Needs a written replacement? |
|---|---|---|---|
Durable Object class StatsHub(ctx, env), one instance |
worker.js |
The adapter builds one StatsHub with a ctx it supplies and an env from the env file. |
No |
env.STATS_HUB.idFromName(..).get(..).fetch(url, init) |
handle() |
In-process stub that calls the one hub’s fetch(Request). |
No |
ctx.storage.get(key) (single key only) |
store.get, Auth, Loaders, Groups, Backup |
hub.kv through the cache (E.3). |
No |
ctx.storage.put(key, value) (single key only; no object form is used) |
store.put |
Cache update plus queued upsert; durable keys wait for the commit. | No |
ctx.storage.delete(key) (one key or an array) |
store.delete, backup restore |
Same as put. | No |
ctx.storage.list({ prefix }) (prefix only; no start, end, limit or reverse is used) |
8 key families, see section 4 | where k like $1 order by k collate "C", merged with pending cache changes. Byte order matters: a Durable Object lists keys in byte order, so the query must use the C collation, not the database default. |
No |
ctx.storage.getAlarm() and setAlarm(ms) |
ensureAlarm, alarm() |
One row in hub.alarms plus one timer. |
No |
alarm() handler |
StatsHub.alarm |
The timer calls it. | No |
ctx.waitUntil(promise) |
later() |
Tracked promise; shutdown waits for it. | No |
ctx.acceptWebSocket(ws, tags), ctx.getWebSockets(), ctx.getTags(ws) |
bot, loader and dashboard sockets | Registry in the ws bridge. | No |
ws.serializeAttachment / deserializeAttachment |
socket identity after hibernation | In-memory plus mirror in hub.kv. Check in branch 2 whether any value read after a restart is needed at all: a Node process does not hibernate, so the mirror may be unnecessary. |
No |
ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair('ping','pong')) |
constructor | The bridge answers ping with pong itself. |
No |
webSocketMessage, webSocketClose handlers |
end of StatsHub |
Called from the ws events. (webSocketError is not defined; nothing to call.) |
No |
new WebSocketPair() and new Response(null, { status: 101, webSocket }) |
4 routes: /wsprobe, /bot-ws, /loader-ws, /ws |
The bridge returns a marker object that server.mjs turns into a real upgrade. Node’s Response rejects status 101, so the marker cannot be a Response. |
Yes, in the bridge design |
import STATS_HTML from '../stats.html' and import RESEARCH_HTML from '../research/page.html' |
lines 5 and 6 | Cloudflare’s [[rules]] type = "Text" makes these text modules. Node does not. A small ESM loader hook (node --import) turns an .html import into a string, so the Worker file stays unchanged. |
Yes, loader hook |
crypto.subtle (HMAC), crypto.randomUUID, fetch, Request, Response, Headers |
hmacHex, groups.mjs, outbound calls |
Node 22 provides all of them. | No |
CF-Connecting-IP request header |
clientIp() |
Cloudflare adds it; the adapter must trust it only from 127.0.0.1, where cloudflared connects. Whether the tunnel passes the header unchanged is verified on the live tunnel in Part I, not assumed. |
Yes, verify in Part I |
Workers Logs ([observability]) |
wrangler.toml |
journald through systemd, shown by the monitoring of Part K. |
No |
fetchCfUsage (Cloudflare GraphQL analytics, CF_API_TOKEN) |
core/cfmeter.mjs |
Works from any server with the token, but it reports the Worker’s usage, which stops at cutover. | See finding 1 |
Not used anywhere: KV, R2, D1, Queues, the cache API, HTMLRewriter, scheduled (cron) handlers, blockConcurrencyWhile, storage.transaction, deleteAlarm, service bindings. E.3 lists some of these; the adapter still provides blockConcurrencyWhile and transaction as the plan says, but nothing exercises them today.
Values stored: every test stores values through a JSON copy, and the code stores plain objects. The adapter still checks each value at write time and keeps anything that is not plain JSON (a Map, a Date, bytes) in hub.kv.vb instead of corrupting it.
3. Findings that change the plan
Section titled “3. Findings that change the plan”- The Worker’s request budget has no meaning on Node. The code counts requests against
DAILY_LIMIT(100,000, the Workers free plan), warns at 70%, sends Telegram warnings at 80% and 95%, and switches bots to lighter polling (“deep saving”, the Updates cycle) to stay under it. On Lightsail there is no such limit, yet the features would keep running. The migration changes no behaviour (the rule of Part E), so they stay as they are, and the meter keeps counting. The backlog gets a task to decide what to do with the request-limit features after the migration (retire them, or turn the limit into a setting). Nothing is built for it now. TELEGRAM_BOT_TOKENin F.3 is wrong. The code readsTELEGRAM_TOKEN. Fixed in this pull request, with the complete list below./admin/*answers cross-origin (Access-Control-Allow-Originechoes the caller) because the control-password routes were once called from a second receiver. With one receiver it is no longer needed. It is left as it is; see the backlog.- The old
server.jsat the repository root is an earlier Express receiver with a JSON-file store. It is not used by the migration and is left untouched. - Part E’s “STATS_HUB” binding and the
titan-statsname stay inside the Worker code until the code rename (N-01).
4. Key families that are listed (the only ones list touches)
Section titled “4. Key families that are listed (the only ones list touches)”bot:, blocked:, crh:<platform>:, hist:, inst:n:, inst:tok:, rlc:<id>:, and the prefix passed by Backup/Loaders/Auth as a variable (auth:user:, auth:sess:, loader:, rel:published: and similar). Every other key is read or written by its exact name.
5. The settings the receiver reads (names only)
Section titled “5. The settings the receiver reads (names only)”HOST and PORT, the PG* names and NODE_ENV are the adapter’s own and are added in branch 2. The rest are read by the Worker code today.
| Group | Names | Kind |
|---|---|---|
| Keys and passwords | DASHBOARD_KEY, CONTROL_PASSWORD, CUSTOMER_REF_SECRET, TELEGRAM_WEBHOOK_SECRET |
Secret |
| Owner sign-in | DASHBOARD_OWNER_USER, DASHBOARD_OWNER_PASSWORD, DASHBOARD_OWNER_TOTP, DASHBOARD_OWNER_RESET, AUTH_ISSUER, DASHBOARD_AUTH_OFF (must never be set in production) |
Secret or switch |
| Telegram | TELEGRAM_TOKEN, TELEGRAM_CHAT_ID, TG_ALERTS, TG_DEBT_PCTS, TG_DIGEST_MODE, TG_LOSS_MILESTONES, TG_QUIET_HOURS, DASHBOARD_URL |
Secret and values |
| The private script repository | GITHUB_TOKEN, GITHUB_OWNER, GITHUB_REPO |
Secret and values |
| Research service | RESEARCH_URL, RESEARCH_TOKEN |
Value and secret |
| Backup | BACKUP_URL, BACKUP_TOKEN, BACKUP_FETCH (test hook) |
Secret and test hook |
| Cloudflare meter | CF_API_TOKEN, CF_ACCOUNT_ID, CF_PLAN, CF_BILLING_DAY, CF_METER_CACHE_SEC, CF_FETCH (test hook) |
Secret and values; see finding 1 |
| Tuning (all optional, each has a default in the code) | ALARM_EVERY_SEC, AUDIT_KEEP, BCGAME_FEED_KEEP, CMD_MAX_AGE_SEC, DEEP_ACTIVE_SEC, DEEP_AUTO_BOTS, DELETE_MIN_SILENT_SEC, ID_HOLD_SEC, REALTIME_GRACE_SEC, REPLAY_MAX_AGE_SEC, ROUNDLOG_KEEP, SOCK_ALERT_MIN, STUCK_UPDATE_MIN, UPDATES_CYCLE_SEC, USDT_PRICE_SEC |
Value |
The required set for the adapter to start is: DASHBOARD_KEY, CONTROL_PASSWORD, DASHBOARD_OWNER_USER, DASHBOARD_OWNER_PASSWORD. Everything else is optional, as in the Worker today. A name that exists in the file but is not in this list is reported at start as unknown (a typo guard).
6. The routes and the hostname each one answers on
Section titled “6. The routes and the hostname each one answers on”The split follows E.5 item 5. The bot-side column is what the script, loader, bootstrap and tab userscript really call (found by reading them).
api.bideward.com (bots, loaders, feed; the posting key X-Titan-Key, or ?key= for a socket):
POST /log-stats, POST /log-stats-batch, POST /claim-id, GET /commands, POST /loader/register, /loader/poll, /loader/bundle, /loader/source, POST /bcgame-feed/push, /bcgame-feed/latest, /bcgame-feed/tab-claim, POST /bcgame/loader, WebSocket /bot-ws and /loader-ws, POST /telegram/webhook (checked against TELEGRAM_WEBHOOK_SECRET; the Cloudflare rules of D.6 must let Telegram’s servers through), WebSocket /wsprobe (a feasibility probe, kept), and the new health route.
app.bideward.com (the dashboard, sign-in cookie): GET /, /stats.html, /auth/* (open ones: /auth/config, /auth/login, /auth/login/code, /auth/setup, /auth/setup/confirm), the WebSocket /ws, /control, /audit, /admin/* (control password), the signed-in reads /roundlog, /crashhistory, /realtime, /budget, /tgmuted, /loaders, /survival-code, /config-code, /usdt-price, /rates, /releases, /releases/repo, /releases/check, /diag, /hidden-scripts, /backup-status, /groups, /groups/save, /groups/delete, /c/* (customer routes), /research, /research/status, /research/api/*.
Anything else on either name answers 404. Host matching is exact; the Host header is the one cloudflared forwards.
Ambiguous routes, decided here. /tgmuted (GET) is answered with the bot origins’ CORS but is read by the dashboard, not by the script, so it is an app route. GET /rates and GET /usdt-price are dashboard reads (the script does not call them), also app routes.
7. What this means for the next branches
Section titled “7. What this means for the next branches”- Branch 1 (this one): the Layer 1 migration and the runner. Nothing else is needed from this audit.
- Branch 2 builds the pieces marked “Yes” above (the ws bridge marker, the
.htmlloader hook, the trusted-header rule) together with the rest of the adapter. - Branch 3 builds the tests of E.6 and the
deploy/folder.