API security
Authenticate every call with scoped tokens, authorise every object, and keep secrets out of addresses. Link to the security playbook for the attacks.
- Required 6
- Recommended 2
Required
Authenticate with tokens in headers
API-38Authenticate API calls with short-lived tokens in the
Authorizationheader, issued through OAuth 2 for anything acting for a user.Grant narrow scopes
API-39Give each token only the scopes its job needs, and check the scope on every endpoint.
Authorise every object
API-40Check on every request that the caller may access the exact object, not just the endpoint.
Keep secrets out of addresses
API-41Never put tokens, keys or personal data in paths or query strings. Send them in headers or the body. The one exception is a capability link that is short-lived, scoped to one object and action, and single-use where the store allows it.
Store API keys as hashes
API-42Show each API key once, store only its hash, and let clients hold two keys at a time so they can rotate.
Refuse plain HTTP on the API
API-43Serve the API over HTTPS only. Refuse plain HTTP calls with an error instead of redirecting them.
Recommended
Bind high-value tokens to the client that holds them
API-95For tokens that move money, read personal data in bulk or act for another party, bind each token to a key the client holds. Use DPoP or mutual TLS, and refuse a bound token sent without proof of that key.
List every API you run
API-44Keep a list of every API, version and host you expose, and switch off what is no longer used.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/api-security">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.