Skip to content

Website Change Alerts on Cloudflare Workers: Verified Receiver

A complete Cloudflare Worker that receives AyeWatch website change alerts: raw body, crypto.subtle.verify for the signature, KV to skip repeats, a 200 inside 10 seconds, then your action.

By AyeWatch Team5 min read

Short answer: To receive website change alerts on Cloudflare Workers, deploy a Worker that reads the raw body with request.arrayBuffer(), checks X-AyeWatch-Signature with crypto.subtle.verify, skips update_id values already stored in KV, and answers 200 within 10 seconds. Cloudflare's free plan allows 100,000 requests a day, far more than an alert pipeline needs.

Why a Worker suits this job

A Worker gives you a public HTTPS URL on workers.dev that answers directly, with no redirect unless you write one. It has the Web Crypto API built in, so the signature check needs no library. And it can sit in front of tools that cannot check a signature themselves: Power Automate, Apps Script, IFTTT and Home Assistant.

Cloudflare's free plan allows 100,000 requests a day and 10 ms of CPU time per request, as of December 2026. Time spent waiting on KV or on another fetch is not CPU time, and one HMAC over a small JSON body takes a fraction of a millisecond. KV's free tier allows 1,000 writes a day, and this Worker writes once per new alert.

The Worker

Sample rule: Alert me when Northwind Cloud's status page posts an incident or planned maintenance for the EU region. Ignore resolved incidents older than a day.

The Worker below forwards each new alert to your own API, an incident tool at ops.example in this case. Store AYEWATCH_SECRET, FORWARD_URL and FORWARD_TOKEN as secrets and bind a KV namespace as SEEN.

