n8n Webhook Signature Verification: Trusting Requests From Third-Party Services
By Abhishek Patoliya · 2026-08-16
A webhook URL, even one that's long and unguessable, is not authentication — it's obscurity. Anyone who obtains that URL, whether through a leaked log, a misconfigured proxy, or simply having access to the sending service's own configuration screen, can send a request to it that looks, on the surface, identical to a real one. Webhook signature verification is what actually proves an incoming request came from the specific service it claims to, by checking a cryptographic signature the sending service computes using a secret only it and your workflow know.
Why n8n Webhook Signature Verification Matters More Than It Seems
It's easy to underestimate this because a webhook endpoint that "just works" gives no visible sign that anything is wrong — an unsigned, unverified endpoint accepts a forged request exactly as smoothly as it accepts a legitimate one, with no error, no warning, nothing to notice until the forged request actually causes a real, visible problem downstream.
How Signature Verification Actually Works
When a service supports webhook signatures, it computes a hash (typically HMAC-SHA256) of the outgoing request body using a shared secret configured when you set up the webhook, and sends that hash in a header alongside the request — commonly something like X-Signature or a provider-specific header name. On the receiving end, you compute the same hash over the exact raw body you received, using the same shared secret, and compare it to the header value. If they match, the request genuinely came from someone who knows the shared secret — in practice, the legitimate service, assuming the secret hasn't leaked.
Implementing Verification in an n8n Workflow
This needs to happen in a Code node immediately after the Webhook trigger node, before any other processing touches the payload, and it needs access to the raw, unparsed request body — verification against an already-parsed and re-serialized version of the body can produce a different byte sequence than what the sender actually signed, causing valid requests to fail verification for reasons that have nothing to do with an actual security problem.
// n8n Code node — immediately after the Webhook trigger,
// verifying an HMAC-SHA256 signature before trusting the payload
const crypto = require('crypto');
const signature = $input.first().json.headers['x-signature'];
const rawBody = $input.first().json.rawBody; // raw body, not the parsed json
const secret = $env.WEBHOOK_SIGNING_SECRET;
const expected = crypto
.createHmac('sha256', secret)
.update(rawBody)
.digest('hex');
const isValid = crypto.timingSafeEqual(
Buffer.from(signature, 'hex'),
Buffer.from(expected, 'hex')
);
if (!isValid) {
throw new Error('Webhook signature verification failed — rejecting request');
}
return $input.all();
Using timingSafeEqual rather than a plain string comparison matters here — a naive comparison can leak timing information about how much of the signature matched, which is a real (if narrow) attack vector against signature verification specifically.
Storing the Signing Secret Correctly
The webhook signing secret is exactly the kind of value covered under n8n credentials management elsewhere on this blog — it belongs in an environment variable or n8n's credential system, never hardcoded directly into a Code node's source, where it would be visible to anyone with workflow-view access and exposed in plain text in any exported workflow JSON. Treat it with the same handling discipline as an API key, because functionally it is one.
Failing Closed, Not Open
A workflow that catches a signature verification failure and merely logs a warning, then proceeds to process the payload anyway, has verification in name only — it provides no actual protection, since a forged request without a valid signature still gets processed identically to a genuine one. The verification step needs to actually stop the workflow on failure — throwing an error that halts execution, or explicitly routing to a rejection path that never reaches the rest of the workflow's logic — not merely note that something looked wrong and continue regardless.
What to Do When a Service Doesn't Support Signatures
Not every third-party service offers webhook signing, particularly older or simpler integrations. Where signatures aren't available, IP allowlisting — restricting which source IPs are accepted, if the sending service publishes a fixed, documented set — is a meaningfully weaker but still worthwhile fallback. It doesn't cryptographically prove authenticity the way a signature does, but it does raise the bar against a random unauthenticated request reaching the workflow, and it's worth implementing even as a partial measure rather than leaving an unsigned webhook endpoint with no verification at all.
Testing Verification Without Breaking Real Traffic
Test the verification logic with both a deliberately invalid signature (confirming it correctly rejects) and a real request from the actual sending service's test/sandbox mode where one is available (confirming it correctly accepts). Testing only the rejection path risks shipping verification logic that also rejects legitimate traffic due to a subtle bug — a mismatched header name, a raw-body encoding difference — which fails safe in principle but breaks the actual integration in practice, trading one problem for a more immediately disruptive one.
Rotating a Signing Secret Without an Outage
A signing secret occasionally needs rotation — after a suspected leak, or as routine security hygiene. Because verification depends on both sides agreeing on the same secret, a naive rotation (updating it on only one side first) causes every request to fail verification during the gap. Where the sending service supports it, configure a brief overlap window accepting both the old and new secret during rotation; where it doesn't, coordinate the change as a deliberate, timed cutover on both sides rather than updating your side first and discovering the mismatch only once real traffic starts failing.
Verification as Part of a Layered Webhook Security Approach
Signature verification is the strongest single control for confirming a webhook's authenticity, but it's worth pairing with the other measures covered elsewhere on this blog rather than treating it as the only necessary safeguard — a webhook endpoint restricted to expected source IPs where possible, rate-limited against abuse, and logging rejected verification attempts for visibility into whether someone is actually probing the endpoint. None of these replace signature verification; together they make the endpoint meaningfully harder to abuse than any single measure alone.
Handling Replay Attacks, Not Just Forged Requests
A valid signature proves a request genuinely came from the expected sender at some point — it doesn't by itself prove the request is new rather than a captured, legitimate request being resent later by someone who intercepted it. Services that care about this typically include a timestamp in the signed payload; verify that the timestamp is recent (within a small tolerance window, accounting for reasonable network delay) as part of the same verification step, rejecting requests with a stale or missing timestamp even if the signature itself is technically valid.
// n8n Code node — rejecting stale requests alongside signature verification
const timestamp = parseInt($input.first().json.headers['x-timestamp'], 10);
const ageSeconds = Math.abs(Date.now() / 1000 - timestamp);
if (ageSeconds > 300) { // reject anything older than 5 minutes
throw new Error('Webhook timestamp too old — possible replay, rejecting request');
}
Different Providers, Different Signature Schemes
Not every service signs requests the same way — some use HMAC-SHA256 over the raw body as shown earlier, others use SHA-1, others include additional context (the URL, a timestamp) in what gets signed rather than just the body alone. Always implement verification against the specific service's own documented scheme rather than assuming the generic pattern from one provider transfers exactly to another; a mismatched hashing algorithm or a missing piece of signed context produces the same symptom (verification always fails) regardless of which specific detail was actually wrong, so check the provider's documentation carefully rather than guessing.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.