Aller au contenu principal

Security Best Practices

API keys carry live spending authority against your account balance. Treat every key like banking credentials.

1. Secret Storage & Zero Client Exposure​

  • Backend-Only Execution: Call /api/v1/* exclusively from secure backend servers. Never embed gpk_live_... tokens in browser JavaScript bundles, React/Vue SPAs, browser extension storage, or mobile APK/IPA clients.
  • Environment Variables & Secrets Managers: Store keys in server environment variables (GPKEYS_API_KEY) or vaults (AWS Secrets Manager, GCP Secret Manager, Doppler, HashiCorp Vault). Never check .env files into Git.
  • Log Redaction: Never log Authorization, x-api-key, or full key strings in application logs, APM breadcrumbs, error trackers (Sentry), or webhook payloads. Log at most the non-secret prefix (gpk_live_ab12cd34).

2. Principle of Least Privilege & Spend Caps​

  • Separate Keys per Environment & Service: Issue distinct keys for production checkout, staging tests, and reporting workers so compromising one worker never disrupts unrelated workflows.
  • Always Set perRequestCap and monthlySpendCap: Configure tight caps matching expected SKU pricing so a buggy loop or compromised container cannot drain your balance.
  • Set expiresAt for Scheduled Rotations: Assign finite expiration dates for short-lived migrations or contractor integrations.

3. Rotation, Revocation & Compromise Response​

  1. Provision a replacement key and deploy it to your secrets manager.
  2. Verify production traffic runs cleanly on the new key via GET /api/v1/key.
  3. Disable first if confirming zero lingering dependencies (403 KEY_DISABLED surfaces stray callers immediately).
  4. Permanently revoke the old key (REVOKED invalidates cached authorization immediately and blocks forever with 401 UNAUTHORIZED).

If you suspect a key leak:

  • Revoke immediately (revocation takes effect instantaneously across auth caches).
  • Inspect GET /api/v1/audit and GET /api/v1/ledger (?keyOnly=true) for unexpected IPs, purchases, or MULTI_IP_ABUSE events.
  • Watch out for multi-IP blocks: routing one key behind many unpredictable outbound NAT IPs (>= 5 distinct IPs in 15 minutes) triggers automatic 403 FRAUD_DETECTED (MULTI_IP_ABUSE). Route reseller traffic through a consistent static egress IP or dedicated NAT gateway.

4. Handling Account Suspension (403 FORBIDDEN)​

If your user account is suspended, cached keys are invalidated immediately and all API calls reject with 403 FORBIDDEN. Build circuit-breaker handling to pause purchase workers, alert operations, and contact support (@Etkeys) rather than retrying infinitely.