Skip to content

Custom headers, the firewall and webhooks

Add security and robots headers to your pages, allow or block visitors by country, address and path, and send your site's events to your own address.

4 min readENFRNLDE
On this page 4 sections

Where

Site menuCustom headers…Open in the editor

These three are in the site menu. Owners and admins set them, or designers for custom headers, and each needs a plan that includes it.

Custom headers

Choose Custom headers…. A rule says which Path gets which Header with which Value. The edge adds it to the pages there, beside the site's own headers. You can add rules, never remove one: security headers stay as they are. Publish to send them.

  • Path: starts with /, with no spaces, ? or #. It covers that page in every language. End it with /* for everything under it.
  • Header: Content-Security-Policy (directives separated by ;, enforced beside the site's own, so it can only restrict), X-Robots-Tag (such as noindex), Reporting-Endpoints, or a Link resource hint such as preconnect.
  • A site can have a limited number of custom headers. A rule that is wrong is marked, and Save waits.

Firewall

Choose Firewall…. It decides which visitors the site's edge serves, by country, address range and path, and how many requests one address may make. Rules work at once, without a publish.

  1. Select Add a rule. Choose what it does: Allow, Block or a Rate limit.
  2. Set its conditions: Countries (two-letter codes such as BE or NL), Address ranges (IPv4 or IPv6, one per line, such as 192.0.2.0/24) and Path starts with. A condition you leave empty means any.
  3. The first rule that matches a visitor decides, so the order matters. Use the arrows to move a rule. A visitor that no rule matches is served.
  4. Save the rules. Turn the firewall off serves every visitor.

A path rule doesn’t hide a page from search engines or the sitemap. To keep a page private, put it behind the password gate.

Each rule shows what it blocked or limited in the last 8 days, as counts only. The firewall comes with a contract; rules already set can still be removed.

Webhooks

Choose Webhooks…. It sends the site's events to your own https address as signed JSON.

  1. Select Add webhook, enter the Address and choose Send when: A collection item is added, A collection item is changed, A collection item is deleted or The site is published.
  2. Copy the signing secret when it is shown. It is shown only once. The receiver checks each request's X-Xs-Signature header with it, as described in "Verify the signature" below.
  3. Make a new secret replaces it; the current one keeps signing for 24 hours so you have time to update the receiver.

Each endpoint has a Delivery log with every attempt, newest first, and Send again. The address must be reachable from the internet, and must answer with a 2xx status within 10 seconds, or the attempt counts as failed.

A failed send is tried again up to 7 more times, 8 attempts in all. Each retry comes after the wait below, counted from the end of the failed attempt:

AttemptSent after the failed one before itTime since the first attempt
1at once0
21 minute1 minute
35 minutes6 minutes
430 minutes36 minutes
52 hours2 hours 36 minutes
66 hours8 hours 36 minutes
712 hours20 hours 36 minutes
824 hours44 hours 36 minutes

So a failing event is tried for a little over 44 and a half hours, plus up to 10 seconds for each attempt that times out. After 50 failed attempts in a row, whichever events they were for, the endpoint turns off and sends nothing more until you choose Turn on again.

Verify the signature

Each request is a POST with the event as JSON in its body, and these headers:

HeaderValue
X-Xs-Signaturet=<unix seconds>,v1=<signature>: the time it was signed, and one v1= per secret (two for 24 hours after a new secret, so either one matches)
X-Xs-Event-IdThe event's ID: the same on every attempt of the event, and on Send again
X-Xs-Event-TypeThe event, such as site.published
X-Xs-Delivery-Attempt1 for the first attempt, up to 8

The signature is the hex HMAC-SHA256, with your signing secret as the key, of the text <t>.<body>: the number from t=, a dot, and the body exactly as it arrived. Check it on the raw body, before you parse the JSON, and compare in constant time. Refuse a t more than 5 minutes from your clock; every attempt is signed again, so a retry carries a fresh t.

js
import { createHmac, timingSafeEqual } from 'node:crypto';

export function isValid(secret, header, rawBody) {
  const parts = header.split(',');
  const t = parts.find((p) => p.startsWith('t='))?.slice(2);
  if (!t || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  return parts
    .filter((p) => p.startsWith('v1='))
    .some((p) => {
      const given = Buffer.from(p.slice(3), 'hex');
      return given.length === expected.length && timingSafeEqual(given, expected);
    });
}
python
import hashlib
import hmac
import time


def is_valid(secret: str, header: str, raw_body: bytes) -> bool:
    items = [part.split("=", 1) for part in header.split(",") if "=" in part]
    t = next((v for k, v in items if k == "t"), "")
    if not t.isdigit() or abs(time.time() - int(t)) > 300:
        return False
    signed = t.encode() + b"." + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest().encode()
    return any(hmac.compare_digest(v.encode(), expected) for k, v in items if k == "v1")

Delivery is at least once

An event can arrive more than once, after a retry or Send again. Keep the X-Xs-Event-Id values you have handled and skip a repeat.