n8n Security: Complete Setup Guide for Self-Hosted Workflows
Complete guide to securing n8n: MFA, SSO, encryption, webhook validation, and network hardening. Learn how to protect against CVE-2026-21858 and CVE-2026-25049.
- Self-hosted n8n faces documented RCE vulnerabilities (CVE-2026-21858, CVE-2026-25049); you're responsible for patching on your timeline
- Enforce MFA and SSO, rotate encryption keys every 12 months, and validate all webhook signatures with HMAC-SHA256
- Deploy n8n behind a reverse proxy, disable the public API unless needed, and restrict dangerous nodes (Code, HTTP) to admins only
- Managed hosting eliminates patch management, certificate renewal, and key rotation--trades operational burden for less control
n8n security isn't optional when you're automating business workflows. Self-hosted instances face authentication gaps, credential exposure, vulnerable nodes, and webhook attacks. The good news: each risk has a known fix. This guide walks through authentication hardening, credential management, network isolation, and code restrictions--then shows you what managed hosting handles for you.
Why n8n Security Matters: Real Risks and Recent Vulnerabilities
n8n self-hosted deployments have faced real, documented attacks. In 2026, two critical remote code execution (RCE) vulnerabilities surfaced: CVE-2026-21858 exploited unauthenticated access, and CVE-2026-25049 leveraged JavaScript destructuring through public webhooks. Both allowed attackers to execute arbitrary code on the server running n8n. These weren't theoretical bugs. They were weaponized in the wild.
When you deploy n8n yourself, you own the security patch timeline. No one else is monitoring for vulnerabilities on your behalf. You're responsible for detecting CVEs, testing patches, and rolling them out before attackers find them. That window--from vulnerability disclosure to your patch deployment--is your exposure.
The attack surface is broad. n8n runs workflows that touch databases, APIs, and third-party services. A compromised n8n instance becomes a pivot point into your entire stack. The workflow editor itself is a code execution environment. Nodes can call HTTP endpoints, execute JavaScript, or query databases. If access controls fail, an attacker can inject malicious nodes into your critical workflows. If credentials aren't encrypted, they leak. If webhooks aren't validated, an attacker can trigger workflows remotely.
This isn't scaremongering. It's the reason companies running n8n self-hosted must treat it like any other production service: with authentication, encryption, network isolation, and monitoring. The setup takes hours, not days. But skipping steps is how incidents happen.
Authentication and Access Control: MFA, SSO, and Session Management
Authentication is your first gate. By default, n8n allows users to sign up without limits and stores passwords in a database. That's fine for a solo developer. It's not fine for a team, especially one handling customer data or business-critical workflows.
Start here: enforce strong passwords. Set N8N_USER_MANAGEMENT_JWT_SECRET to a 32+ character random string. Require all users to change their default passwords on first login. Remove any public signup endpoint--managed n8n hosting handles this for you, but self-hosted requires explicit configuration.
Next, enable multi-factor authentication (MFA). n8n supports time-based one-time passwords (TOTP) via apps like Google Authenticator or Authy. Require MFA for any user with workflow edit permissions. This blocks attackers who've stolen a password from logging in.
For teams with existing identity providers, configure SSO via OIDC or SAML. This centralizes credential management in your existing directory (Okta, Entra ID, etc.). Users log in once to your corporate SSO; n8n trusts that signal. This eliminates password reuse across tools and simplifies offboarding--when someone leaves, one revocation deletes access everywhere, including n8n.
Manage session tokens strictly. Set N8N_JWT_EXPIRATION to a reasonable window, like 24 hours. After 24 hours, the user's session expires and they must log in again. This limits the window an attacker has to use a stolen token. Pair this with a refresh token rotation: when a user requests a new access token, also issue a fresh refresh token. The old one becomes invalid. This pattern is common in OAuth 2.0 and reduces token reuse.
For workflows that call the n8n API programmatically, use API keys, not passwords. Create a service account with minimal permissions--only the roles and workflows it needs. Rotate keys every 90 days. This containment prevents a leaked key from granting full admin access.
Protecting Credentials and Encryption Keys
n8n stores credentials--database passwords, API keys, OAuth tokens--in a database. By default, these are encrypted at rest using a master key. That master key is your single point of failure. If an attacker gets the key, every credential in your n8n instance decrypts.
The fix: generate a strong master key and store it outside the n8n database. Set N8N_ENCRYPTION_KEY to a 32-byte random value (base64-encoded). Never hardcode it in your config file. Store it in a secrets manager--AWS Secrets Manager, HashiCorp Vault, or Kubernetes Secrets. When n8n starts, it reads the key from the secrets manager, decrypts its credential database, and operates normally.
Rotate this key every 12 months, or after a suspected credential leak. Key rotation in n8n requires downtime: you export all credentials, re-encrypt them with the new key, and re-import them. Plan this maintenance window in advance.
Within n8n's credential manager, audit which credentials exist and who can access them. Mark credentials as "shared" only if the team needs them. Most credentials should be private to the user who created them, reducing lateral movement if one user's account is compromised.
Avoid hardcoding credentials in workflows. Instead, use n8n's credential references. When a node needs a database password, don't paste the password into the node config. Select the credential from the credential manager. This keeps secrets out of the workflow JSON, which could be exported, versioned, or inspected by someone without access to the actual credential.
For external systems that support certificate-based authentication (like mutual TLS), use certificates instead of passwords. Store the certificate chain and private key as n8n credentials, then reference them in HTTP requests. This is more resistant to brute-force and phishing than password-based auth.
Securing Webhooks and the Public API
Webhooks are n8n's window to the outside world. An external service sends an HTTP request to your n8n webhook URL, and n8n fires a workflow. If webhooks aren't secured, an attacker can trigger your workflows at will.
Every webhook in n8n has a URL like https://your-n8n.com/webhook/unique-id. By default, anyone who knows the URL can trigger it. That unique ID is a secret, but it's predictable and often leaks in logs or Git history. Apply these protections:
First, enable webhook authentication. n8n supports both query string parameters and HTTP headers. Set a header like Authorization: Bearer YOUR_SECRET_TOKEN and configure the webhook to validate it. Any external service calling the webhook must include this header, or the request is rejected.
Second, sign webhook payloads with HMAC-SHA256. Configure the external service (e.g., Stripe, GitHub) to send an X-Signature-256 header containing an HMAC of the request body signed with a shared secret. Inside n8n, verify the signature before processing. This guarantees the request came from the expected service and wasn't tampered with in transit.
Third, disable the public API if you don't need it. By default, n8n exposes a REST API at https://your-n8n.com/api/. This allows external tools to trigger workflows, fetch execution history, and manage workflows via code. If your team doesn't use this API, disable it by setting N8N_PUBLIC_API_DISABLED=true. Fewer endpoints mean fewer attack vectors.
Fourth, restrict API access to known IP addresses. Use a firewall or reverse proxy to allow only your internal services and third-party webhooks to reach n8n. If Stripe is the only service calling your n8n webhook, whitelist Stripe's IP ranges.
Network Hardening: Reverse Proxy, Private Subnets, and HTTPS
n8n shouldn't face the internet directly. Place it behind a reverse proxy like Nginx or Traefik. The proxy terminates TLS, enforces HTTPS, adds security headers, and rate-limits requests. If n8n has a vulnerability, the proxy is your first line of defense.
Configure the reverse proxy with these headers:
Strict-Transport-Security: max-age=31536000; includeSubDomains- force HTTPSX-Content-Type-Options: nosniff- prevent MIME sniffing attacksX-Frame-Options: DENY- prevent clickjackingContent-Security-Policy: default-src 'self'- restrict resource loading
Use a certificate from a trusted certificate authority (Let's Encrypt is free). Renew every 90 days automatically. Never use self-signed certificates for production--they open n8n to man-in-the-middle attacks.
Deploy n8n in a private subnet with no direct internet access. If n8n needs to reach external APIs (Slack, GitHub, etc.), route traffic through an egress proxy or VPN tunnel. This containment prevents an attacker inside n8n from directly scanning your internal network.
If n8n needs to run workflows across your internal infrastructure, use a task runner or execution worker. Task runners are lightweight services deployed in your internal network that receive work from n8n and execute it locally. This way, n8n stays on the edge, and sensitive internal access stays internal.
Hardening Nodes and Code Execution
Some n8n nodes are more dangerous than others. The Code node and HTTP Request node execute arbitrary code. If a workflow editor injects malicious code, it runs with n8n's full permissions.
Restrict these nodes to trusted users only. In n8n's admin settings, disable Code and HTTP Request nodes for regular team members. Only admins can use them. This reduces the attack surface--a compromised team member can't inject a data exfiltration payload into a workflow.
Monitor community nodes. n8n allows third-party developers to publish custom nodes. They're convenient but unvetted. If you use a compromised community node, it has access to all n8n credentials and can execute code on your server. Apply this policy: community nodes are banned by default. Only admins can enable them, and only after security review.
If you do use community nodes, pin them to a specific version. Don't use "latest". If a node is updated with malicious code, your pinned version stays safe. Review node updates before upgrading.
For task runners, isolate them in separate containers or VMs. If a workflow running on a task runner is compromised, it's contained--it can't affect n8n's main instance or other task runners. Use Kubernetes network policies or Docker network namespaces to restrict which services a task runner can reach.
Keeping n8n Updated: Patches and Vulnerability Management
Self-hosted n8n is your responsibility to patch. n8n publishes updates regularly, often for security fixes. You must monitor for CVE disclosures, test patches in staging, and deploy to production--all within a reasonable window (ideally under 2 weeks for critical vulnerabilities).
Set up monitoring for new n8n releases and security advisories. Use a tool like Dependabot or Renovate to watch your Docker image registry for updates. Set up Slack alerts so your team knows within hours of a patch. Implement an automated deployment pipeline to streamline testing and rollout.
Test patches in a staging environment. Spin up a copy of your production setup with current data (sanitized of sensitive information). Deploy the n8n update and run your most critical workflows. Verify they behave the same. This catches incompatibilities before they hit production.
Schedule maintenance windows. Patching n8n requires a brief downtime--typically 5-15 minutes. Notify your team in advance. Update during low-traffic hours if possible.
For security-critical vulnerabilities (RCE, authentication bypass), patch within 24-48 hours. For moderate issues (data exposure, privilege escalation), patch within 1-2 weeks. For low-severity bugs, batch them into monthly maintenance windows.
This is where self-hosted diverges from managed hosting. Managed providers patch automatically. You're not on a maintenance window calendar. You don't miss updates because you were too busy.
What Managed Hosting Covers (And What You Still Own)
Managed n8n hosting, like Opsily's managed n8n, eliminates entire categories of work.
Opsily handles: SSL certificate management and renewal, infrastructure updates and security patches, monitoring for CVEs and attack patterns, secure credential encryption with managed key rotation, automated backups with encryption, compliance with GDPR and data residency requirements.
You still own: workflow logic and business logic, credential values (passwords and API keys), data processed by workflows, access control policy (who can edit which workflows), and monitoring your own workflows for correctness.
This division of labor reduces your security footprint. You're not patching servers or managing keys. You're not running monitoring infrastructure. You can focus on building secure workflows instead of securing infrastructure.
Compare this to self-hosted: you manage every patch, every certificate, every backup. You're responsible for the security of the entire server. One misconfiguration--like exposing the database, or running n8n as root--can compromise the whole system. For teams without dedicated DevOps staff, this is a significant operational burden.
Frequently Asked Questions
How secure is n8n compared to other automation tools?
n8n is open-source, which means anyone can audit the code and discover vulnerabilities. This transparency is both a strength and a weakness: vulnerabilities are found faster, but they're also public. Proprietary tools might hide vulnerabilities longer. For security-conscious teams, open-source is preferable because you can read the code and audit it yourself. n8n's maintenance team has demonstrated responsiveness to security reports, releasing patches within days of disclosure.
What do I do if n8n has a known vulnerability?
If your self-hosted n8n is running a vulnerable version, patch immediately. Stop n8n, pull the latest Docker image, and restart. Test critical workflows to ensure they still work. For cloud n8n, Opsily patches automatically; no action required from you. If you've exposed credentials, rotate them after patching--a vulnerability might have already leaked them.
Can I run n8n on shared hosting like a cPanel server?
No. n8n requires Docker, Node.js runtime, and a PostgreSQL or MySQL database. Shared hosting providers don't offer these tools. You need a VPS, dedicated server, Kubernetes cluster, or managed hosting. This is one reason managed hosting exists: n8n has infrastructure requirements that exceed simple uploads.
Do I need a VPN to access n8n safely?
Yes, unless you've restricted access by IP. If your n8n instance is on the public internet, use a VPN or SSH tunnel to access the editor. This prevents login attempts from random attackers scanning the web. Even better: deploy n8n in a private subnet and use a jump host (bastion) to reach it. This is standard practice for internal tools.
How do I audit which workflows ran and when?
n8n logs execution history by default. Access it in the UI under Executions. For compliance purposes, export these logs to a syslog server or S3 bucket so they can't be deleted locally. Set up alerts for failed executions, especially if they involve sensitive operations like credential reads or data deletions. Managed hosting platforms often provide audit logs separate from application logs, with long-term retention.
What's the difference between n8n cloud and self-hosted security?
n8n cloud is managed by n8n, Inc. and uses AES-256 encryption, FIPS-140-2 compliant storage, and SOC 2 Type 2 audits. You don't manage infrastructure; n8n handles patches, backups, and compliance. Self-hosted requires you to manage everything. If you have a small team and no DevOps staff, cloud is simpler. If you have strict data residency requirements or want full control, self-hosted is necessary--just budget for the operational burden.
Can I encrypt n8n's database beyond the default encryption?
Yes. Use database-level encryption: PostgreSQL with pgcrypto extension, or MySQL with Transparent Data Encryption (TDE). This provides encryption beyond n8n's built-in credential encryption. If the database is stolen, it's unreadable without the decryption key. This is recommended for high-security deployments.
The Bottom Line
n8n security is not a one-time setup. It's a series of choices: how strict your authentication rules are, how often you rotate keys, how quickly you patch vulnerabilities, and what network access you allow. Each choice trades convenience for security. The goal is to find the balance that fits your risk tolerance.
If your team is small or n8n doesn't process sensitive data, basic hardening--strong passwords, HTTPS, restricted node usage--is enough. If you're handling customer data or business-critical workflows, invest in MFA, SSO, secrets management, and routine audits.
If you don't have time to manage this yourself, explore Opsily's managed n8n hosting, which handles infrastructure security so you can focus on building workflows.