Skip to content
API PlatformDevelopers

Securing sensitive operations

IP allowlists, the two-factor step-up and live keys for operations like sending a broadcast.

Most operations change one record. A few reach many customers at once and cannot be undone. Sending a broadcast is the first of these sensitive operations. It needs its own permission (broadcasts:send), and a key holds that permission only when three extra guards are in place:

  1. the key has an IP allowlist, and every send comes from an address on it;
  2. the permission was granted with a fresh two-factor code;
  3. the key is a live key.

The workspace must also allow sending broadcasts from API keys (see “Turning it on for the workspace” in Sending broadcasts).

The IP allowlist

An IP allowlist is the list of addresses a key works from. You set it when you create the key on the Keys page: one entry per line, at most 32.

  • For an ordinary key it is optional. Empty means any address.
  • For a key with broadcasts:send it is required. The key cannot be created without one.

A leaked key is the usual way an integration gets abused. With an allowlist, the key is useless anywhere but your servers, so a copy in a log, a laptop or a public repository cannot send a broadcast to your customers.

The address that counts is the one the API sees the connection come from. The API works it out from its own trusted network path and signs it for the platform, so headers such as X-Forwarded-For in your request are ignored.

What to put in it

EntryMeans
203.0.113.7One IPv4 address (the same as 203.0.113.7/32).
203.0.113.7/32The same single address, written as a block.
198.51.100.0/24A range: the 256 addresses from 198.51.100.0 to 198.51.100.255.
2001:db8:1234::/48An IPv6 range.
2001:db8::7One IPv6 address (the same as 2001:db8::7/128).
  • List your servers' outbound (egress) addresses: for a cloud function or a container platform, the static egress IP or NAT gateway address it sends from, not the address people use to reach you.
  • Keep ranges as small as you can. A /32 for each server is best. On a key that sends broadcasts no entry may be wider than /8 (IPv4) or /32 (IPv6): a wider one counts as no allowlist, and the key's sends are refused (allowlist_required).
  • If you send from both IPv4 and IPv6, list both.
  • Ranges (10.0.0.1-10.0.0.9), host names and zone ids (fe80::1%eth0) are not accepted.
Never use `0.0.0.0/0` or `::/0`. They allow every address on the internet, which is the same as having no allowlist. The Keys page refuses them, and any range wider than /8 or /32, on a key that can send broadcasts.

To change the servers a key works from, create a new key with the new allowlist, move your integration to it, then revoke the old key.

When a request comes from somewhere else

A key used from an address outside its allowlist is refused on every operation, like an unknown key (401 unauthenticated), so the answer never tells a caller which addresses are allowed. On a broadcast send, the platform checks the signed address against the allowlist again. A mismatch there is refused with 403 forbidden and reason: ip_not_allowed:

{
  "type": "https://dev.wa-api.cloud/errors/forbidden",
  "title": "Not allowed",
  "status": 403,
  "detail": "The request came from an address outside the key's IP allowlist. Nothing was sent.",
  "code": "forbidden",
  "reason": "ip_not_allowed",
  "request_id": "req_01J9EXAMPLE0000000000000000"
}

Nothing is sent. Check which address your server really sends from (for example, call a what-is-my-IP service from that server), then either call from an allowed server or create a key whose allowlist includes it.

A key with broadcasts:send but no allowlist cannot be created. If one is ever missing its allowlist, or its allowlist is wider than that, its sends are refused with reason: allowlist_required.

The two-factor step-up

Granting broadcasts:send needs a fresh two-factor code from the person creating the key, every time. It is a strict check:

  • two-step sign-in must be set up on their account: without it the permission cannot be granted at all, even in a workspace where keys can otherwise be made without a code;
  • the code is used once, for that one key;
  • the person must be allowed to send broadcasts in the app themselves.

After that, the key sends without a code on each call: the code was given when the permission was granted, and the allowlist and the live key guard every call. The key acts as the person who made it. If they lose permission to send broadcasts, or leave the workspace, the key's sends stop at once.

Live keys only

broadcasts:send is for live keys. A test key never sends a broadcast: POST /v1/broadcasts with a test key always answers a preview in sandbox mode, and a real send asked of a test key is refused with reason: key_not_live. Use a test key, or ?dry_run=true, while you build, then a live key with the permission to send.

The checklist

  • A workspace admin allowed sending broadcasts from API keys.
  • You can send broadcasts in the app, and two-step sign-in is set up on your account.
  • A live key with messaging:write and broadcasts:send, and an allowlist of your servers' outbound addresses (never 0.0.0.0/0).
  • The key stored as a secret on those servers, never in a browser or a repository.
  • Your code previews with ?dry_run=true first, then sends with Api-Confirm: send and an Idempotency-Key.
  • Someone watches the admins' notifications and knows how to pause or stop a broadcast.

See Keys and permissions for everything else about keys.