Communication

Webhook security

How UptimeWarden signs webhook requests, where to get the signing secret and how your endpoint verifies a signature and turns away replays.

In the app: Notifications › Webhook endpoints

Your webhook endpoint sits on a URL, and anyone who learns the URL can POST to it. A fake "everything is fine" message could hide a real outage. UptimeWarden signs every request with a secret that only you and UptimeWarden know, so your endpoint can check that a request really came from UptimeWarden and has not been changed or replayed.

Get the signing secret

Each webhook has its own signing secret. You see it once:

  • When you create the webhook. Leave the Signing secret field in the Authentication step blank and UptimeWarden generates a random secret when you save. A dialog then shows it with a copy button. Copy it and store it where your endpoint reads its configuration (for example a secret manager or an environment variable), then click I've saved it.
  • When you rotate it. In the webhook list, click the key icon (Rotate signing secret) on the webhook's row and confirm. The new secret is shown once, in the same dialog.

You can also paste your own secret into the Signing secret field when you create or edit a webhook. Use a long random value. UptimeWarden does not show a secret you typed back to you.

UptimeWarden stores the secret encrypted and never shows it again: the webhook list and every later API response show it only as *****. If you lose it, rotate it.

Through the API, the secret is in the secret field of two responses only: the 201 of POST /api/webhooks/configs (when the server generated the secret) and the 200 of PATCH /api/webhooks/configs/{id} with the body {"rotateSecret": true}.

Slack, Discord, Microsoft Teams, Telegram, Google Chat and Mattermost check the secret inside their own webhook URL and ignore signatures, so the dashboard does not show a signing secret or a rotate button for them. Keep those URLs private.

What every signed request carries

When a webhook has a signing secret, every alert request carries these headers:

X-Webhook-Timestamp: 1713360123
X-Webhook-Signature-V2: sha256=e18f559a35636f97aa5f7f4b805e5a5350f90ee51616f9d1136a05e96845d958
X-Webhook-Signature: 5d5cc4a691c98c6711bcf6d5dbc4174b49ca0cdd8acb6f6abc92f4a4ff5215d7
HeaderValue
X-Webhook-TimestampThe time UptimeWarden signed the request, in Unix seconds.
X-Webhook-Signature-V2sha256= followed by the lowercase hex HMAC-SHA256 of <X-Webhook-Timestamp>.<raw body>. Verify this one.
X-Webhook-SignatureLowercase hex HMAC-SHA256 of the raw body alone, without a prefix. Kept for receivers written against the first scheme. It does not cover the timestamp, so it cannot detect a replay.

The HMAC key is the secret exactly as it was shown to you, as UTF-8 text. Do not base64-decode it. The signed body is the exact bytes UptimeWarden sent: JSON for the JSON format, text (text/plain; charset=utf-8) for the Markdown, HTML and Plain Text formats.

Requests also carry User-Agent: UptimeWarden/1.0, the Content-Type of the format and the Bearer, Basic or custom header credentials you configured. Custom headers are stored encrypted, and the values of headers whose name looks like a credential are shown as ***** in API responses and in the dashboard. See Webhooks for details.

A webhook without a secret sends the same requests without the signature headers. To start signing, rotate its secret. No header you configure, custom or otherwise, can set the signature, timestamp or event headers, so a signature on a request always comes from UptimeWarden.

Verify a request

  1. Read the raw request body before any JSON parsing. A body that was parsed and serialized again will not produce the same signature.
  2. Read X-Webhook-Timestamp and X-Webhook-Signature-V2. Reject the request if either is missing.
  3. Check that the timestamp is a whole number and within your tolerance of your own clock. We recommend 5 minutes (300 seconds).
  4. Compute HMAC-SHA256 with your secret over the timestamp, a . and the raw body. Write the result as lowercase hex and put sha256= in front of it.
  5. Compare your value with X-Webhook-Signature-V2 using a constant-time comparison. Reject the request if they differ.
  6. Only then parse the body and act on it.

Answer a rejected request with 401. UptimeWarden records a non-2xx answer as a failed delivery. It does not follow a 3xx redirect; that is a failure too.

To check your code, run it on this example. With the secret example-secret-do-not-use, the timestamp 1713360123 and the raw body {"event":"test"} (16 bytes, no spaces or trailing newline), the expected headers are the ones in the block above:

