API Keys and IP Whitelisting: How to Secure Your API Access

When you work with recharge, bill payment, payout or verification APIs, your API key is effectively a spending authority on your account. Anyone who has it can use your balance or run verifications in your name. This post explains how API keys and IP whitelisting work together and how to set them up properly.

What an API key is

An API key is a long, random secret string issued to your account. Your server sends it with every request, usually in a header such as Authorization: Bearer YOUR_API_KEY. The provider looks it up, identifies your account and decides what you are allowed to do.

A key proves "this request comes from someone who knows the secret". It does not prove the request comes from you. That is why a second check is so useful.

What IP whitelisting adds

IP whitelisting means the provider accepts requests for your account only from a list of server IP addresses you register. Even if your key leaks, an attacker calling from their own machine is rejected, typically with a 403 Forbidden.

Two practical consequences:

  • You need a server with a fixed (static) public IP. Shared hosting plans often send outgoing traffic from changing IPs; a VPS or dedicated server is more predictable. If you need one, our sister company DomainsRock offers VPS and server plans.
  • Calls must go from your server, not directly from a browser or a mobile app. Your app talks to your server; your server talks to the API.

Where to keep your key

The rule is simple: the key lives on the server, outside your code repository.

  • Use environment variables or a configuration file outside the web root, and exclude it from version control.
  • Never put the key in JavaScript sent to the browser, in an Android or iOS app, or in a public repository.
  • Restrict file permissions so only the application user can read the configuration.
  • Do not paste keys into chat groups, emails or support tickets. Our support team will never ask for your full key.

A Laravel example, reading from .env:

// .env (never committed)
PEPPLO_API_KEY=YOUR_API_KEY
PEPPLO_API_BASE=https://www.pepploweb.com/api/services/v1

// config/services.php
'pepplo' => [
    'key'  => env('PEPPLO_API_KEY'),
    'base' => env('PEPPLO_API_BASE'),
],

// usage
$response = Http::withToken(config('services.pepplo.key'))
    ->timeout(20)
    ->get(config('services.pepplo.base') . '/balance');

And in Node.js:

const API_KEY = process.env.PEPPLO_API_KEY; // set on the server, not in code
if (!API_KEY) throw new Error('PEPPLO_API_KEY is not set');

Rotating keys

Rotation means replacing your key with a new one. Do it:

  • When a developer or agency who had access leaves the project.
  • If the key may have appeared in a log, screenshot, repository or message.
  • On a regular schedule that suits your organisation.

Plan rotation so it causes no downtime: generate the new key, update the server configuration, reload the application, confirm traffic works, then revoke the old key.

Keep keys out of your logs

Logging requests is essential for reconciliation, but logs are read by many people and often copied around. Mask secrets before writing them:

def mask(secret: str) -> str:
    return secret[:4] + "****" + secret[-4:] if secret and len(secret) > 8 else "****"

Also mask personal data such as full Aadhaar numbers or bank account numbers in logs; store only what you need.

Separate keys for separate purposes

  • Use different keys for sandbox and live, and never mix them up in configuration.
  • If you run several applications, consider a separate account or key for each where possible, so one leak does not expose everything.
  • Give staff access to the dashboard through their own logins, not a shared key.

Signs that a key may be compromised

  • Transactions you do not recognise, or a sudden drop in balance.
  • Requests rejected from IPs you do not own (visible in some dashboards).
  • Rate-limit errors at times when your own traffic is low.

If you notice any of these, rotate the key immediately, review your whitelist, and contact support with the transaction references.

Security checklist

  1. Key stored in environment or protected config, not in code.
  2. All API calls made server-side from a static IP.
  3. Only your production server IPs whitelisted; remove old ones.
  4. Keys masked in logs and error reports.
  5. Separate sandbox and live keys.
  6. Rotation process documented and tested.
  7. HTTPS used for every call, with certificate verification left on.

Exact header names and whitelisting steps are in our API documentation. If you want our team to review or harden an existing integration, see our software audit service or our API integration service.

0 comments

Leave a comment

Not shown publicly.
Security check image
Chat with us
Hi! Send us a message and we will reply here as soon as we can.
Security check image
Chat with us