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

# Segurança

> Verificação de assinatura HMAC nos webhooks

# Segurança do Webhook

O Grwthy verifica automaticamente a autenticidade dos eventos recebidos do WhatsApp usando assinaturas HMAC-SHA256.

## Como Funciona

1. Cada evento do WhatsApp contém uma assinatura no header `X-Hub-Signature-256`
2. O Grwthy verifica a assinatura usando o `appSecret` da instância
3. Eventos com assinatura inválida são rejeitados com `403 Forbidden`

```
Evento recebido do WhatsApp
   Header: X-Hub-Signature-256: sha256=<hmac_hex>
   Body: { ... payload do evento ... }
              ↓
   Instância identificada pelo phone_number_id
              ↓
   Assinatura verificada com appSecret
              ↓
   ✅ Válida → evento processado
   ❌ Inválida → 403 Forbidden
```

## Respostas de Erro

| Status | Cenário                                               |
| ------ | ----------------------------------------------------- |
| `403`  | Header de assinatura ausente                          |
| `403`  | Nenhuma instância encontrada para o phone\_number\_id |
| `403`  | Instância está inativa                                |
| `403`  | Assinatura não corresponde                            |

## Verificando Webhooks no Seu Servidor

Se você configurou um webhook na instância, recomendamos verificar a autenticidade das requisições no seu servidor. Use os `headers` customizados como um token secreto:

```bash theme={null}
curl -X POST https://grwthy.com/v1/instances \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: SUA_API_KEY" \
  -d '{
    "instanceName": "minha-loja",
    "phoneNumberId": "123456789012345",
    "accessToken": "EAAx...",
    "webhook": {
      "url": "https://meusite.com/webhook",
      "enabled": true,
      "headers": {
        "X-Webhook-Secret": "meu-token-secreto"
      }
    }
  }'
```

No seu servidor, valide o header `X-Webhook-Secret` em cada requisição recebida.
