HubSpot v3 request signature verification: base64 HMAC-SHA256 of method + decodedUri + body + timestamp with your app's client secret, delivered as X-HubSpot-Signature-v3 + X-HubSpot-Request-Timestamp (millisecond timestamp, 5-minute window). See https://developers.hubspot.com/docs/apps/developer-platform/build-apps/authentication/request-validation.
Values
MAX_AGE_SECONDS
MAX_AGE_SECONDS: Int 300
URI_DECODES
URI_DECODES: Vec [
[
"%3A",
":"
],
[
"%2F",
"/"
],
[
"%3F",
"?"
],
[
"%40",
"@"
],
[
"%21",
"!"
],
[
"%24",
"$"
],
[
"%27",
"'"
],
[
"%28",
"("
],
[
"%29",
")"
],
[
"%2A",
"*"
],
[
"%2C",
","
],
[
"%3B",
";"
]
]
Functions
build-base-string
fn (method: Str, uri: Str, raw-body: Str | Bytes, timestamp: Str): Str | Bytes
The v3 signed message: method + normalize-uri(uri) + rawBody + timestamp. A Bytes body (non-UTF-8, from ::hot::http/raw-body)
yields Bytes, so it is signed verbatim. Exposed for testing.
Example
::hubspot::webhooks/build-base-string("POST", "https://example.com/hook", "{}", "1762000000000") // "POSThttps://example.com/hook{}1762000000000"
normalize-uri
fn (uri: Str): Str
The URI as HubSpot signs it: any #fragment dropped, and the twelve
characters in HubSpot's v3 table (: / ? @ ! $ ' ( ) * , ;) decoded
from their percent-escapes, in either hex case. Exposed for testing.
Example
::hubspot::webhooks/normalize-uri("https://example.com/hook%3Fa%20b#top") // "https://example.com/hook?a%20b"
verify-request
fn (request: Map): Bool
fn (request: Map, client-secret: Str): Bool
fn (request: Map, client-secret: Str, url: Str): Bool
Verify a HubSpot v3 webhook request. request needs method,
original-url (the URL HubSpot called, as delivered by the platform),
headers, and the raw body (body-raw, or body-bytes when the body
is not UTF-8; read through ::hot::http/raw-body). Returns true when
the signature matches (constant-time) and the millisecond timestamp is
within 5 minutes. Uses the hubspot.client.secret context variable by
default (failing when it is unset), or accepts an explicit secret — an
empty explicit secret never verifies.
HubSpot signs the exact URL configured in your app, query string
included. The 3-arity form takes that URL explicitly for when the
platform-reconstructed original-url differs from it — e.g. a
rewriting proxy in front, or a plain http:// endpoint behind an edge
that doesn't set x-forwarded-proto (reconstruction defaults to
https). The platform also withholds original-url on redelivery
paths it cannot corroborate (it is never persisted with the webhook
token intact), so re-verifying a replayed event needs the explicit-URL
form too.
Example
hubspot-webhook
meta {webhook: {service: "hubspot", path: "/hubspot/webhook"}}
fn (request) {
if(not(::hubspot::webhooks/verify-request(request)),
::hot::http/HttpResponse({status: 401, body: "invalid signature"}),
::hot::http/HttpResponse({status: 200, body: "ok"}))
}
hubspot.client.secret