How webhooks work
Webhooks are HTTP POST requests sent to your specified endpoint whenever certain events occur in your repositories. When you create a webhook subscription, Code Storage will:- Monitor Events: Watch for the events you’ve subscribed to (e.g.,
pushevents) - Generate Payloads: Create JSON payloads containing event details
- Sign Requests: Add cryptographic signatures for security verification
- Deliver Webhooks: Send HTTP POST requests to your endpoint with automatic retries
Example
Here’s an example webhook payload for push events:Webhook headers
Content-Type: application/jsonUser-Agent: Pierre-Webhook/1.0X-Pierre-Event: push(event type)X-Pierre-Signature: t=1642678200,sha256=abc123...(security signature)
Securing webhooks
To ensure the webhooks you receive are legitimate and from Code Storage, you must verify the HMAC signature included with each webhook delivery.HMAC Signature Verification
Each webhook includes anX-Pierre-Signature header with the format:
Webhook SDK methods
The SDK provides helper methods to help you validate webhook events quickly.Advanced SDK usage
Custom Validation Options:Common verification errors
When using the SDK, these errors are automatically detected and returned in theresult.error
field:
- Missing signature components: “Invalid signature header format”
- Timestamp too old: “Webhook timestamp too old (X seconds)”
- Future timestamp: “Webhook timestamp is in the future”
- Signature mismatch: “Invalid signature”
- Invalid JSON: “Invalid JSON payload” (when using
validateWebhook) - Missing headers: “Missing or invalid X-Pierre-Signature header”