Webhooks in meCash are signed with HMAC-SHA256 to ensure authenticity and integrity.
This guide shows you how to verify webhook signatures in different programming languages.
Overview
Each webhook request includes a signature in the X-meCash-Signature header. You must verify this signature to ensure the webhook came from meCash and wasn’t tampered with.
Getting Your Webhook Secret
- Log into your meCash dashboard
- Navigate to Developer → Webhooks
- Find your webhook endpoint
- Copy the webhook secret
Keep your webhook secret secure and never expose it in client-side code.
Verification Process
- Extract the signature from the
X-meCash-Signature header
- Create a payload string from the request body
- Generate HMAC-SHA256 using your webhook secret
- Compare signatures using a constant-time comparison
Code Examples
Node.js
Python
PHP
Ruby
Testing Webhook Verification
Test Your Implementation
Expected Responses
- Missing signature: 400 Bad Request.
- Invalid signature: 401 Unauthorized.
- Valid signature: 200 OK.
Security Best Practices
1. Always Verify Signatures
Never process webhooks without signature verification:
2. Use Constant-Time Comparison
Always use constant-time comparison to prevent timing attacks:
3. Store Secrets Securely
4. Handle Raw Request Body
Make sure to use the raw request body for signature verification:
Common Issues
Issue 1: Signature Mismatch
Problem: Signature verification always fails.
Solutions:
- Check that you’re using the raw request body.
- Verify the webhook secret is correct.
- Ensure you’re removing the ‘sha256=’ prefix.
Problem: X-meCash-Signature header is missing.
Solutions:
- Check your webhook endpoint configuration.
- Verify the header name is correct (case-sensitive).
- Ensure your server is receiving all headers.
Issue 3: Body Parsing Issues
Problem: Request body is modified before verification.
Solutions:
- Use raw body parsing for webhook endpoints.
- Don’t use JSON middleware before signature verification.
- Parse JSON after signature verification.
Monitoring & Debugging
Log Signature Verification
Create a simple test endpoint: