Skip to main content

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:
  1. Extract X-Timestamp from the request headers.
  2. Extract X-Signature from the request headers.
  3. 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.

Required Headers

When receiving a callback request, extract: X-Timestamp X-Signature

Example Usage in Express

Security Notes

  • Always use crypto.timingSafeEqual to 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