Short answer: compute an HMAC (SHA-256 is the safe, widely supported default) over the raw request body with the shared secret, compare it to the signature header in constant time, and reject the request on any mismatch. Do all of that before you parse the JSON, render anything, or publish anything.

A webhook endpoint is just a public POST route. On a headless blog, a request that slips through can put fake or tampered articles on a live page, so the check has to fail closed.

Why content webhooks need verification

If your site receives each article as a JSON payload, the endpoint decides what your readers (and Google) see. Without verification, anyone who finds the URL can send a plausible article with spam links. Signing the payload is one way to authenticate webhooks.

The idea is simple: the sender signs the payload with a secret only you and the sender know. You recompute the signature and compare. A match means the body came from the secret holder and was not changed in transit.

The verification flow, step by step

Verification flow. Capture the raw bytes → Read signature and timestamp headers → Recompute the HMAC with your secret → Compare in constant time → Only then parse the JSON

  1. Capture the raw bytes. Do not let a JSON middleware parse and re-serialize the body first. Re-serialization can change whitespace and key order, so your hash will not match.
  2. Read the signature (and the timestamp, if your sender provides one) from headers. Reject the request if the signature, or a timestamp your scheme requires, is missing.
  3. Recompute the HMAC over exactly what the sender signs, using your stored secret.
  4. Compare in constant time. StateSet's webhook documentation uses constant-time comparison in its Node.js and Python examples (timingSafeEqual, compare_digest) and says to reject missing signatures in production.
  5. Only then parse the JSON and validate its shape.

Here is a vendor-neutral sketch. The header names and the signed string are placeholders, not any real provider's scheme; take the exact format from your sender's documentation.

import crypto from 'node:crypto';
import express from 'express';

const app = express();

app.post('/webhooks/articles',
  express.raw({ type: 'application/json' }), // req.body is a Buffer
  (req, res) => {
    const sig = req.get('X-Example-Signature') ?? '';
    const ts = req.get('X-Example-Timestamp') ?? '';

    // 1. freshness check (see replay section)
    const age = Math.abs(Date.now() / 1000 - Number(ts));
    if (!Number.isFinite(age) || age > 300) return res.sendStatus(401);

    // 2. recompute over the raw bytes
    const expected = crypto
      .createHmac('sha256', process.env.WEBHOOK_SECRET)
      .update(`${ts}.`)
      .update(req.body)
      .digest('hex');

    // 3. constant-time compare (lengths must match first)
    const a = Buffer.from(sig);
    const b = Buffer.from(expected);
    if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
      return res.sendStatus(401);
    }

    // 4. only now parse
    const article = JSON.parse(req.body.toString('utf8'));
    // validate, sanitize, store as draft or publish
    res.sendStatus(200);
  });

Replay protection

Replay protection at a glance. Example timestamp tolerance window: ±5 min; Article ID or slug used to make writes idempotent: 1 ID

A valid signature proves origin and integrity, not freshness. An attacker who captures one signed request can resend it. Replay protection is the receiver's job. It works best when the sender includes a timestamp and a unique message ID, both covered by the signature; otherwise an attacker can edit them.

For article payloads:

  • Reject stale timestamps outside a tolerance window. The five-minute window in the sketch above is only an example; choose a value that allows for clock drift and delivery delay.
  • Make the write idempotent on the article's ID or slug, so a replay or accidental duplicate delivery updates the same record instead of creating a second post.
  • Because old timestamps are rejected, you only need to remember recent message IDs, not every ID ever seen.

If your sender does not provide a signed timestamp, idempotency on the article ID is your main defense, so check what the sender actually signs.

Common failure modes

  • Parsing before hashing. Hash the raw bytes, not a re-encoded object.
  • Weak primitives. Use a real HMAC rather than a homemade scheme like hash(key + payload), and follow the algorithm your sender documents.
  • Shared secrets. Reusing one secret across endpoints means a compromise of one destination lets an attacker forge payloads for all of them. Use one secret per endpoint.
  • Low-entropy secrets. Use long random values for secrets.
  • Verification that can be switched off. A bypass flag or environment variable that disables checks in production gives false confidence. Make production refuse to start if the secret is missing.
  • Wrong URL or body behind a proxy. For schemes that sign the URL (StateSet's Twilio example does), the public URL seen by the verifier must match the signed one. For body-only schemes, make sure no proxy or middleware rewrites the body.

Secret management and rotation

Store the secret in your host's secret manager or environment, never in the repo or client bundle, and never log it or the full signature. For rotation, StateSet's docs recommend a previous-token overlap window and clearing audit logs when rotation completes. In practice: accept signatures from the new and previous secret for a short period, then drop the old one.

Fail closed

Return a 401 or 403 on a bad or missing signature and stop. Log the reason (missing header, stale timestamp, mismatch), the request ID and source IP, but not the secret or the body of unverified content. Never write unverified payloads to your database or build pipeline, even as drafts.

A test plan for a content webhook

Write these as automated tests against your handler:

Case Expected result
Valid signature, fresh timestamp 200, article stored
Valid signature, then the same request again No duplicate article (idempotent)
One character changed in the body 401, nothing stored
Body re-serialized with different whitespace 401 (proves you hash raw bytes)
Missing signature header 401
Timestamp outside tolerance 401
Signed with the old secret during overlap 200
Signed with the old secret after rotation ends 401
Signature of different length 401, no exception thrown

Verified does not mean safe to render

A signature proves who sent the content, not that the HTML is harmless. Sanitize article HTML with an allowlist-based sanitizer before rendering, validate required fields and URL schemes, and restrict where embedded scripts or iframes can come from (for example with a Content Security Policy). If the sender is ever compromised, this is your second layer.

Where PilotScribe's webhook fits

If you use PilotScribe, its docs say the webhook option lets you receive each article as signed JSON on your own endpoint and render it your way, and its MCP guide lists a webhook among the publishing options. The supplied documentation excerpts do not state the header name, algorithm, timestamp handling or rotation process, so read the webhook guide linked from the docs before implementing, and adapt the placeholders above to it.

Pre-launch checklist

  • Raw body captured before any parsing
  • HMAC-SHA256 (or the sender's documented scheme) recomputed exactly as specified
  • Constant-time comparison, with a length check first
  • Missing or invalid signature rejected; no environment flag disables this in production
  • Timestamp tolerance enforced and idempotency on article ID
  • Unique secret per endpoint, high entropy, stored in a secret manager
  • Rotation procedure with an overlap window, tested
  • Failures logged without secrets or unverified content
  • HTML sanitized and validated before rendering
  • All test cases in the table passing in CI

FAQ

Can I just keep the endpoint URL secret? No. URLs leak through logs, referrers and config files. Treat the URL as public and rely on the signature.

Why not parse the JSON first and sign the object? Different serializers produce different bytes for the same data. Verify what was actually sent, then parse.

Is a signature enough for security? It handles authenticity and integrity. You still need replay protection, secret hygiene and safe rendering.