1 min read

πŸ” How to Secure Webhooks in n8n with Bearer Token & Field Validation

If you're exposing n8n workflows to the public via webhooks, you need to secure them.

In this guide, I’ll show you how to build a secure n8n webhook that uses a Bearer Token for authentication and dynamic field validation to make sure the incoming request has everything you need β€” no code-heavy setup required.

⚑ Why Secure Webhooks in n8n?

By default, n8n webhooks are public. That’s great for ease of use, but dangerous if you're expecting sensitive or structured data from clients, forms, or APIs.

With this workflow, you get:

  • βœ… Bearer Token authentication
  • βœ… Dynamic validation of required fields
  • βœ… Clean JSON responses for 200, 400, and 401
  • βœ… A modular setup you can reuse and extend

Perfect for form submissions, private APIs, or automation endpoints.


πŸ”§ How the Secure Webhook Workflow Works

Here’s a quick breakdown of what’s inside:

1. Webhook Node

Receives POST requests from external services.

2. Configuration Node

Set:

  • config.bearerToken β†’ Your secret token
  • config.requiredFields β†’ Add a key for each required field (e.g. message, email)

3. Auth Check πŸ”’

Validates the Authorization header using Bearer token logic.

4. Field Check πŸ§ͺ

Uses a Code node to loop through config.requiredFields and compare with the request body.

5. Error Handling πŸ“­

Returns:

  • 401 if the token is missing or wrong
  • 400 if required fields are missing

6. Success Response βœ…

Returns a 200 OK with your custom message.


πŸ›  How to Set It Up

  1. Download the workflow below and import it into your n8n instance.
  2. Open the Configuration node:
    • Add your Bearer token.
    • Define the required fields.
  3. Customize the success response if needed.
  4. Plug in your own logic after the validation step.

It takes 2 minutes to make your webhook production-ready.


πŸ’Ύ Download the Workflow ($2)

Want to save time and grab a clean, production-ready template?

Comes with:

  • Full validation logic
  • Config instructions
  • Modular and ready to expand

πŸ™Œ Like This? Support My Work

I build helpful tools and templates for the n8n community.

Thanks for reading! Now go secure those webhooks πŸ’ͺ