Nathaniel Lewis

Project 02 · Cloudflare Workers

Identity-gated analytics dashboard

One dashboard for 12 sites' traffic, with the API token kept server-side and every request gated by identity.

  • Cloudflare Workers
  • Cloudflare Access
  • GraphQL Analytics API
  • JavaScript

Problem

Traffic for 12 sites sat in 12 views, and the token to combine them could never reach a browser.

Approach

A single-file Worker behind Access that validates the Access token itself and fails closed.

Result

6 of 6 authorization tests passed before go-live.

  1. Visitorsingle identity
  2. Cloudflare Accesspolicy gate
  3. Workervalidates JWT itself
  4. GraphQL API5-min edge cache

The problem

Traffic data for 12 websites sat in 12 separate views, and the API token needed to combine them could never reach a browser.

The approach

Built a single-file Cloudflare Worker that pulls each site's Web Analytics through the GraphQL API, with a 5-minute edge cache and 7-, 30- and 90-day views. Cloudflare Access gates all traffic with a single-identity policy, and the Worker validates the Access token itself (signature, audience, issuer and expiry) and fails closed until configured. Edge hosting keeps the dashboard up if a NAS goes down.

The result

6 of 6 authorization tests passed before go-live: missing, wrong-audience, expired, tampered, valid and unconfigured. When a credential was briefly exposed during setup, I revoked and rotated it within minutes and stored the replacement as an encrypted secret. A second release removed my own Access sign-in pages from the referrer data so the numbers show real visitors only.

  • 12sites in one view
  • 6 / 6authorization tests passed
  • Minutesto revoke and rotate an exposed credential

What I'd tell the next engineer

Put the check in the code too. If the gateway is ever misconfigured, the app should still refuse.