Skip to main content
Back to news
4 min readCifrago team

Payment gateway API keys: least privilege, rotation, and leak response

Managing payment credentials requires separating environments, restricting privileges, and maintaining an immediate revocation and audit protocol for accidental leaks.

A secret API key connected to payment infrastructure is not equivalent to a standard user password. It serves as the cryptographic credential that authorises fund transfers, issues refunds against existing balances, and retrieves full transaction histories. Across online payments, a lapse in safeguarding these credentials can compromise both company treasury and customer personal data in minutes.

Understanding how to segment access, schedule credential rotation, and respond with technical precision to accidental public exposure is essential to maintaining operational integrity.

The anatomy of payment credentials: public versus secret

Every modern payment gateway divides its credentials into two distinct operational planes with contrasting risk profiles:

  • Public or publishable keys: designed to execute in untrusted client environments, such as a customer's web browser or mobile application. Their sole legitimate function is to initialise data collection interfaces and request the direct tokenisation of a payment card or instrument on the gateway's servers. They must never permit initiating a final charge, executing payouts, or querying past transactions.
  • Secret or private keys: strictly restricted to communication between authenticated servers. These credentials authorise charges on previously created tokens, manage recurring subscriptions, trigger refunds, and access accounting and banking records.

Embedding a secret key within client-side code, mobile binaries, or a public version control repository remains a widespread vulnerability. When this occurs, anyone with basic network inspection capabilities can capture the key and execute authenticated requests on behalf of the merchant.

Applying the principle of least privilege

Historically, many businesses operated using a single root secret key endowed with unrestricted read and write permissions. From a security standpoint, this approach is equivalent to distributing a master key that unlocks every entrance in a facility.

The principle of least privilege requires restricting each credential to the narrow technical scope required for its intended purpose:

  • Payment-only keys: authorised strictly to create payment intents or confirm pending charges, without read access to customer directories or the ability to issue refunds.
  • Accounting and reconciliation keys: configured exclusively with read permissions across historical transactions and payouts, intended for ERP systems or financial analytics tooling.
  • Customer support keys: restricted to processing refunds within a predetermined financial cap, without permissions to create new transactions or alter payout bank accounts.
  • Webhook signing keys: distinct secrets or cryptographic signatures used solely to verify that inbound event notifications originate from the processing gateway rather than an imposter.

By segregating permissions, the blast radius of a compromised credential is confined to its assigned surface, neutralising the risk of full treasury drainage or extensive data extraction.

Scheduled key rotation and overlap windows

Retaining the same API key over extended periods increases the likelihood of accidental exposure within server logs, staging backups, or developer workstations. Periodic credential rotation sharply curtails this vulnerability window.

To rotate keys in production without service interruptions, engineering teams rely on a controlled overlap window:

  • A new API key is generated within the gateway's management console while the existing key remains fully operational.
  • Configuration variables across application clusters and secret management stores are updated, rolling out the new key incrementally.
  • Traffic metrics and authentication logs are monitored to verify that inbound and outbound requests are using the new identifier.
  • Once traffic on the retired key ceases entirely, the old credential is permanently revoked in the payment dashboard.

Automating this routine via dedicated secret managers and continuous deployment pipelines minimises manual errors, ensuring credentials are systematically renewed every ninety to one hundred and eighty days.

Incident response: actions when an API key is leaked

When a secret key is discovered in a public repository, an unindexed log file, or client-side assets, every minute is critical. Remediation must follow an immediate sequence:

  • Immediate revocation: the primary step is not identifying how the exposure occurred, but revoking the exposed credential via the gateway console or generating an active replacement if the platform requires simultaneous rollover.
  • Audit log investigation: inspect the gateway's audit logs for all activity involving that key during preceding hours or days. The immediate objective is verifying whether unauthorized refunds were dispatched, malicious charges were processed, or bank payout destinations were modified.
  • Impact assessment and [fraud](/noticias/tema/fraude) evaluation: if the key held permissions to read customer profiles, physical addresses, or financial amounts, an assessment of personal data breach risk is mandatory. Under the European GDPR, if the exposure presents a risk to the rights and freedoms of individuals, the merchant must report the incident to the relevant data protection authority within 72 hours.
  • Root-cause remediation: purge the exposed secret from git commit trees using history sanitisation utilities, decommission any remaining local cache, and address the deployment review mechanism that allowed the leak.

Continuous operational hygiene

Securing payment credentials does not rely on complex workarounds, but on rigorous operational hygiene. Implementing automated static analysis to block commits containing high-entropy secrets, enforcing strict multi-factor authentication on dashboard accounts, and injecting credentials through secured runtime environment variables safeguard business operations without slowing development cycles.

Building subscriptions?

Check the pricing and try the dashboard with sample data before integrating anything.

Keep reading

4 min read

Bizum, cards or bank transfers: cost, operations and friction for Spanish e-commerce

Selecting payment methods for a store in Spain requires balancing customer checkout habits, unit economics, chargeback exposures, and back-office reconciliation.

2 min read

Embedded finance in operational software and new supervisory decisions

BMO and Mastercard embed virtual commercial cards into business platforms, the ECB issues governance decisions, and a case highlights unmonitored contract risks.