Pakk Documentation
More HelpSubmit TicketPakk.io
  • Docs Home
  • Pakk Explained in 2 Minutes
  • Account Setup
    • Brands
    • Shipping Methods
      • Restricting Shipping Methods
      • Shipping Calculations
    • Payment Methods
      • Stripe
      • Paypal
      • Paytriot
      • VivaWallet
    • Admin Panel
      • Beginner Tutorial Series
        • Part 1: Overview of the Main Menu and Auxiliary Functions
        • Part 2: Overview of the Main Menu and Entities in the Admin Panel
        • Part 3: Overview of Data Management Features: Sorting, Filtering, and Bulk Actions
        • Part 4: Warnings and Detail Views
        • Part 5: Auxiliary Functionality
      • List Views
        • List View FAQs
      • Troubleshooting
  • Suppliers and Purchasing
    • Purchase Orders
      • Item Types
      • Stock Receipts
      • Invoicing and Payment
    • Demand Planning
      • Approaching the Demand Planner
      • Data Sources
      • Concepts
      • The Maths Behind the Predictions
      • Order Screen
  • Customers and Sales
    • Leads
    • Orders
      • Order Sources
        • Telephone Orders
        • In-Person Sales
      • Item Types
      • Order Status
        • Committed
        • Invoiced/Cash Saled
        • Dispatched
        • Paid
      • Order FAQs
    • Sales
      • Limitations of Sales
      • Entering and Processing Sales
      • Invoicing
      • Cancellation, Returns, Credits and Refunds
    • Credit Management
      • Payment Methods and Flows
      • Credit Terms
      • Credit Management
      • Credit Control
    • Credits, Refunds, Returns and Replacements
      • Customer Credits
        • Raising a Credit
        • The Impact of a Credit
        • Using a Credit
        • Checking Your Logic
      • Returns
      • Common Scenarios
    • Help Desk
      • Tickets
      • Configuring your Help Desk
      • Ticket Creation
      • Ticket Management
    • Loyalty Program
      • Set up Your Loyalty Program
      • Activate Your Loyalty Program on Site(s)
      • Administer your Loyalty Program
      • Accounting Considerations
  • Accounting, Bookkeeping and Finance
    • Accounting Overview
    • Accountants Guide to Pakk
    • Journal Entries
    • Rounding
    • Period Locking
    • Reconciliations
      • Create a Reconciliation
      • Build the Reconciliation
      • Completing Reconciliations
    • Cost of Goods Sold (COGS)
    • Multi-Currency
      • Exchange Rates
  • Products and Inventory
    • Pricing
      • Base Price
      • Bulk Pricing
      • Pricing Schemes
      • Per-Site Pricing
      • Web Discounts
      • Discount Adjustment Lines
      • Composite Products
    • Stock Control
      • Batches
        • Reusing Batches
    • Custom Product Attributes
      • Attribute Types
      • Attribute Setup
      • Apply to Products
    • Stock Adjustments
      • Stock Valuation
      • Assembly Builds
    • Multi-Location
      • Setting Up Locations
      • Items, Batches and Locations
      • Moving Stock between Locations
      • Incoming Stock
      • Outgoing Stock
    • Gross Margin Calculation and Control
      • Set up Default Variable Cost Parameters and Target Margin
      • Overrides
      • Margin Calculations
  • Websites
    • Visual Style Guide
      • Logo
      • Colour
      • Typography
      • Header
      • Custom CSS
      • Imagery
      • Icons
    • Configuration and Customisation
      • Website Development
      • Navigation Menus
        • Menus
        • Slots
          • Aux Bar Menu
          • Main Menu
          • Footer Menu
    • Product Categorisation
      • Related Groups
      • Product Variants
        • Variant Axes
        • Custom Attributes
        • Variant Category
        • Category List Page
        • Variant Shell Page
      • Category Warnings
    • Filtering and Sorting
      • Sorting
      • Filtering
    • Content
      • FAQs
        • Setting up FAQs
        • Using FAQs Around Your Site
      • Pages
      • Posts
      • Forms
        • How Customer Forms Work
        • Advanced Customisation
        • Confirmations, Notifications and Form Submissions
        • Use Cases and Examples
      • Feature Blocks
      • Feed Posts
      • Videos
    • SEO
      • What you need to do
      • What you don't need to worry about
    • Google Services
      • Analytics
      • Merchant Centre and Shopping Feed
      • Search Console and Sitemap
      • Adwords
    • GDPR, Privacy and Cookies
      • GDPR
      • Cookies
    • Reviews
      • Merchant Reviews
        • Shopping Experience Reviews
      • Product Reviews
    • Checkout
      • New Customers
      • Invoice Options
      • Custom Checkout Questions
      • Signup Options
    • Passwordless Login
    • Webstore Features
    • Email Sending
  • Admin and Reporting
    • Document Storage
    • Email Sending and Receiving
      • Postmark Setup
    • PDFs and Printing
  • Data and Integrations
    • Using Pakk with Other Systems
      • Pakk Integrated to Legacy Stock System
    • Data Import and Export
      • Export
        • CSV Conventions
        • List Fields
      • Import
        • Referencing Other Records
        • Test then Commit
        • Advanced
        • Importing Images & Documents
      • Tips and Tricks
    • API
      • Integrations
      • API Keys
      • Authentication
      • Integration Data (Key-Value Store)
      • Exploring API Requests and Responses
      • API Structure
        • Utility Endpoints
        • Generic Entity API
        • RPC API
        • CSV API
        • Document API
    • Webhooks
      • Setting Up a Webhook
      • Configuring the Webhook
      • Webhook Signature Verification
      • Data Transformation
      • Testing the Webhook
      • Webhook Execution Log
  • Pakk Services
    • Fulfilled by Pakk (FBP)
      • Overview of the Integration
      • Configuration
      • The FBP Tab
      • Products
      • Orders
      • Purchase Orders/ASNs
      • List Views
    • PakkPay
      • How to Setup PakkPay
