Skip to content

feat: add webhook signature verification helper#63

Open
dipankardas011 wants to merge 1 commit into
polarsource:mainfrom
dipankardas011:feat/webhook-verification
Open

feat: add webhook signature verification helper#63
dipankardas011 wants to merge 1 commit into
polarsource:mainfrom
dipankardas011:feat/webhook-verification

Conversation

@dipankardas011
Copy link
Copy Markdown

@dipankardas011 dipankardas011 commented Nov 22, 2025

Summary

  • Adds WebhookVerifier struct for verifying incoming Polar webhook signatures
  • Adds ValidateWebhookSignature convenience function for one-shot verification
  • Uses the Standard Webhooks specification (which Polar uses for webhook signing)
  • Handles base64 encoding of secrets internally, providing a cleaner API

Usage

// Option 1: Reusable verifier (recommended for handlers)
verifier, err := polargo.NewWebhookVerifier(webhookSecret)
if err != nil {
    // handle error
}
if err := verifier.Verify(payload, r.Header); err != nil {
    // signature invalid
}

// Option 2: One-shot validation
if err := polargo.ValidateWebhookSignature(payload, r.Header, webhookSecret); err != nil {
    // signature invalid
}

Motivation

Currently, SDK users need to:

  1. Import the standard-webhooks library separately
  2. Manually base64-encode their webhook secret
  3. Understand the Standard Webhooks spec

This PR provides a native SDK solution that hides these implementation details. As Python and Typescript sdk have this

Test plan

  • Unit tests for NewWebhookVerifier
  • Unit tests for Verify with valid/invalid signatures
  • Unit tests for missing headers
  • Unit tests for wrong secret
  • Unit tests for ValidateWebhookSignature convenience function
  • All tests passing

Add WebhookVerifier and ValidateWebhookSignature for verifying incoming
webhook payloads using the Standard Webhooks specification.

This provides a convenient API for SDK users to validate webhook
signatures without having to manually handle base64 encoding or
import the standard-webhooks library directly.

Co-Developed-By: Claude <noreply@anthropic.com>
Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant