Introducing our brand new Rules Engine —
Read the docs
LogoLogo
Core APIOther APIsChangelog
Getting started
Getting started
  • Welcome to Commerce Layer
    • Guided setup
    • Manual configuration
  • API specification
  • API credentials
  • Authentication
    • Client credentials
    • Password
    • Authorization code
    • Refresh token
    • JWT bearer
    • Revoking a token
  • Roles and permissions
  • Fetching resources
  • Fetching relationships
  • Including associations
  • Sparse fieldsets
  • Sorting results
  • Pagination
  • Filtering data
  • Creating resources
  • Updating resources
  • Tagging resources
  • Deleting resources
  • Importing resources
  • Exporting resources
  • Cleaning up resources
  • External resources
    • External order validation
    • External prices
    • External shipping costs
    • External payment gateways
    • External promotions
    • External tax calculators
  • Rate limits
  • Handling errors
  • Real-time webhooks
  • Callbacks security
On this page

Callbacks security

How to verify callbacks authenticity

PreviousReal-time webhooks

Last updated 2 months ago

For security reasons, when sending and receiving data and information to and from an external endpoint (i.e. , ) we recommend verifying the callback authenticity by signing the payload with the shared secret () and comparing the result with the X-CommerceLayer-Signature callback header. In details:

  1. Read the X-CommerceLayer-Signature header and get the encrypted signature.

  2. Rebuild the signature according to the SHA256 HMAC algorithm, using the payload body and the provided shared secret.

  3. Compare your signature with the one you got from the header.

  4. If the two signatures match, you can proceed safely — if not, you can't trust the callback.

Example

This is a sample script in Node.js that you can use as a reference to check the signature:

import { createHmac } from "node:crypto";

export default (req, res) => {
  const signature = req.headers['x-commercelayer-signature']
  
  const encode = createHmac("sha256", process.env.CL_SHARED_SECRET)
    .update(req.body)
    .digest("base64");
  
  if (req.method === 'POST' && signature === encode) {
		// your-code
    res.status(200).json({
      success: true,
    })
  } else {
    res.status(401).json({
      error: 'Unauthorized',
    })
  }
}

When verifying the callback authenticity, make sure to read the raw body of the payload and NOT the parsed one.

IP ranges

Region
IPs
Description

eu-west-1

54.246.59.198 99.81.212.137 54.74.119.33

Source IPs for customers with organization localized in the EU region.

us-east-1

3.220.172.67 34.202.177.238 52.0.55.171

Source IPs for customers with organization localized in the US region.

In case there are any changes to the list of IPs above, they will be communicated widely in advance through all our channels.

Do you prefer to use or to verify the signature? Check the linked code samples from our open-source repository on GitHub.

All the external requests (i.e. , ) are sent from a set of dedicated IP addresses. When you receive requests to your endpoints, please make sure their source IP is included in the following lists:

real-time webhooks
external resources
SHA256 HMAC
Next.js
Express.js
Examples
real-time webhooks
external resources