Guides for integrators

Security best practices

On this page

A key and a signing secret open the doors of a store. These habits keep them closed. They cost little and most of them are done once.

Give each system the smallest key#

  • Make one key for each system, named after it. If one key leaks or a system is retired, only that key is rotated or revoked.
  • Tick only the scopes the system uses (read:products, write:products, read:orders, write:orders, read:inventory, write:inventory, read:customers, read:categories). A key that only reads cannot change anything, even if it leaks. The scopes
  • The personal details option shows full emails and phone numbers of contacts. Keep it off unless the system needs them.
  • A key can never do more than the person who made it, and only a Super Admin can give write scopes. Nothing can refund, take payment or touch coupons, whatever the key.

Keep keys and secrets out of sight#

  • Keep keys and webhook secrets in a secret manager or an environment variable on your server. Never in the code, a repository (also a private one), a web page, a mobile app, a screenshot, a ticket or an email.
  • Call the API from your servers only. A key used in a browser or an app can be read by anyone who uses it.
  • Do not put the key in the address of a request. It is read from the headers only, and an address ends up in logs and history.
  • Keep keys out of logs and error reports. Log the first characters if you must tell keys apart: the admin shows the same beginning of each key.
  • Hand a key to a colleague through a password manager or secret manager, not through chat.

Limit where a key works#

  • If your server has fixed addresses, set the allowed addresses of the key (up to 50; IPv4, IPv6 or ranges). A stolen key then fails from anywhere else with 403 ip_not_allowed. If the store sits behind a CDN or proxy, the store must be set up to see the real visitor address.
  • Give keys for temporary work an expiry date. The key works until the end of that day.
  • Set the requests per minute to what the system needs, not more.

Rotate on a plan#

  • Rotate keys when a person with access leaves, when a system changes hands, and on a calendar you choose.
  • Rotate secret on a key gives it a new secret and the old one stops at once. For a change without a gap, make a second key with the same scopes, move your software to it, then revoke the first.
  • A webhook secret is different: after Rotate secret the old one keeps signing for 24 hours, and every message carries both signatures. Deploy the new secret within that time and your receiver never misses a message.
  • Pause switches a key off for now and can be undone. Revoke is permanent.

Check every webhook#

  • Anyone who knows your address can post to it. Check the signature of every message on the raw body, with a constant-time comparison, and reject a time more than 5 minutes away. Working code
  • Use an https address, and answer 400 when the check fails. Do not process a message that fails.
  • For decisions about money or shipping, read the thing again from the API before you act (for example the order's payment_status). The message tells you something happened; the API tells you the state now.
  • The signing secret belongs to one endpoint. Do not share one endpoint (and one secret) between systems.

Make repeats harmless#

  • Send an Idempotency-Key on every POST and PATCH, and keep it with your record. A network failure then never creates a second product or adds stock twice. How it works
  • Keep the event id of every webhook you handled and ignore an id you have seen. The same event arrives again after a retry or a Redeliver.
  • Write handlers that can run twice: "set the order to packed", not "add one to a counter".

Be gentle with limits and errors#

  • Retry only 429, 500, 503 and network failures, after the Retry-After wait or a growing pause. Never retry a 400-level error unchanged: it will fail the same way.
  • Stop and alert when you see repeated 401 or 403: the key was revoked, paused, expired or used from the wrong address. 10 wrong keys within 5 minutes lock that address out for a while.
  • Use updated_since and limit=100 to read less, not more.

Protect customers' personal data#

  • Orders always carry the customer's name, contact details and delivery address, because shipping needs them. Give read:orders only to systems that need it.
  • On a webhook endpoint that does not need personal details, switch off Include customers' personal details.
  • Store only what you need, protect it, and delete it when you no longer need it. Never write it to logs.
  • A store can Redact personal details from a stored delivery in its own log. That does not touch your copies: you are responsible for them.

Watch for trouble#

  • The store's Request log lists every call of every key (address, result, time, never what was sent). A call you do not recognise, or a burst at a strange hour, means the key is being used by someone else.
  • The Delivery log shows what your endpoint answered. Repeated failures switch the endpoint off after 20 deliveries are given up on in a row.
  • Log your own failed calls and alert on them.

If a key or secret may have leaked#

  1. Rotate or revoke it now in the store's admin (Settings > API & webhooks). For a webhook, Rotate secret and then switch your receiver to the new one; the old one stops signing after 24 hours.
  2. Put the new secret in your secret manager and deploy it.
  3. Look at the Request log (and the audit log) for calls you do not recognise since the key was exposed.
  4. Tell the store's owner what happened. If personal data may have been read, they will need to know.
  5. Find out how it leaked and close that door.

To report a security problem in GroKeeper itself, write privately to the address under Report a security problem. Please do not post keys or personal data anywhere public.