HMAC Callback Signature Verification
This guide explains how to securely verify incoming webhook or callback requests using HMAC-SHA256. HMAC ensures:- The request came from a trusted source
- The payload was not modified in transit
- The request is protected against timing attacks
- Replay attacks are mitigated using timestamps
Note:
Merchants can find their Webhook Secret in the Dashboard → Webhooks section.
This secret is required to verify callback signatures.
Keep it secure and never expose it in frontend code or public repositories.
Callback Headers
When Star Pay sends a callback request to your server, the HTTP request includes the following required headers.Verification Flow
When receiving a callback:- Extract
X-Timestampfrom the request headers. - Extract
X-Signaturefrom the request headers. - Recompute the expected signature:
How Signature Generation Works
The signature is generated using: HMAC_SHA256(secret,${timestamp}.${JSON.stringify(payload)})
The timestamp is included in the message to prevent replay attacks.
- JavaScript
- Go
- Python
- C#
- cURL (OpenSSL)
Required Headers
When receiving a callback request, extract: X-Timestamp X-SignatureExample Usage in Express
- JavaScript
- Go
- Python
- C#
- cURL (OpenSSL)
Security Notes
- Always use
crypto.timingSafeEqualto prevent timing attacks. - Reject requests with missing headers.
- Optionally validate that the timestamp is within an acceptable time window (e.g., ±5 minutes).
- Never expose your callback secret publicly.
Summary
| Feature | Purpose |
|---|---|
| HMAC-SHA256 | Ensures data integrity |
| Timestamp | Prevents replay attacks |
| timingSafeEqual | Prevents timing attacks |
| Shared Secret | Authenticates sender |