V2 signed string: 1713360123.{"event":"test"}
X-Webhook-Signature-V2: sha256=e18f559a35636f97aa5f7f4b805e5a5350f90ee51616f9d1136a05e96845d958
X-Webhook-Signature:    5d5cc4a691c98c6711bcf6d5dbc4174b49ca0cdd8acb6f6abc92f4a4ff5215d7

Node.js (Express)

import crypto from "node:crypto";
import express from "express";

const app = express();
const SECRET = process.env.UPTIMEWARDEN_WEBHOOK_SECRET;
const TOLERANCE_SECONDS = 300;

// express.raw keeps the body as a Buffer, exactly as it was sent.
app.post("/hooks/uptimewarden", express.raw({ type: "*/*" }), (req, res) => {
  const timestamp = req.get("X-Webhook-Timestamp") || "";
  const signature = req.get("X-Webhook-Signature-V2") || "";

  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (!/^\d+$/.test(timestamp) || age > TOLERANCE_SECONDS) {
    return res.status(401).send("stale or missing timestamp");
  }

  const expected =
    "sha256=" +
    crypto.createHmac("sha256", SECRET).update(`${timestamp}.`).update(req.body).digest("hex");

  const a = Buffer.from(signature);
  const b = Buffer.from(expected);
  if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
    return res.status(401).send("bad signature");
  }

  const event = JSON.parse(req.body.toString("utf8"));
  // ...handle the event
  res.sendStatus(204);
});

crypto.timingSafeEqual throws when the two buffers differ in length, so check the length first.

Python (Flask)

import hashlib
import hmac
import os
import time

from flask import Flask, abort, request

app = Flask(__name__)
SECRET = os.environ["UPTIMEWARDEN_WEBHOOK_SECRET"].encode("utf-8")
TOLERANCE_SECONDS = 300


@app.post("/hooks/uptimewarden")
def uptimewarden_hook():
    timestamp = request.headers.get("X-Webhook-Timestamp", "")
    signature = request.headers.get("X-Webhook-Signature-V2", "")

    if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
        abort(401)

    body = request.get_data()  # raw bytes, exactly as sent
    expected = "sha256=" + hmac.new(
        SECRET, timestamp.encode() + b"." + body, hashlib.sha256
    ).hexdigest()

    if not hmac.compare_digest(signature, expected):
        abort(401)

    event = request.get_json()
    # ...handle the event
    return "", 204

Replay protection

What UptimeWarden does: it puts the signing time in X-Webhook-Timestamp and includes that time in the V2 signature, so an attacker cannot change the timestamp without breaking the signature.

What UptimeWarden does not do: it does not reject anything on your side. The time window is a check your endpoint makes. Without it, a captured request still verifies and can be sent to you again later.

What your endpoint should do:

  • Reject a request whose timestamp is more than 5 minutes from your clock (step 3 above). Keep your server clock in sync with NTP.
  • Inside that window an identical copy of a request still verifies. To block those too, remember the X-Webhook-Signature-V2 values you accepted for the length of the window and reject a value you have already seen.
  • Expect the same alert more than once. When a delivery fails, UptimeWarden sends it again as a new request with a new timestamp and a new signature. Recognise a repeat by the body instead, for example by event, monitor.id, timestamp and, when present, alert.incidentId.

Rotate the secret

Rotation takes effect at once: the next request is signed with the new secret and the old one stops working. There is no overlap period, so update your endpoint right after you rotate:

  1. Click Rotate signing secret (the key icon) on the webhook's row and confirm.
  2. Copy the new secret from the dialog.
  3. Put it on your endpoint. To lose no alerts during the switch, let the endpoint accept a signature made with either the old or the new secret for a short while, then remove the old one.
  4. Click Test Webhook on the row to send a signed test request and confirm that your endpoint accepts it.

Rotate whenever the secret may have leaked, when someone who knew it leaves your team, and on your regular credential rotation schedule.

The test request

The Test Webhook button on a webhook's row sends a small JSON request with "event": "test". It carries the same three signature headers as a real alert, plus X-Uptimewarden-Event: test and X-Uptimewarden-Signature (the same value as X-Webhook-Signature), so you can check your verification code before the first real alert. The Test URL button in the wizard only checks that the address answers and sends no signature.

Protect your endpoint further

  • Use an HTTPS address so the payload and the signature do not travel in the clear.
  • Treat the signing secret like a password: keep it out of source control and logs.
  • Limit the webhook to the alert types and monitor types you need (the Targeting step).

Bu sayfayı Türkçe okuyun