Overview
Webhook security is critical to ensure that requests to your endpoint are actually from Modulus Labs and haven’t been tampered with. All webhook notifications include cryptographic signatures that you must verify before processing.How Webhook Security Works
Modulus Labs uses JWE (JSON Web Encryption) to secure webhook payloads. Every webhook notification you receive is encrypted and must be decrypted using your encryption key.1
We Encrypt the Payload
Modulus Labs encrypts the webhook payload using your encryption key with JWE (A256KW algorithm with A256CBC-HS512 encryption)
2
We Send Encrypted Token
The encrypted payload is sent as a
Token field in the webhook POST request to your endpoint3
You Decrypt the Token
Your endpoint decrypts the token using your encryption key to access the transaction data
4
You Process the Event
Once decrypted and verified, process the transaction event securely
Decrypting Webhook Payloads
Node.js Example
Python Example
C# / .NET Example
Security Best Practices
Use HTTPS Only
Always use HTTPS endpoints for webhooks. HTTP is not supported in production and is insecure.
Verify All Payloads
Always decrypt and verify webhook payloads before processing to prevent fake notifications.
Keep Keys Secret
Never expose your encryption key in client-side code, logs, or version control.
Validate Structure
Always validate that decrypted payloads contain expected fields before processing.
Handle Errors Gracefully
Return appropriate HTTP status codes and log verification failures for debugging.
Implement Idempotency
Handle duplicate webhook deliveries by checking transaction IDs you’ve already processed.
Webhook Payload Structure
After decryption, webhook payloads follow this structure:Success Event
Declined Event
Implementing Idempotency
Modulus Labs may send the same webhook multiple times (e.g., due to network retries). Implement idempotency to handle duplicates:Testing Webhook Security
Use the Simulate Webhook API to test your webhook endpoint security in sandbox:Common Security Issues
Decryption Fails
Decryption Fails
Symptoms:
- Cannot decrypt webhook token
- “Invalid token” errors
- Verify you’re using the correct encryption key from environment variables
- Check that encryption key matches the one provided by Modulus Labs
- Ensure you’re using the correct JWE algorithms (A256KW, A256CBC-HS512)
- Verify no whitespace or encoding issues with the key
Webhook Endpoint Not Reachable
Webhook Endpoint Not Reachable
Symptoms:
- Not receiving webhook notifications
- Webhook delivery failures
- Verify your endpoint is publicly accessible over the internet
- Check firewall rules allow incoming HTTPS connections
- Ensure SSL certificate is valid and not self-signed
- Test endpoint accessibility from external networks
Missing Required Fields
Missing Required Fields
Symptoms:
- Decryption succeeds but payload validation fails
- Unexpected payload structure
- Check webhook event type and expected payload structure
- Verify you’re handling both SUCCESS and DECLINED event types
- Log full decrypted payload to debug unexpected structures
- Ensure backward compatibility for new fields
Duplicate Webhooks
Duplicate Webhooks
Symptoms:
- Same transaction processed multiple times
- Duplicate order fulfillment
- Implement idempotency using transaction ID tracking
- Use database to persist processed transaction IDs
- Check transaction ID before processing
- Use database transactions to prevent race conditions
IP Whitelisting
For additional security, you can whitelist Modulus Labs webhook IP addresses:Contact Modulus Labs support to get the list of IP addresses for webhook notifications in your environment (sandbox vs production).
Webhook Retry Logic
Modulus Labs implements automatic retry logic for webhook delivery:- Retry Attempts: Up to 3 additional attempts
- Retry Interval: 15 minutes between attempts
- Success Criteria: Your endpoint returns
200 OKwithin 10 seconds