Verify the HMAC-SHA256 signature on Star-Pay webhook callbacks.
When Star-Pay sends a callback to your server after a payment event, it signs the request with an HMAC-SHA256 signature. Verifying this signature ensures:
The request came from Star-Pay, not an unknown third party.
The payload was not modified in transit.
The request is not a replay of an earlier legitimate request.
Your Webhook Secret is available in Dashboard → Webhooks. Keep it secure and never expose it in frontend code or public repositories.
The timestamp is concatenated with the serialized payload body before hashing. This binds the signature to a specific point in time, preventing replay attacks.
Read X-Timestamp and X-Signature from the incoming request headers. Reject the request immediately if either header is missing.
2
Serialize the payload
Serialize the request body to a JSON string using the same format as the sender (no extra spaces).
3
Build the signed message
Concatenate the timestamp and the serialized body: "${timestamp}.${serializedBody}".
4
Recompute the expected signature
Compute HMAC-SHA256 of the signed message using your Webhook Secret as the key. Encode the result as a lowercase hex string.
5
Compare signatures
Use a constant-time comparison function to compare the expected signature against the X-Signature header value. Reject the request if they do not match.
Optionally, also validate that the X-Timestamp is within an acceptable window (for example, ±5 minutes of your server clock) to further reduce replay attack surface.