Verifying X-SyncShield-Signature (HMAC-SHA256)
Always verify signatures over the raw unparsed request body bytes, enforce a maximum 300-second timestamp window, compare digests in constant time, and accept both v1 and v1_prev during zero-downtime secret rotation.
Node.js (TypeScript / ESM — node:crypto)
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifySyncShieldSignature(
rawBody: Buffer,
sigHeader: string,
secrets: string[], // [currentSecret, previousSecret?]
maxAgeSec = 300,
): boolean {
const parts = Object.fromEntries(
sigHeader.split(",").map((kv) => kv.split("=") as [string, string]),
);
const ts = Number(parts.t);
if (!Number.isFinite(ts) || Math.abs(Math.floor(Date.now() / 1000) - ts) > maxAgeSec) {
return false;
}
const candidates = [parts.v1, parts.v1_prev].filter(Boolean) as string[];
const payload = Buffer.concat([Buffer.from(`${ts}.`, "utf8"), rawBody]);
for (const secret of secrets) {
const expected = createHmac("sha256", secret).update(payload).digest();
for (const hex of candidates) {
const provided = Buffer.from(hex, "hex");
if (provided.length === expected.length && timingSafeEqual(provided, expected)) {
return true;
}
}
}
return false;
}
Python (FastAPI / Flask — hmac + hashlib)
import hashlib, hmac, time
def verify_syncshield_signature(raw_body: bytes, sig_header: str, secrets: list[str], max_age_sec: int = 300) -> bool:
parts = dict(item.split("=", 1) for item in sig_header.split(",") if "=" in item)
try:
ts = int(parts["t"])
except (KeyError, ValueError):
return False
if abs(int(time.time()) - ts) > max_age_sec:
return False
candidates = [parts[k] for k in ("v1", "v1_prev") if k in parts]
signed_bytes = f"{ts}.".encode("utf-8") + raw_body
for secret in secrets:
expected = hmac.new(secret.encode("utf-8"), signed_bytes, hashlib.sha256).hexdigest()
if any(hmac.compare_digest(expected, cand) for cand in candidates):
return True
return False
C# (.NET 8+ — System.Security.Cryptography)
using System.Security.Cryptography;
using System.Text;
public static bool VerifySyncShieldSignature(byte[] rawBody, string sigHeader, IEnumerable<string> secrets, int maxAgeSec = 300)
{
var parts = sigHeader.Split(',')
.Select(p => p.Split('=', 2))
.Where(kv => kv.Length == 2)
.ToDictionary(kv => kv[0].Trim(), kv => kv[1].Trim());
if (!parts.TryGetValue("t", out var tsStr) || !long.TryParse(tsStr, out var ts)) return false;
if (Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) > maxAgeSec) return false;
var candidates = new[] { "v1", "v1_prev" }
.Select(k => parts.TryGetValue(k, out var v) ? v : null)
.Where(v => !string.IsNullOrEmpty(v))
.ToList();
var prefix = Encoding.UTF8.GetBytes($"{ts}.");
var payload = new byte[prefix.Length + rawBody.Length];
Buffer.BlockCopy(prefix, 0, payload, 0, prefix.Length);
Buffer.BlockCopy(rawBody, 0, payload, prefix.Length, rawBody.Length);
foreach (var secret in secrets)
{
var expected = HMACSHA256.HashData(Encoding.UTF8.GetBytes(secret), payload);
foreach (var hex in candidates)
{
try
{
var provided = Convert.FromHexString(hex!);
if (provided.Length == expected.Length && CryptographicOperations.FixedTimeEquals(provided, expected))
return true;
}
catch (FormatException) { /* ignore malformed hex */ }
}
}
return false;
}
Go (crypto/hmac, crypto/sha256)
package syncshield
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"math"
"strconv"
"strings"
"time"
)
func VerifySignature(rawBody []byte, sigHeader string, secrets []string, maxAgeSec int64) bool {
parts := map[string]string{}
for _, kv := range strings.Split(sigHeader, ",") {
if k, v, ok := strings.Cut(kv, "="); ok {
parts[strings.TrimSpace(k)] = strings.TrimSpace(v)
}
}
ts, err := strconv.ParseInt(parts["t"], 10, 64)
if err != nil || int64(math.Abs(float64(time.Now().Unix()-ts))) > maxAgeSec {
return false
}
candidates := []string{}
for _, k := range []string{"v1", "v1_prev"} {
if v := parts[k]; v != "" {
candidates = append(candidates, v)
}
}
prefix := []byte(strconv.FormatInt(ts, 10) + ".")
for _, secret := range secrets {
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(prefix)
mac.Write(rawBody)
expected := mac.Sum(nil)
for _, cand := range candidates {
provided, decErr := hex.DecodeString(cand)
if decErr == nil && hmac.Equal(provided, expected) {
return true
}
}
}
return false
}
Troubleshooting FAQ
Why did my destination fail with SSRF_BLOCKED?
SyncShield enforces HTTPS only on ports 443 or 8443, resolves DNS A and AAAA records against private/reserved CIDR ranges, and blocks all 3xx redirects. Ensure your ERP receiver uses a public DNS hostname over HTTPS and responds with a direct 2xx status without redirecting.
Why is an event marked SUPPRESSED_STALE?
SyncShield's Out-of-Order Monotonic Guard compares each incoming resource timestamp against the newest delivered watermark for that entity and destination. When Shopify delivers an older update late, SyncShield drops it as SUPPRESSED_STALE so older order state cannot overwrite newer fulfillment or cancellation state in your ERP.
Why are 4xx errors sent straight to the DLQ without retrying?
Permanent 4xx responses (400, 401, 403, 404, 410, 422) indicate payload schema mismatches or credential errors that blind retries will not fix. Routing them straight to the Dead-Letter Queue lets you inspect the 4 KB ERP response snippet, patch the JSON payload or credentials, and replay cleanly.
Why is read_companies optional?
Shopify restricts the read_companies scope to Shopify Plus B2B stores. Declaring read_companies in optional_scopes allows Basic, Shopify, and Advanced stores to install without scope errors while Plus merchants can grant B2B Company and VAT hydration in one click inside Settings.
What IP addresses does SyncShield deliver from?
SyncShield runs on Cloudflare's global edge network (ASN AS13335), which uses dynamic egress IPs. Authenticate outbound requests cryptographically using the X-SyncShield-Signature HMAC-SHA256 header rather than static IP allowlisting.