An API (application programming interface) lets one piece of software talk to another. Your mobile app talks to your server through an API; your partners may place recharges or verify customers through your API; your website may call payment, SMS or KYC APIs. Because APIs are designed for machines, they are easy for attackers to probe automatically, and problems are often invisible from the normal user interface.
This guide covers the controls every business API should have, whether you build your own or consume ours.
1. Authenticate every request
Every API call should prove who is making it. Common methods:
- API keys: a secret string issued to each client. Simple and common for server-to-server calls.
- Tokens: short-lived credentials issued after login, typical for mobile and web apps.
- Request signing: the client signs each request with a secret, so tampering is detectable.
Keys must never be placed in a mobile app, browser JavaScript or a public code repository, where anyone can extract them. Calls needing secret keys should go through your own server.
2. Authorise every object
Authentication says who you are; authorisation says what you may access. The most common API flaw is checking the first but not the second. If /api/orders/1052 returns an order, the server must confirm that order belongs to the caller. Do this on every endpoint, for read, update and delete actions alike.
3. Validate input strictly
- Reject unexpected fields and types.
- Check ranges: amounts cannot be negative, quantities have limits.
- Never trust prices or totals sent by the client; calculate them on the server.
- Use parameterised database queries to prevent injection.
4. Return only what is needed
APIs often return entire database records when the app needs two fields. Extra fields, such as internal IDs, other users' details or hashed passwords, can leak. Design responses deliberately and mask sensitive values such as account numbers and ID numbers where full values are not needed.
5. Rate limiting and quotas
Limit how many requests each client can make in a time window. This protects against brute-force attempts, scraping and accidental loops in a partner's code, and it keeps your service available for everyone else.
6. Network restrictions
For server-to-server APIs, IP whitelisting (accepting calls only from registered server addresses) adds a strong extra layer. We recommend enabling it wherever it is offered, including on our own recharge and payout APIs.
7. Use HTTPS everywhere
All API traffic must be encrypted with HTTPS. Never accept credentials or personal data over plain HTTP, even in testing environments that reach real data.
8. Secure your webhooks
A webhook (callback) is when another system calls your server to report an event, such as a recharge status update or a payment confirmation. Attackers can send fake callbacks. Protect them by:
- Verifying a signature or shared secret on every callback.
- Restricting accepted source addresses where possible.
- Re-checking the transaction status with the provider before crediting or refunding money.
- Handling duplicate callbacks safely (idempotency), so the same event cannot be processed twice.
9. Log, monitor and alert
Log each request with the client identity, endpoint, result and timing, without storing secrets or full sensitive data in the logs. Watch for spikes in errors, unusual volumes and calls from new locations, and alert someone who can act.
10. Manage keys over their lifetime
- Issue separate keys per client and per environment (test and live).
- Rotate keys periodically and immediately if a leak is suspected.
- Revoke keys for partners who leave.
- Store keys in environment configuration or a secrets store, not in code.
11. Version and document
Keep an inventory of all your API endpoints, including old versions. Forgotten endpoints from an earlier app release are a common weak point because they miss later security fixes.
Example
Neha's team built a mobile app for her salon chain with an API for bookings. A review found the API returned every customer's phone number in the "available slots" response, because the developers reused a full booking object. Trimming the response and adding ownership checks closed the leak without changing the app's appearance at all.
Quick API security checklist
- Every endpoint authenticated and authorised per object.
- No secrets in apps or front-end code.
- Strict input validation and server-side calculations.
- Rate limits, IP whitelisting where possible, HTTPS only.
- Signed, verified webhooks with idempotent handling.
- Logging and alerting in place.
Need help securing an API?
We design and secure APIs as part of our API integration and development service and review existing APIs during an application audit. Developers can read our API documentation for the security options on our own APIs. Contact us for a review.
0 comments