Powered by GitBook
On this page
  • How Requests are Signed
  • Verifying the Signature
  • Tips and Tools
Export as PDF
  1. Data and Integrations
  2. Webhooks

Webhook Signature Verification

All webhook requests sent from Pakk are signed. Here's how to verify the authenticity of the incoming request.

How Requests are Signed

Pakk signs all webhook requests by hashing the request body bytes using HMAC-SHA256 with the webhook signing key (which you can find on the Webhook record in the admin panel) and encoding to Base64. The resulting signature is send in the header X-Pakk-Webhook-Signature.

Verifying the Signature

You should implement verification code that performs the same procedure and compares the result against the received signature. Here's an example of what that code would look like in Go:

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/base64"
    "io"
    "net/http"
)

// SharedSecret is the secret key used for signing and verifying webhook requests.
// In production, securely retrieve this from a configuration file or environment variable.
var SharedSecret = "your-shared-secret"

// VerifyWebhookSignature verifies that the request's payload matches the signature in the header.
func VerifyWebhookSignature(payload []byte, receivedSignature string) bool {
    // Generate the HMAC-SHA256 signature
    hash := hmac.New(sha256.New, []byte(SharedSecret))
    hash.Write(payload)
    expectedSignature := base64.StdEncoding.EncodeToString(hash.Sum(nil))

    // Use hmac.Equal to prevent timing attacks when comparing signatures
    return hmac.Equal([]byte(expectedSignature), []byte(receivedSignature))
}

// WebhookHandler handles incoming webhooks and verifies their signatures.
func WebhookHandler(w http.ResponseWriter, r *http.Request) {
    // Extract the signature from the header
    receivedSignature := r.Header.Get("X-Pakk-Webhook-Signature")
    if receivedSignature == "" {
        http.Error(w, "Missing signature header", http.StatusUnauthorized)
        return
    }

    // Read the raw JSON payload from the request body
    payload, err := io.ReadAll(r.Body)
    if err != nil {
        http.Error(w, "Failed to read request body", http.StatusInternalServerError)
        return
    }
    defer r.Body.Close() // Make sure to close the body when done reading

    // Verify the signature
    if !VerifyWebhookSignature(payload, receivedSignature) {
        http.Error(w, "Invalid signature", http.StatusUnauthorized)
        return
    }

    // Process the webhook payload as it's been verified successfully
    w.WriteHeader(http.StatusOK)
    w.Write([]byte("Webhook received and verified"))
}

Tips and Tools

PreviousConfiguring the WebhookNextData Transformation

Last updated 6 months ago

Use a testing tool like to quickly produce expected hashes and compare to the signature sent by Pakk using the previously suggested webhook testing tool.

https://www.devglan.com/online-tools/hmac-sha256-online