Secrets rotation for WhatsApp integrations

A rotation plan for API keys, channel tokens and webhook signing secrets: inventory, overlap windows and what to do when rotation is immediate.

A WhatsApp integration holds more secrets than people count. There is the API key used to call the provider, a channel token that can send from one number, a signing secret that verifies incoming webhooks, and in some setups a long-lived Meta access token. Each one has a different failure mode when it leaks and a different procedure when it must change. This article builds a rotation plan: what to inventory, how to rotate without dropping messages and how to practise the procedure before an incident forces it.

Which secrets does the integration hold?

Start with a written inventory that names every secret, what it can do, where it lives and who can read it. Rotation is impossible for a secret nobody knows exists.

SecretWhat it can doRotation behaviour on CRPRO Hub
API key (hub_pk_...)Calls the API within its scopesCreate a new key, deploy, then revoke the old; revocation is immediate
Channel token (hub_ch_...)Sends and checks diagnostics for one channelRegenerate; the old token answers 401 immediately
Webhook signing secret (whsec_...)Proves a delivery came from the providerRotate; the old secret stops matching immediately
Customer-held keys on your platformCalls your platform APIYour own overlap design, see the per-customer keys article

If you connect customers through their own Meta app credentials, add those to the inventory too: an app secret and a system-user token that lives as long as the customer allows. The Hub documents a credentials route for that case, validating the app secret and the token before saving. Those are the customer's secrets in your custody, so they deserve the strictest handling.

Why does immediate rotation break integrations?

Because some secrets die the instant they are replaced, so any process still holding the old value fails until it is updated. The fix is a rollout order that updates every consumer before the old secret is revoked, or an overlap mechanism where one exists.

The Hub's behaviour is blunt by design. Regenerating a channel token revokes the previous one immediately, so integrations using the old hub_ch_ value receive 401 at once. Rotating a webhook secret invalidates the previous one immediately, so signatures computed with it stop matching. In each case the new value is shown only in the response of the rotation call. Plan for that: have the new value written to the vault before anything else, because losing it means rotating again.

API keys give you the overlap for free, since several keys can exist at once. Create the new key, roll it out, verify traffic on it and only then revoke the old one. The authentication page documents the scopes you will copy to the new key.

How do you rotate a webhook secret without losing events?

Accept signatures from two secrets during the changeover on your receiver, then rotate at the provider and remove the old one afterwards. Because the provider's rotation is immediate, your receiver needs to be ready for both values before you trigger it.

// receiver accepts the current and the previous secret during a rotation window const secrets = [process.env.WEBHOOK_SECRET_NEW, process.env.WEBHOOK_SECRET_OLD].filter(Boolean) function verify(rawBody, headers) { const signed = `${headers['x-hub-timestamp']}.${headers['x-hub-delivery-id']}.${rawBody}` const received = headers['x-hub-signature-256']?.replace('sha256=', '') if (!received || !/^[0-9a-f]{64}$/.test(received)) return false return secrets.some((s) => { const expected = createHmac('sha256', s).update(signed).digest('hex') return timingSafeEqual(Buffer.from(received, 'hex'), Buffer.from(expected, 'hex')) }) }

The sequence is: store the new secret in the vault as pending, deploy the receiver that accepts both, call the rotation endpoint, save the returned value as the new secret, and after a day or two, remove the old one. Deliveries that failed in the gap are not lost: the Hub keeps retrying failed deliveries and lets you replay finished ones, and the webhooks reference explains both.

How do you rotate a channel token?

Treat it as a deploy: update the consumers and rotate in one coordinated step, with a rollback plan that is simply a second rotation. Since the old token dies immediately, there is no safe period of overlap, so shorten the window instead.

  • Identify every consumer of the token from the inventory; if you cannot, that is the real finding.
  • Pause outbound jobs for the channel, or accept that a few jobs will retry after a 401.
  • Call regenerate-token, write the new value into the vault in the same script, and let consumers reload.
  • Resume jobs and watch for 401 responses from stragglers.
  • Remember that a key used for this call needs the same scopes the token carries, messages:send and templates:write.

Keep send operations idempotent. Jobs that fail with 401 during the swap are retried with the same idempotency key, so a message accepted just before the rotation is not sent twice.

What does an emergency rotation look like?

Revoke first and clean up after. When a secret is exposed, the cost of a short outage is smaller than the cost of continued exposure, and the order of operations should be written down in advance.

  • Revoke or regenerate the exposed secret at the provider immediately.
  • Check the provider audit log for use of the secret in the exposure window; the Hub log can be filtered by API key and time range.
  • Deploy the new secret and confirm traffic recovers.
  • Find how it leaked and remove the cause: a committed file, a log line, a screenshot, a ticket.
  • Rotate neighbours that shared the same storage location.
  • Tell affected tenants if their data may have been touched, using the incident process from the privacy article.

Not every audit event is visible to every credential. On the Hub, events about key creation have their metadata blanked when the caller is itself an API key, so run the forensic look-up from an interactive session, not from the compromised automation.

How often should you rotate, and how do you practise?

Rotate on a schedule that your team can sustain, and on every staff change that touched the secret, because a rotation nobody has rehearsed fails when it matters. Frequency matters less than the procedure being boring.

Put rotation in a runbook with exact commands, run it in staging quarterly and time it. Use expiry dates where the provider allows them: Hub keys accept an optional expires_at, which turns forgotten long-lived keys into scheduled work instead of silent risk. Store secrets in a manager with versioning, never in environment files committed to a repository, and give each environment its own set so a rotation in staging cannot touch production, as set out in the sandbox article of this series.

Frequently asked questions

Does rotating a webhook secret lose events?

Not if the receiver is ready. Accept both secrets briefly, rotate, and use the provider's retries and replay for deliveries that failed in the gap. On the Hub the old secret stops working immediately.

What happens to the old channel token after regeneration?

On CRPRO Hub it is revoked immediately and answers 401, so every consumer must switch to the new token right away.

Can I recover a secret I lost?

Not on the Hub: key values, channel tokens and webhook secrets are shown only once, and the only recovery is to create or rotate again.

Fontes

Documentação oficial da Meta, conferida em 31 de outubro de 2026.