// src/worker.js
async function verify(raw, header, secret) {
  const hex = header.startsWith("sha256=") ? header.slice(7) : "";
  if (!/^[0-9a-f]{64}$/.test(hex)) return false;
  const sig = new Uint8Array(32);
  for (let i = 0; i < 32; i++) sig[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
  const key = await crypto.subtle.importKey(
    "raw",
    new TextEncoder().encode(secret),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["verify"]
  );
  return crypto.subtle.verify("HMAC", key, sig, raw);
}

export default {
  async fetch(request, env, ctx) {
    if (request.method !== "POST") return new Response("Method not allowed", { status: 405 });

    // 1. Raw body: the signature covers these exact bytes.
    const raw = await request.arrayBuffer();

    // 2. Signature: crypto.subtle.verify compares in constant time.
    const header = request.headers.get("X-AyeWatch-Signature") || "";
    if (!(await verify(raw, header, env.AYEWATCH_SECRET))) {
      return new Response("Bad signature", { status: 401 });
    }

    // 3. Dedupe: retries carry the same update_id.
    const alert = JSON.parse(new TextDecoder().decode(raw));
    const key = "update:" + alert.update_id;
    if (await env.SEEN.get(key)) return new Response("Already handled");

    // 4 and 5. Act inside the 10 seconds, then answer.
    const res = await fetch(env.FORWARD_URL, {
      method: "POST",
      headers: { "Content-Type": "application/json", Authorization: "Bearer " + env.FORWARD_TOKEN },
      body: JSON.stringify({
        title: alert.headline || alert.topic_name,
        details: alert.content || "",
        source: alert.topic_name,
        ref: "ayewatch-" + alert.update_id,
      }),
      signal: AbortSignal.timeout(7000),
    }).catch(() => null);
    if (!res || !res.ok) return new Response("Forward failed", { status: 502 });

    await env.SEEN.put(key, "1", { expirationTtl: 1209600 });
    return new Response("ok");
  },
};

Cloudflare's own docs recommend crypto.subtle.verify() for this check because it guards against timing attacks. The verify helper rejects a header that is not exactly sha256= followed by 64 hex characters before it touches the key.

Deploy it

npx wrangler kv namespace create SEEN
npx wrangler secret put AYEWATCH_SECRET
npx wrangler secret put FORWARD_URL
npx wrangler secret put FORWARD_TOKEN
npx wrangler deploy

Put the namespace ID that the first command prints into wrangler.toml:

name = "ayewatch-receiver"
main = "src/worker.js"
compatibility_date = "2026-12-01"

[[kv_namespaces]]
binding = "SEEN"
id = "PASTE_THE_ID_HERE"

The deploy prints a URL like https://ayewatch-receiver.your-subdomain.workers.dev. Paste it into AyeWatch.

Act first, or answer first?

The Worker above acts before it answers. If your API is down, AyeWatch gets a 502 and retries with backoff, up to 10 attempts. That only works when the action fits inside 10 seconds, so the forward has a 7-second limit.

For slow work, such as an AI summary or a long chain of calls, answer first and keep working with ctx.waitUntil:

await env.SEEN.put(key, "1", { expirationTtl: 1209600 });
ctx.waitUntil(slowFollowUp(alert, env));
return new Response("ok");

The cost: AyeWatch has already seen a 200, so a failure inside slowFollowUp is yours to log and retry. Pick one pattern per Worker and write it down.

Limits and cost

  • KV is eventually consistent. Two copies of an alert that arrive very close together could both pass the check. AyeWatch's retries are spaced out by backoff, so this is rare. Use a Durable Object or a database with a unique key if you need exactly once.
  • One webhook per account. Branch on topic_id if monitors need different destinations.
  • Do not add redirects. A custom domain rule that sends this path elsewhere with a 3xx fails every delivery at once.
  • Public pages only. AyeWatch reads public pages and cannot sign in.

AyeWatch Pro is $9/mo with 50 topics and hourly checks; Pro+ is $19/mo with 200 topics and ASAP mode. Every plan starts with a 7-day free trial. A web page monitor can cover up to 3 URLs on Pro for 1 credit a check, so one monitor for both of Northwind's status pages, checked every 3 hours, uses 240 credits a month. Cloudflare's paid Workers plan starts at $5 a month with 10 million requests included, if you ever outgrow the free one.

From zero to a verified receiver

  1. Create a Worker project and save the code above as src/worker.js.
  2. Create the KV namespace and put its ID in wrangler.toml.
  3. In AyeWatch, open Notification settings, Webhook. You need the Worker URL first, so deploy once, paste the URL and select Save Webhook.
  4. Reveal and copy the signing secret, then run npx wrangler secret put AYEWATCH_SECRET and the other two secrets.
  5. Deploy again and wait for a real update. AyeWatch has no test button.
  6. Open the Worker's logs and confirm the first request got a 200.
StepWorker APIWhat goes wrong without it
Raw bodyrequest.arrayBuffer()A re-encoded body no longer matches the signature
Signaturecrypto.subtle.verify with an HMAC SHA-256 keyAnyone with the URL can send fake alerts
DedupeKV get and put keyed on update_idA retry runs the action twice
Replynew Response within 10 secondsAyeWatch retries an alert you already handled
Slow workctx.waitUntilThe reply waits and misses the 10 seconds

Start a monitor in under a minute

Describe a topic or paste a URL. Cancel before the trial ends and you pay nothing.

Try it free for 7 days

The bottom line

This Worker is the base for every relay in this series: raw bytes, a constant-time check, a KV dedupe and a quick 2xx. Change the forward step and it feeds any tool that cannot verify a signature on its own.

FAQ

How do I verify an HMAC webhook signature in a Cloudflare Worker?

Import the secret as an HMAC SHA-256 key with crypto.subtle.importKey, decode the hex signature into bytes and call crypto.subtle.verify on the raw body. It compares in constant time.

Why use request.arrayBuffer() and not request.json()?

The signature covers the exact bytes AyeWatch sent. Parsing and re-serializing can change spacing or key order, so verify the raw bytes, then parse.

Is the free Workers plan enough for an alert receiver?

Yes for most accounts. It allows 100,000 requests a day and 10 ms of CPU per request, and waiting on fetch or KV does not count as CPU time.

Can KV fully prevent duplicate alerts?

Nearly. KV is eventually consistent, so two copies arriving very close together could both pass. Use a Durable Object or a database unique key for exactly once.

Should the Worker answer before or after it acts?

After, when the action fits inside 10 seconds, so AyeWatch retries on failure. Before, with ctx.waitUntil, when the work is slow and you handle failures yourself.

website change alerts cloudflare workerscloudflare worker webhook hmac verificationcrypto.subtle.verify webhook signaturecloudflare kv webhook dedupewebhook relay worker

Related articles