# Replace a webhook's signing secret (/build/replace-a-webhook-secret)

Give a webhook a new signing secret after a leak, a lost answer or as routine, without deleting it, and keep its deliveries arriving while the receiver changes over.



A webhook's secret signs each delivery, and Marfa shows it only in the answer that makes it. Replacing it keeps the webhook: its `url`, `events`, `type_filter`, pending deliveries and delivery history stay as they were. **Only the key or app that registered the webhook can replace its secret.** [Receive webhooks](/build/receive-webhooks) shows how a receiver checks the signature.

## Replace the secret [#replace-the-secret]

[Replace a webhook's secret](/reference/api/webhooks/replaceWebhookSecret) answers the webhook with its new `secret`, the only time it is shown:



**CLI**

```bash  
marfa webhooks replace-secret <webhook-id>
```

**HTTP**

```http
POST /webhooks/<webhook-id>/secret
Authorization: Bearer <key>
Content-Type: application/json

{}
```

Marfa generates a secret of 64 hexadecimal characters. An agent at `/mcp/admin` calls `marfa_manage_webhook` with `action` set to `replace_secret` and the webhook's `id`.

**If you lose the answer, replace the secret again.** Changing the secret raises the webhook's `version`, and the [audit log](/use/audit-log) records it as `webhook.secret.replace`, without the secret.

## Keep deliveries arriving [#keep-deliveries-arriving]

Marfa signs with one secret at a time. **Every request it sends after the replacement carries the new secret's signature,** retries and redeliveries of older events included. A request already on its way keeps the signature it was sent with.

A receiver that still holds only the old secret refuses those requests, and a refusal such as `401` ends a delivery as `failed`. To lose none, change over in this order:

### Make the receiver accept both secrets [#make-the-receiver-accept-both-secrets]

Choose the new secret yourself, of at least 32 characters, and have the receiver accept a signature under either one.

### Replace the secret with the one you chose [#replace-the-secret-with-the-one-you-chose]



**CLI**

```bash  
marfa webhooks replace-secret <webhook-id> --secret <new-secret>
```

**HTTP**

```http
POST /webhooks/<webhook-id>/secret
Authorization: Bearer <key>
Content-Type: application/json

{ "secret": "<new-secret>" }
```

A shorter secret is refused `400 validation_error`. The CLI doesn't print back a secret you gave.

### Drop the old secret [#drop-the-old-secret]

Once deliveries verify under the new secret, remove the old one from the receiver.

After a leak, replace the secret first and repair afterward: [redeliver](/build/receive-webhooks#handle-a-failed-webhook-delivery) each delivery that `failed` meanwhile.

The rules are in the [events](https://github.com/withmarfa/marfa/blob/main/conformance/spec/events.md#eventswebhook-secret-replace) chapter of the contract.
