# `verify_webhook_signature` — Verify Webhook HMAC Signature

> Part of [HookSink Webhook Inbox & Signature Verifier API](https://hook-sink.apikeg.com/llms.txt) (`com.apikeg/hook-sink`)

Statelessly verifies webhook HMAC-SHA256 signatures and replay timestamps across Stripe, GitHub, Shopify, Slack, Linear, or custom headers using constant-time Web Crypto comparison.

**Why call instead of DIY:** Prevents subtle raw-body serialization bugs, hex vs. base64 mismatches, timing side channels, and Stripe/Slack timestamp replay vulnerabilities.

- **REST Endpoint:** `POST https://hook-sink.apikeg.com/v1/verify-webhook-signature`
- **MCP Server:** `https://hook-sink.apikeg.com/mcp` (tool: `verify_webhook_signature`)
- **Pricing:** $0.001 USD per stateless signature verification (x402 instant micropayment)
- **Free Dry-Run:** `POST https://hook-sink.apikeg.com/v1/verify-webhook-signature?dry_run=true`

## Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "provider": {
      "type": "string",
      "enum": [
        "auto",
        "stripe",
        "github",
        "shopify",
        "slack",
        "linear",
        "generic_sha256"
      ],
      "default": "auto",
      "description": "Webhook signature provider preset (auto, stripe, github, shopify, slack, linear, generic_sha256)."
    },
    "rawBody": {
      "type": "string",
      "maxLength": 262144,
      "description": "Exact raw UTF-8 HTTP request body string as delivered by the webhook sender."
    },
    "headers": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "HTTP request headers map containing the webhook signature header(s)."
    },
    "secret": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "description": "Webhook HMAC signing secret (e.g., whsec_... for Stripe)."
    },
    "toleranceSeconds": {
      "type": "integer",
      "minimum": 0,
      "maximum": 86400,
      "default": 300,
      "description": "Timestamp replay-window tolerance in seconds for Stripe and Slack (default 300)."
    },
    "signatureHeader": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Optional custom signature header name when provider is generic_sha256 or linear."
    },
    "nowSeconds": {
      "type": "integer",
      "minimum": 0,
      "description": "Optional Unix epoch timestamp (seconds) override for deterministic replay checks."
    }
  },
  "required": [
    "rawBody",
    "headers",
    "secret"
  ],
  "additionalProperties": false
}
```

## Examples
### Verify a Stripe webhook signature
```bash
curl -X POST "https://hook-sink.apikeg.com/v1/verify-webhook-signature" \
  -H "Content-Type: application/json" \
  -d '{"provider":"stripe","rawBody":"{\"id\":\"evt_123\",\"type\":\"checkout.session.completed\"}","headers":{"Stripe-Signature":"t=1700000000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"},"secret":"whsec_test_secret","toleranceSeconds":300}'
```
