Verify Square Webhook Signatures: The Notification URL Trap

Learn how to verify Square webhook signatures without falling into the notification URL trap. Avoid common mistakes and secure your payments.

14 jul 2026 • 3 min read • Q2BSTUDIO Team

Avoid Square signature validation errors

Square's webhook integration is a common practice on many platforms that process payments or manage subscriptions. However, validating the signature of these webhooks hides a detail that often goes unnoticed and causes errors that are difficult to debug: the notification URL is part of the signed message. If it doesn't replicate exactly as Square has it registered, each notification will fail verification, even when the HMAC code appears correct. Understanding this mechanism thoroughly is key to ensuring that transactions are processed without loss or delay.

Square uses HMAC-SHA256 to sign its webhooks. The value of the x-square-hmacsha256-signature header is calculated by concatenating the notification URL configured in the Square dashboard with the raw body, then applying the HMAC algorithm with the signing key associated with that subscription, and encoding the result in base64. This means that any discrepancy in the URL, whether it's a different protocol, a host change, a trailing slash, or a slightly different path, will cause the signature to mismatch. In addition, the body must be exactly the one Square sent, without parsing or re-serializing it, because the spaces, the order of the keys or the format of the numbers alter the result.

One of the most common mistakes is to reconstruct the URL from the request headers (req.protocol, req.headers.host). A reverse proxy or load balancer terminating TLS may return HTTP instead of HTTPS, or a different hostname than the registered one. The safest solution is to treat the URL as a constant per environment, exactly the one set up in Square. Another frequent mistake is to check against a re-serialized body after parsing JSON; The firm expects the original bytes, not a reconstructed rendering.

Security doesn't end with the comparison of signatures. It's critical to use a constant-time comparison function, such as crypto.timingSafeEqual, to prevent timing attacks that allow you to deduce the correct signature byte-by-byte. Additionally, Square is retiring the legacy x-square-signature header (based on SHA1) in favor of the current SHA256. Keeping old code exposes the integration to vulnerabilities and compatibility failures.

From a business perspective, improper webhook validation can result in missed notifications about completed payments, refunds, or disputes. Square retries failed deliveries for a limited time; If the server does not respond correctly, the subscription may be deactivated. This represents a direct risk to business continuity. That's why having a robust infrastructure in place that captures the raw body, constantly verifies the signature, and manages retries is critical.

At Q2BSTUDIO we are specialists in cybersecurity and secure software development. We help companies implement webhook validations that withstand these scenarios, combining security best practices with cloud services such as AWS and Azure to ensure high availability. Our team also integrates AI for businesses and AI agents that automate event response, as well as business intelligence solutions with Power BI to monitor the flow of transactions in real-time. Whether you need custom applications to handle webhooks or a complete notification platform, our multidisciplinary approach ensures that every event is processed reliably and securely.

The key is not to underestimate the detail of the URL. Setting it to constant, capturing the raw body before any parsing and always using constant time comparison are practices that, although simple, make the difference between a robust integration and one that fails in production. With the support of an expert team of custom software and cloud services, you can avoid the headaches generated by these errors and focus on what matters: your business.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.