Overview
Webhooks are HTTP callbacks sent from InventPay to your server. Since they can trigger critical business logic (like order fulfillment), securing your webhook endpoint is essential to prevent fraud and unauthorized access.Security Threats
Understanding potential threats helps you implement appropriate defenses:Replay Attacks
Attacker resends captured webhook to trigger duplicate actions
Forgery Attacks
Attacker sends fake webhooks pretending to be InventPay
Man-in-the-Middle
Attacker intercepts and modifies webhooks in transit
Denial of Service
Attacker floods your endpoint with requests
Essential Security Measures
1. Signature Verification (Required)
Every webhook includes an HMAC-SHA256 signature in theX-Webhook-Signature header. Always verify this signature before processing webhooks.
How Signature Verification Works
Implementation
Common Signature Verification Mistakes
❌ Using Parsed JSON
❌ Using Parsed JSON
Wrong:Right:
❌ Wrong Secret
❌ Wrong Secret
Make sure you’re using the webhook secret from your dashboard, not your API
key.
❌ Insecure Comparison
❌ Insecure Comparison
Wrong:Right:
2. HTTPS Only (Required)
Never accept webhooks over HTTP. Always use HTTPS to prevent:- Man-in-the-middle attacks
- Eavesdropping
- Payload tampering
3. Idempotency (Required)
Implement idempotency to handle duplicate webhook deliveries safely. Use theX-Webhook-ID header or payment ID to track processed webhooks.
Why Idempotency Matters
Webhooks may be delivered multiple times due to:- Network retries
- Timeout retries
- Manual redelivery
- Fulfill the same order twice
- Charge customer twice
- Send duplicate notifications
Implementation
Store webhook IDs for at least 7 days to handle retries. After 7 days,
InventPay stops retrying failed webhooks.
4. IP Whitelisting (Optional)
For additional security, whitelist InventPay’s IP addresses:Implementation
5. Rate Limiting (Recommended)
Implement rate limiting to prevent abuse:6. Timestamp Validation (Recommended)
Reject webhooks that are too old to prevent replay attacks:Additional Security Measures
Authentication Tokens
Add custom authentication to your webhook URL:Firewall Rules
Configure firewall to only accept traffic from InventPay IPs:Separate Endpoint
Use a dedicated subdomain or path for webhooks:Request Size Limits
Limit webhook payload size to prevent DoS:Security Checklist
Before going live, verify:✓ Signature Verification
✓ Signature Verification
- Using HMAC-SHA256 with correct secret
- Verifying with raw request body
- Using constant-time comparison
✓ HTTPS Only
✓ HTTPS Only
- Webhook URL uses HTTPS - [ ] Valid SSL certificate - [ ] Rejecting HTTP requests
✓ Idempotency
✓ Idempotency
- Tracking processed webhook IDs - [ ] Handling duplicates gracefully - [ ] Using database or cache
✓ Rate Limiting
✓ Rate Limiting
- Implemented rate limits - [ ] Appropriate limits configured - [ ] Returning proper error codes
✓ Logging
✓ Logging
- Logging all webhook deliveries - [ ] Logging security violations - [ ] Monitoring for suspicious activity
✓ Error Handling
✓ Error Handling
- Graceful error handling
- Returning appropriate status codes
- Not exposing sensitive errors
Secret Management
Storing Secrets Securely
Environment Variables
bash INVENTPAY_WEBHOOK_SECRET=your_secret_here Secret Manager
Use AWS Secrets Manager, Azure Key Vault, or HashiCorp Vault
Never in Code
❌ Never hardcode secrets in source code
Never in Logs
❌ Never log webhook secrets
Rotating Secrets
Periodically rotate your webhook secret:1
Generate New Secret
Create new secret in dashboard
2
Update Application
Deploy new secret to your servers
3
Test
Verify webhooks work with new secret
4
Revoke Old Secret
Remove old secret from dashboard
Monitoring and Alerts
What to Monitor
- Failed signature verifications
- Unusual webhook volume
- Old timestamp attacks
- Repeated webhook IDs
- IP address mismatches
Setting Up Alerts
Incident Response
If you suspect a security breach:1
Rotate Secrets Immediately
Generate new webhook secret in dashboard
2
Review Logs
Check for unauthorized webhook deliveries
3
Verify Orders
Audit recent orders for fraudulent fulfillment
4
Contact Support
Email [email protected] with incident details
5
Implement Additional Security
Add extra security layers based on findings
