> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify webhook signatures

> Every webhook is signed with HMAC-SHA256 of the timestamp and raw body. Verify it with the SDK for JavaScript, Python, Go, Ruby or PHP.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Accept only genuine, recent webhooks from StackShift.

## Prerequisites

* A destination and its signing secret (whsec\_…), shown once when you add it.

## Workflow

**Step 1**

Store the signing secret as an environment variable, for example STACKSHIFT\_WEBHOOK\_SECRET.

**Step 2**

Read the request body as raw bytes, before any JSON parsing.

**Step 3**

Call the SDK verify function with the raw body, the StackShift-Signature header and the secret.

**Step 4**

Answer 2xx quickly, and drop events whose id you have already handled.

## Headers

* StackShift-Signature: t=\<unix seconds>,v1=\<hex>, where v1 is HMAC-SHA256 with your secret over "\<t>." followed by the raw body.
* StackShift-Timestamp, StackShift-Event-Id, StackShift-Event-Type and StackShift-Delivery-Id.
* The SDKs refuse signatures more than 300 seconds from now. Errors carry a code: missing\_signature, invalid\_signature, expired or invalid\_body.
* Rotate a secret with Make a new secret on the destination. Mail webhooks keep their existing body and signature, so receivers built for Mail keep working.

## Verify with an SDK

Each verify call returns the parsed event when the signature is valid and throws or returns an error otherwise.

```ts Verify theme={null}
import { verifyEvent } from '@stackshift-cloud/sdk'

const event = verifyEvent({
  rawBody,
  signatureHeader: req.headers['stackshift-signature'],
  secret: process.env.STACKSHIFT_WEBHOOK_SECRET!,
})
```

```ts JavaScript theme={null}
import { verifyEvent } from '@stackshift-cloud/sdk'

const event = verifyEvent({
  rawBody,
  signatureHeader: req.headers['stackshift-signature'],
  secret: process.env.STACKSHIFT_WEBHOOK_SECRET!,
})
```

```python Python theme={null}
import os
from stackshift import verify_event

event = verify_event(
    raw_body=request.get_data(),
    signature_header=request.headers.get('StackShift-Signature'),
    secret=os.environ['STACKSHIFT_WEBHOOK_SECRET'],
)
```

```go Go theme={null}
event, err := stackshift.VerifyEvent(stackshift.VerifyEventInput{
	RawBody:         body,
	SignatureHeader: r.Header.Get("StackShift-Signature"),
	Secret:          os.Getenv("STACKSHIFT_WEBHOOK_SECRET"),
})
if err != nil {
	http.Error(w, "invalid signature", http.StatusBadRequest)
	return
}
```

```ruby Ruby theme={null}
require "stackshift/events"

event = StackShift::Events.verify(
  raw_body: request.raw_post,
  signature_header: request.headers["StackShift-Signature"],
  secret: ENV.fetch("STACKSHIFT_WEBHOOK_SECRET")
)
```

```php PHP theme={null}
$event = \StackShift\Events::verify(
    file_get_contents('php://input'),
    $_SERVER['HTTP_STACKSHIFT_SIGNATURE'] ?? null,
    getenv('STACKSHIFT_WEBHOOK_SECRET'),
);
```

## Error types

* JavaScript: EventSignatureError with code. Python: EventSignatureError with code. Go: \*stackshift.EventSignatureError with Code. Ruby: StackShift::EventSignatureError with code. PHP: StackShift\EventSignatureError with errorCode.
* Every SDK takes an optional tolerance: toleranceSeconds in JavaScript, tolerance\_seconds in Python, Tolerance in Go, tolerance in Ruby and the fourth argument in PHP.

## Expected result

> [!TIP]
>
> Your endpoint rejects forged, altered or replayed requests and processes each event once.

## Common failures

> [!WARNING]
>
> * invalid\_signature on every request: the body was parsed and re-serialised before verifying. Use the raw bytes.
> * expired: the server clock is wrong, or the request was queued for more than 5 minutes.

## Related guides

> [card] [Retries, replay and the dead-letter list](https://docs.stackshift.cloud/events/retries-and-replay.md)
>
> Failed deliveries retry 8 times over about 2 days. After the eighth failure the delivery goes to the dead-letter list, the destination or rule is turned off, and the owner gets an email.

> [card] [Targets](https://docs.stackshift.cloud/events/targets.md)
>
> Send a matched event to a webhook, a Function, a durable queue or waiting job, a hosted agent or Stackie, Slack, email or the dashboard, or an automation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.