Verify webhooks from Terapi

Step-by-step guide on how to verify the signatures of webhooks from Terapi.

Validate webhook provenance by looking at the X-Terapi-Signature header.

It's a SHA-256 hash generated using the secret key found in the Environment Settings in the Terapi UI.

The webhook signature can be generated with the following code:

import crypto from 'crypto';

const secretKeyDev = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
const signature = `$$`;
const hash = crypto.createHash('sha256').update(signature).digest('hex');
import hashlib
import json

secret_key_dev = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
signature = f""
hash = hashlib.sha256(signature.encode('utf-8')).hexdigest()
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.bind.DatatypeConverter;

public class Main 
}

Only accept a webhook if the X-Terapi-Signature header value matches the webhook signature.

Last updated