Skip to main content

Secure AI agent webhook with HMAC, replay protection, and OpenAI GPT-5

Workflow preview

Workflow preview
100%
Secure AI agent webhook with HMAC, replay protection, and OpenAI GPT-5 preview
Open on n8n.io

1. Workflow Overview

️ Disclaimer: I am not a cybersecurity expert . This workflow was built through research and with the assistance of an LLM (Claude Opus 4.6). While it implements well established security pat...

Best for

  • SecOps automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.if, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.respondtowebhook, n8n-nodes-base.code, n8n-nodes-base.crypto, n8n-nodes-base.stickynote, n8n-nodes-base.webhook

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Dataki.

Original n8n.io source

1.1 Workflow description

Title
Secure AI agent webhook with HMAC, replay protection, and OpenAI GPT-5
Workflow name
Secure AI agent webhook with HMAC, replay protection, and OpenAI GPT-5

⚠️ Disclaimer:

> I am not a cybersecurity expert. This workflow was built through research and with the assistance of an LLM (Claude Opus 4.6). While it implements well-established security patterns (HMAC-SHA256, timing-safe comparison, replay protection, strict payload validation), please review the logic carefully and ensure it meets your own security requirements before deploying it in production.

Who is this for?

This template is for anyone exposing an n8n workflow via webhook and wanting to ensure that only authenticated, untampered requests are processed.

What problem does this solve?

Public webhooks are vulnerable by default. Without proper verification, anyone who discovers your URL can send forged requests, replay old ones, or inject unexpected parameters. While n8n's built-in Webhook authentication modes (Basic Auth, Header Auth, JWT) verify who is calling, they don't verify that the payload hasn't been altered, that the request is fresh, or that the data structure matches what you expect. This template adds those missing layers:

  • Authentication — Verifies the sender's identity through HMAC-SHA256 signature validation
  • Integrity — Ensures the payload hasn't been modified by signing the raw body byte-for-byte
  • Replay protection — Rejects requests with expired timestamps (configurable, default: 5 minutes)
  • Payload sanitization — Strict whitelist filtering blocks unauthorized fields before they reach your logic

What this workflow does

The workflow chains six security layers before any business logic runs:

  1. Webhook receives the request with Header Auth + Raw Body enabled to preserve the original payload
  2. Extract rawBody (Code node) decodes the binary into a UTF-8 string and extracts the security headers
  3. Crypto computes the HMAC-SHA256 signature of {timestamp}.{rawBody} using your HMAC secret
  4. Timing-Safe HMAC Check (Code node) validates the timestamp freshness and compares signatures using crypto.timingSafeEqual()
  5. Strict Payload Validation (Code node) parses the JSON, checks required fields, and rejects any unexpected keys
  6. AI Agent processes the prompt only after all checks pass

Invalid requests are immediately rejected with 403 Forbidden (signature/timestamp failure) or 400 Bad Request (payload validation failure), with no response body to avoid leaking internal logic.

Example use case

The included example protects an AI Agent endpoint that expects a simple {"prompt": "..."} payload. But this is just a starting point — replace the AI Agent with any node and adapt the payload validation to your own schema.

Common adaptations:

  • CRM or SaaS event callbacks
  • CRUD operations on a database
  • Third-party API integrations

Setup

Prerequisites

  • An n8n instance (Cloud or Self-hosted)
  • A shared HMAC secret between the sender and this workflow — keep it safe and never expose it in workflow logs or execution data

Going further

This workflow is a solid starting point — it's more secure than a raw exposed webhook.

However, it focuses on application-level security (authentication, integrity, replay protection, payload sanitization).

For a production-grade setup, consider adding layers at the infrastructure level :

  • Rate limiting
  • IP whitelisting
  • Reverse proxy hardening

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - If1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 2 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 3.1

Block 3 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.3

Block 4 - Response to webhook : Forbidden

Type / Role
n8n-nodes-base.respondToWebhook - respondToWebhook
Config choices
Version 1.5

Block 5 - Bad Request

Type / Role
n8n-nodes-base.respondToWebhook - respondToWebhook
Config choices
Version 1.5

Block 6 - Strict Payload Validation

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 7 - Crypto

Type / Role
n8n-nodes-base.crypto - crypto
Config choices
Version 2

Block 8 - If2

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 9 - Timing-Safe HMAC Check

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 10 - Extract rawBody

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 11 - Sticky Note8

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2.1

Block 13 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Secure AI agent webhook with HMAC, replay protection, and OpenAI GPT-5
Complexity advanced
Nodes 16
Categories SecOps, AI Chatbot
Author Dataki
Published 30 Mar 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/14486/14486.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Secure AI agent webhook with HMAC, replay protection, and OpenAI GPT-5 do?

️ Disclaimer: I am not a cybersecurity expert . This workflow was built through research and with the assistance of an LLM (Claude Opus 4.6). While it implements well established security pat...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your SecOps, AI Chatbot use case.