Security Best Practices
This guide covers the security measures you should implement when integrating with Open Pay, from API key management to smart contract safety.API Key Management
Store Secrets Securely
Never hardcode API keys in source code. Use environment variables or a secret manager.
- Environment Variables
- AWS Secrets Manager
- HashiCorp Vault
Use Separate Keys per Environment
Generate distinct API keys for development, staging, and production. This limits the blast radius if a key is compromised.
| Environment | Key Prefix | Purpose |
|---|---|---|
| Development | sk_test_ | Local testing with test network |
| Staging | sk_staging_ | Pre-production validation |
| Production | sk_live_ | Live payments on mainnet/testnet |
Rotate Keys Regularly
Rotate your API keys periodically (recommended: every 90 days). The Merchant Portal supports having two active keys simultaneously for zero-downtime rotation:
- Generate a new API key
- Update your application to use the new key
- Verify the new key works in production
- Revoke the old key
Webhook Signature Verification
Always verify webhook signatures before processing events. This prevents attackers from forging webhook payloads.The timestamp validation window (5 minutes) protects against replay attacks. An attacker who captures a valid webhook cannot replay it after the window expires.
HTTPS Only
- Always use
https://for your webhook endpoint - Always call the API over
https://olp-api.nipuntheekshana.com - Ensure your TLS certificates are valid and not self-signed in production
- Use HSTS headers on your webhook endpoint
Idempotency Keys
Include anIdempotency-Key header on all POST requests to prevent duplicate operations during retries:
- First request with a given key: creates the resource and caches the response
- Subsequent requests with the same key and parameters: returns the cached response
- Same key with different parameters: returns a
409 Conflicterror - Keys expire after 24 hours
IP Allowlisting
Restrict API key usage to specific IP addresses for an extra layer of protection. Configure this in the Merchant Portal under Integrations > API Keys > IP Restrictions.- Supports individual IPs and CIDR ranges
- Requests from non-allowlisted IPs receive a
403 Forbiddenresponse - Recommended for production server-to-server integrations
For webhook signature verification, you can also allowlist Open Pay’s outbound IP addresses. Contact support for the current list of webhook delivery IPs.
Two-Factor Authentication (2FA)
Enable 2FA on your merchant account to protect against unauthorized access to the Merchant Portal and sensitive API operations.Set Up 2FA
HMAC Replay Protection
For server-to-server API calls using HMAC authentication (used by SDKs), the platform enforces timestamp-based replay protection:| Component | Description |
|---|---|
timestamp | Current Unix timestamp (seconds) |
method | HTTP method (GET, POST, etc.) |
path | Request path (e.g., /v1/payments) |
body | Request body (empty string for GET) |
Smart Contract Security
Open Pay’s on-chain escrow contracts implement multiple security patterns:ReentrancyGuard
All external calls are protected with OpenZeppelin’s
ReentrancyGuard to prevent reentrancy attacks on fund withdrawal functions.SafeERC20
Token transfers use OpenZeppelin’s
SafeERC20 library to handle non-standard ERC20 implementations that don’t return a boolean.Ownable
Admin functions (fee updates, pausing) are restricted to the contract owner using OpenZeppelin’s
Ownable pattern.Chainlink Price Feeds
Exchange rates are sourced from Chainlink oracles with staleness checks. Payments are rejected if the price feed is stale (> 1 hour old).
Contract Audit Checklist
Key security properties of the escrow contract:- Funds can only be released to the merchant after payment confirmation
- Refunds can only be triggered by the contract owner or after expiration
- Slippage tolerance is configurable (default: 1%) and capped at 5%
- Emergency pause functionality halts all deposits and withdrawals
- Contract is upgradeable via proxy pattern for critical security patches