Secure your webhook receiver
Use HTTPS and verify Pollarix's signature before processing survey events. You need the API secret for the department sending the events and access to the raw request bytes in your receiver.
Security Checklist
- Require a valid HTTPS certificate on the final callback URL.
- Keep the department API secret in your secret store.
- Verify the signature, then check the department and schema version.
- Use durable processing and deduplicate retries.
- Keep response bodies and credentials out of receiver logs.
Authentication Methods
Pollarix signs regular event deliveries with the department API secret. In addition, webhooks can send custom headers you configure. The Send Test connection check uses a fabricated payload and its own test behavior.
Secret Token Verification
Pollarix sends the HMAC-SHA256 digest of the raw JSON body as hexadecimal in X-Signature. Capture the body before applying your JSON middleware. Verify it with a constant-time comparison before parsing:
import { createHmac, timingSafeEqual } from 'node:crypto';
export function hasValidSignature(rawBody, signature, apiSecret) {
if (!Buffer.isBuffer(rawBody) || typeof signature !== 'string') {
return false;
}
if (!/^[0-9a-f]{64}$/i.test(signature)) {
return false;
}
const expected = createHmac('sha256', apiSecret).update(rawBody).digest();
return timingSafeEqual(expected, Buffer.from(signature, 'hex'));
}
Configure a request size limit and pass the original bytes as rawBody. In a local test, use a synthetic payload and a generated test secret. Verify that changing even one signed byte makes the checker reject the request.
Bearer Token Authentication
If your ingress also requires a bearer token, configure its Authorization header in Webhooks. Use a separate receiver token from your department API credentials. Verify both the receiver token and the Pollarix signature.
HTTPS Requirements
Use the receiver's final public HTTPS URL. A redirect counts as a failed delivery. Configure certificate renewal and check the URL from outside your private network.
Free SSL Options
A managed host or a certificate issued through an ACME provider can give your receiver a trusted certificate. Keep renewal enabled and test after changing the endpoint's domain or ingress.
Payload Validation
After validating the signature, check X-Pollarix-Schema-Version, parse the JSON, and verify that departmentId and event match your subscription. Read the payload fields for the event you accept.
Rate Limiting
Set a body size limit and keep processing time bounded. Allow for event bursts and retries. Queue verified requests when work can take longer than a short acknowledgement.
Idempotency
Use Idempotency-Key from the request header. Each event has its own key, even if multiple events refer to the same response. Store the key and the queued work in one transaction or equivalent durable operation. A retry of an accepted key can receive the same success status.
Common Security Mistakes
- Parsing and reserializing JSON before verifying the signature can change the signed bytes.
- Comparing retries by response ID can collapse separate event types.
- Using the test payload as a signed event fixture can hide integration problems.
Logging and Monitoring
Log All Webhook Requests
Record the event type, schema version, delivery key, and outcome. Omit secrets and respondent content.
Monitor for Anomalies
Monitor delivery failures, signature rejections, queue lag, and repeated processing attempts. Inspect a synthetic delivery after changing your endpoint configuration.
Error Handling
Don't Expose Internal Errors
Return a short error status for an invalid signature or unhandled request. Store internal details in your own restricted logs.
Graceful Degradation
Return success once the request is durable. If the receiver can't store an accepted event, return an error so Pollarix can retry.
Summary
Verify the signature over the raw body, route by event and schema version, and use the idempotency key to handle retries.