Why Verify Webhooks?
Anyone can send a POST request to your webhook endpoint. Without verification, a malicious actor could send fake payment notifications to your server. HMAC signatures ensure that webhooks are genuinely from Card2Crypto and haven’t been tampered with.How Signature Verification Works
When Card2Crypto sends a webhook, we include an HMAC-SHA256 signature in theX-Card2Crypto-Signature
header.
This signature is generated using:
- Your webhook secret (from your shop settings)
- The complete webhook payload
- HMAC-SHA256 algorithm
Verification Implementation
Node.js / JavaScript
PHP
Python
Common Mistakes
Mistake 1: Not Using Raw Body
Mistake 2: Using Wrong Secret
Mistake 3: Modifying Payload Before Verification
Security Best Practices
1. Always Verify Signatures
Never skip signature verification, even in development:2. Use HTTPS Only
Always use HTTPS for your webhook endpoint. HTTP traffic can be intercepted and modified.3. Keep Secrets Secure
Never commit webhook secrets to version control:4. Use Timing-Safe Comparison
Always use timing-safe comparison to prevent timing attacks:5. Limit Request Size
Prevent memory exhaustion attacks by limiting webhook payload size:Webhook Replay Protection
Implement timestamp verification to prevent replay attacks:Testing Signature Verification
Test your implementation using the “Test Webhook” button in your shop settings. Expected test payload:- You’re using the correct webhook secret
- You’re properly generating the HMAC-SHA256 signature
- You’re not modifying the payload before verification
Troubleshooting
Signature Always Fails
Problem: Verification always returns false, even for valid webhooks. Solutions:- Check you’re using the webhook secret (not API key):
- Ensure you’re not modifying the payload:
- Verify you’re using HMAC-SHA256:
Webhook Secret Not Working
Problem: Can’t find webhook secret or it doesn’t work. Solutions:- Go to Dashboard > Shops
- Click your shop settings
- Find “Webhook Secret” section
- Click “Regenerate Secret” if needed
- Copy the new secret and update your environment variables
Test Webhook Fails
Problem: Test webhook button shows verification failed. Solutions:- Check your server logs for the actual error
- Ensure your endpoint is publicly accessible
- Verify you’re returning
200 OK
status - Test with a tool like ngrok if developing locally