FlowKit

Does n8n store my API keys securely? Encryption, the master key and hardening

By Clément Lacaille (Tech-Bharat) · Published 21 July 2026 · updated 28 November 2026 · 13 min read · how we build and test

FlowKit Library — the English guides — €69

5 PDF guides in English in one ZIP · €115 bought separately · 14-day guarantee

See the library

Yes, n8n stores your API keys securely: every credential is encrypted at rest with AES-256, using a key unique to your instance (N8N_ENCRYPTION_KEY), so the database never holds an API key in plain text. The whole system rests on that one master key: whoever holds both the key and a copy of the database can read every secret. What n8n does not do for you is back up that key, keep it strong, decide who may use each credential, or rotate the keys: that part is yours, and it is what this guide covers, with what n8n's source code actually does.

Credentials are the most sensitive part of an n8n workflow: an OpenAI API key, a Stripe token, a database password — anything that grants access to an external system passes through them. n8n encrypts them properly by default, but "encrypted by default" doesn't mean "safe to ignore." Here's how to manage credentials seriously, from baseline encryption to rotating keys in production.

Clear padlock and its keys
Clear padlock and its keys. Photo: zaphad1, CC BY 2.0

What the encryption covers, and what it doesn't

The encryption protects a key while it sits in the database. It stops protecting it as soon as the key travels outside a credential:

  • A key typed into a node parameter, a Set node, an expression or a Code node is not a credential: it is stored with the workflow and comes out in clear text in every JSON export, whereas an export only references a credential by its ID and name.
  • Execution data: if a node outputs the key (a Code node that returns it, a debug Set node), it is saved with the execution and visible to anyone who can open that execution.
  • The request itself: n8n decrypts the credential at run time and sends it to the API you call. We tested the HTTP Request node in our lab (n8n 2.45.7, 31/10/2026) against an API that redirects to another domain: with the default settings, a Bearer Auth credential's Authorization header was dropped, but the X-API-Key header of a Header Auth credential was forwarded to the destination domain. For a key sent in a custom header to an API whose redirects you don't control, turn off Follow Redirects (Redirects option) or use Bearer Auth when the API accepts it.
  • The instance key: anyone who holds both a copy of the database and the N8N_ENCRYPTION_KEY can decrypt every credential. Keep them apart.

That redirect test, and the authentication options of the HTTP Request node (generic credential types, OAuth2 without a dedicated node), are covered in our PDF guide Connect Any API (€24).

How n8n encrypts your credentials

Every credential saved in n8n is encrypted at rest with AES, using a key unique to your instance: the N8N_ENCRYPTION_KEY. It's generated automatically on first startup if you don't set it yourself, and stored locally (in ~/.n8n/config on a typical self-hosted setup). That key — and only that key — is what lets n8n decrypt your credentials to run a workflow.

In practice, that means n8n's database (Postgres or SQLite depending on your install) never holds your API keys in plain text, even if someone gets direct access to it. That's good news for data-at-rest security, but it also creates a single point of failure that deserves to be taken seriously.

What the source code shows: AES-256 and a fast key derivation

We read n8n's encryption code in November 2026 (aes-256-cbc.ts in the public n8n-io/n8n repository). Credentials are encrypted with AES-256-CBC in the OpenSSL "Salted__" format: each encryption draws an 8-byte random salt, and the actual AES key and IV are derived from your N8N_ENCRYPTION_KEY plus that salt with a single pass of MD5. The data encryption keys used by key rotation go through a separate AES-256-GCM implementation with HKDF (aes-256-gcm.ts).

That derivation is fast by design, with no deliberately slow function such as PBKDF2 or scrypt. The practical consequence: the strength of the whole scheme is the randomness of your key.

  • The key n8n generates itself is 24 random bytes encoded in base64 (instance-settings.ts): far beyond any brute-force attempt.
  • A key you chose by hand (a company name, a phrase, a short password) is the weak case: someone holding a leaked SQLite file or Postgres dump can try candidate keys offline, at full speed, without ever touching your instance.
  • Generate yours with openssl rand -hex 24, never commit it, never bake it into a Docker image you publish, and keep the database backups and the key in two different places.

The same key also signs your login sessions

One dependency is rarely mentioned. If N8N_USER_MANAGEMENT_JWT_SECRET is not set, n8n builds the secret that signs its session tokens from the encryption key itself: every other character of N8N_ENCRYPTION_KEY, hashed with SHA-256 (jwt.service.ts). A leaked encryption key is therefore more than a credentials problem: it is enough to compute that signing secret. Setting N8N_USER_MANAGEMENT_JWT_SECRET to its own random value, as listed in the user management variables, separates the two. Set it once and leave it alone: changing it invalidates the tokens already issued, so everyone has to log in again.

Never lose your encryption key

This is self-hosted mistake number one: the N8N_ENCRYPTION_KEY isn't backed up anywhere by default outside the instance itself. Lose the server, the Docker volume, or simply the config file without having copied it elsewhere, and every existing credential becomes permanently unreadable — not "hard to recover," unreadable, full stop. You'd then have to recreate every credential by hand in every workflow that uses it.

The fix is simple and belongs on your production checklist:

  • Set the value yourself instead of letting n8n generate it, via the N8N_ENCRYPTION_KEY environment variable defined before the first startup (on a running instance, copy the existing key from .n8n/config first: our N8N_ENCRYPTION_KEY guide covers that step and the "Mismatching encryption keys" error).
  • Back it up separately from the n8n database: a team password manager, a secrets vault — never a text file sitting in the same folder as everything else.
  • Include it in your disaster recovery procedure, alongside the workflow backups described in our guide on versioning n8n workflows with Git — a workflow export without its matching encryption key won't restore the credentials that go with it.
  • In queue mode, give every worker the same key: n8n's documentation requires the N8N_ENCRYPTION_KEY variable on all workers, not just the main instance.

Rotating the encryption itself (self-hosted)

N8N_ENCRYPTION_KEY is not meant to change. What n8n can rotate is a second layer: a data encryption key, stored encrypted in the database and protected by the instance key, which is the one that actually encrypts the credentials. According to n8n's documentation, this is available on every self-hosted edition but not on n8n Cloud; it is on by default from n8n 3.0, and on n8n 2.x you turn it on with N8N_ENV_FEAT_ENCRYPTION_KEY_ROTATION=true on the main instance and every worker. The instance owner then rotates from Settings > Data Encryption Keys. Take a full database backup first: older n8n versions can't read data written with a data encryption key, and before n8n 2.40.3, turning the feature off again makes that data permanently inaccessible.

Credentials in the UI vs. environment variables

n8n gives you two ways to feed a secret to a workflow, and they don't serve the same purpose.

Credentials stored in the UI are the default option, and the right one for the vast majority of cases: an OpenAI API key, a Slack token, database login details. They're encrypted with the N8N_ENCRYPTION_KEY, reusable across multiple workflows, and — crucially — governed by n8n's permission system, so you can share them with a team without exposing the actual value.

Environment variables fit better for instance-wide secrets: the encryption key itself, access credentials for an external secrets manager, configuration that never changes and applies to the whole installation rather than to one specific business workflow. They don't get the same granular sharing model as UI credentials, so reserving them for genuine infrastructure secrets keeps you from losing track of who can see what.

Since n8n 2.0, workflows can no longer read them by default: N8N_BLOCK_ENV_ACCESS_IN_NODE now defaults to true, which blocks $env in the Code node (n8n 2.0 breaking changes). Leave it that way on a shared instance: switched back to false, it lets anyone who edits a workflow read every variable of the process, database password included. Our n8n environment variables guide lists the rest of that family of settings.

Who can see what: permissions and team sharing

On n8n Cloud (Team plan and above) and on self-hosted n8n Enterprise, credentials are organized into projects: each credential belongs to a project, and only members with access to that project can use it inside a workflow. A credential can also be shared individually with a specific user or role, without granting access to the whole project.

The principle to apply is the same as with any privileged access: least privilege. A freelancer building a scraping workflow doesn't need to see the production Stripe credential. On Community edition instances (no projects), that granularity doesn't exist — every user with instance access can potentially use every credential, which is a strong argument for moving to Enterprise or Cloud Team as soon as more than two or three people share the same instance.

Backlit computer keyboard in the dark
Backlit computer keyboard in the dark. Photo: Colin, CC BY-SA 4.0

Rotating an API key without breaking production

Regular API key rotation is basic hygiene that gets pushed off constantly — "what if it breaks a production workflow?" With n8n, the move is actually simple, because the credential is an object independent of the workflow itself:

  1. Generate the new key with the provider (OpenAI, Stripe, etc.) without revoking the old one right away.
  2. Open the existing credential in n8n and swap the value — every node that references this credential switches over automatically, without touching a single workflow.
  3. Run a test execution on a representative workflow to confirm the new key works.
  4. Revoke the old key on the provider's side once the switch is confirmed.

The key point: you never edit the workflows themselves, only the credential's contents. That's exactly why you should never duplicate an API key hardcoded across multiple nodes — rotation then turns into a treasure hunt across every workflow instead of a single edit in one place.

Avoiding leaks: the Code node trap

The sneakiest risk isn't a stolen credential — it's an accidental leak. An API key pasted directly into a Code node instead of being referenced via $credentials, or an expression like {{ $json.apiKey }} that surfaces the plain-text value in the execution panel — both can end up visible in execution logs, in a JSON export shared with a colleague, or in a screenshot sent for support.

The phenomenon is massive and well documented: a study by Meli, McNiece, and Reaves, presented at the NDSS Symposium in 2019, scanned billions of public files on GitHub and found hundreds of thousands of repositories containing secrets leaked by mistake (API keys, tokens, database credentials), with several thousand new secrets leaking every single day (Meli, McNiece & Reaves, 2019, NDSS Symposium). An n8n workflow export shared carelessly, or accidentally pushed to a public Git repository, reproduces exactly that scenario at the scale of a single company.

A few simple habits prevent most leaks:

  • Always reference a secret through a node's dedicated credential (HTTP Request, Postgres, Slack, etc.), never as a hardcoded value in a Set or Code node.
  • If a Code node seems to need a secret, move the call that uses it into an HTTP Request node with a credential and keep the Code node for the logic; since n8n 2.0, $env is blocked in the Code node by default anyway.
  • Before sharing a workflow export or a screenshot, check that no credential value shows up in visible fields or displayed execution data.
  • Treat every inbound webhook with the same rigor described in our guide on securing a public n8n webhook: a well-protected credential is worthless if access to the workflow itself is wide open.

Auditing which credentials each workflow uses

Before a production launch or a security audit, it's worth knowing exactly which workflow uses which credential — and, more importantly, which credentials nobody uses anymore. n8n's built-in security audit answers the second question: the CLI command n8n audit --categories=credentials --days-abandoned-workflow=90, or POST /api/v1/audit on the public API (scope securityAudit:generate), returns a credentials report in three sections: credentials not used in any workflow, not used in any active workflow, and not used in recently executed workflows. We ran it on a Community 2.45.7 instance: the report gives IDs and names only, and only the first section is safe to act on without asking around, since a credential tied to an unpublished workflow may belong to a sub-workflow or a yearly job. Our PDF guide Public API and CLI Administration (€29) includes a script that joins the report with the credential list (type, creation date) into a CSV you can hand to the owners of each integration.

This kind of audit follows the same logic as the GDPR audit trail with n8n and Supabase: knowing who has access to what, and being able to prove it, is part of the baseline expectation as soon as a workflow touches sensitive data or payment systems.

Self-hosted: environment variables and an external secrets manager

Self-hosted, you get a layer of control that n8n Cloud doesn't offer: direct server access. That makes it possible to harden secret management further:

  • Isolate sensitive environment variables in a .env file that's never committed to your infrastructure config repository.
  • Encrypt the disk volume hosting the n8n database, on top of the application-level encryption already provided by N8N_ENCRYPTION_KEY.
  • Wire in an external secrets manager (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault…) for organizations that already run automated rotation policies across their whole infrastructure. n8n's built-in External Secrets feature (Enterprise plans) references those values from credential fields with {{ $secrets.<vault>.<secret> }} instead of storing them in n8n; our External Secrets guide covers the setup and its limits. That's added complexity worth considering only if it already exists elsewhere in your stack.

This is the same trade-off between simplicity and control we cover in our comparison, n8n self-hosted vs cloud: more control, but also more operational responsibility for secret security.

The n8n API key is not a credential

Two different secrets are often confused. Credentials hold the keys your workflows send to other services (OpenAI, Stripe, Slack). The n8n API key, created under Settings > n8n API and sent in the X-N8N-API-KEY header, opens your own instance's public API: reading and changing workflows, reading executions, provisioning credentials. A leaked n8n API key is administrative access to the instance, not access to one service.

It leaks through the same channels as any key: a script committed to Git, a workflow export where it was pasted into a node parameter, a screenshot, a Code node that logs it. Give each use its own key with limited scopes and an expiration, run a secret scanner on your repositories, and revoke a key the moment it shows up somewhere it shouldn't: deletion in Settings > n8n API takes effect immediately. Our guide to creating and securing the n8n API key walks through scopes, storage and revocation.

A hardened baseline for a self-hosted instance

Each line below comes from n8n's documentation of the security, nodes and user management variables:

# Master key: random, set before the first start, same value on every worker
N8N_ENCRYPTION_KEY=<output of openssl rand -hex 24>
# Session signing secret, separate from the master key
N8N_USER_MANAGEMENT_JWT_SECRET=<another random value>
# Workflows cannot read the process environment ($env)
N8N_BLOCK_ENV_ACCESS_IN_NODE=true
# Session cookie sent over HTTPS only (default: true)
N8N_SECURE_COOKIE=true
# Two-factor authentication available to users (default: true)
N8N_MFA_ENABLED=true
# Nodes not loaded: the default already excludes these two
NODES_EXCLUDE="[\"n8n-nodes-base.executeCommand\", \"n8n-nodes-base.localFileTrigger\"]"

Around those variables: serve the editor through an HTTPS reverse proxy, restrict who can reach it (VPN or an IP allow list) while the webhook paths stay public, ask every account to turn on two-factor authentication, and apply least privilege everywhere the key lives: who can log into the server, who can read the database and its backups, who can build workflows in which project. The blast radius of a leak is defined by who controls the key.

Then stay current. n8n publishes its security fixes as GitHub security advisories on the n8n-io/n8n repository, and its SECURITY.md points vulnerability reports to the n8n vulnerability disclosure program. A flaw that lets someone read arbitrary files on the server matters more than its label suggests: the ~/.n8n/config file holds the encryption key when you did not set it as a variable. Our method for updating n8n in Docker without breaking production turns that into a routine.

If you'd rather have someone review this setup on your own instance, you can ask an n8n integrator for a security review of your instance (credentials, keys, access, updates).

Wrapping up

n8n credential security comes down to a short list of rules, but they don't forgive being ignored: generate a random N8N_ENCRYPTION_KEY and back it up separately from the database, reserve environment variables for infrastructure secrets, scope access by project, rotate API keys through the credential rather than hardcoding them in nodes, and audit regularly who's using what. If you're starting from a fresh instance, the lowest-friction path is the earliest one: building these habits in from the first credential you create costs a few minutes; fixing them after a leak costs a lot more. The Compliance & Audit Pack gives a practical case: its setup guide covers creating the credentials and protecting the Supabase key that feeds the audit trail.

FAQ

Frequently asked questions

Does n8n store my API keys securely?

Yes. Every credential saved in n8n is encrypted at rest with AES-256, using a key unique to your instance, the N8N_ENCRYPTION_KEY, so the database (Postgres or SQLite) never holds your API keys in plain text. The weak point is the key itself: it is not backed up anywhere by default, and losing it makes every stored credential unreadable.

Is n8n's credential encryption strong enough if my database leaks?

With the key n8n generates itself (24 random bytes), yes: the ciphertext in the database is useless without that key. The catch is the key derivation: n8n's AES-256-CBC code turns the key into the actual AES key with a single pass of MD5 and a random salt, not a slow function like PBKDF2 or scrypt, so a short or guessable key you typed yourself can be brute-forced offline from a stolen backup. Use a random key (openssl rand -hex 24) and keep it away from the database backups.

Where does n8n store credentials?

In the instance's database (SQLite or Postgres), encrypted with AES before they are written. What sits in the database is the encrypted value; the key that decrypts it, N8N_ENCRYPTION_KEY, lives outside it, in the ~/.n8n folder or an environment variable. A workflow's JSON export only references the credential by its ID and name, not its value.

Can other users in my n8n instance see my API keys?

Not the value itself: sharing a credential lets a colleague use the connection in a workflow without reading the secret. Two things still open the door: on Community edition (no projects), every user with access to the instance can use every credential in their own workflows, and anyone allowed to use a credential can point an HTTP Request node at a server they control and have the key sent there. Restrict who can build workflows, and use projects where your plan includes them.

What happens if I lose my N8N_ENCRYPTION_KEY?

You lose access to every stored credential: n8n can no longer decrypt them, and they become unreadable strings. You'd have to recreate each credential by hand (API keys, OAuth tokens, database passwords) in every workflow that uses it. It's the longest outage to recover from on n8n, and it's entirely avoidable with a proper backup of the key.

Can I change N8N_ENCRYPTION_KEY without losing my credentials?

Not by simply replacing the value: changing N8N_ENCRYPTION_KEY re-encrypts nothing, so n8n either refuses to start (Mismatching encryption keys) or starts with every credential unreadable. On self-hosted n8n, rotate the data encryption keys from Settings > Data Encryption Keys instead (on n8n 2.x, after setting N8N_ENV_FEAT_ENCRYPTION_KEY_ROTATION=true). To truly move to a new instance key, export the credentials decrypted with n8n export:credentials --decrypted, import them on an instance started with the new key, then delete the plain-text file.

Should API keys live in the n8n UI or in environment variables?

Encrypted credentials in the UI cover most cases: they're shareable across workflows, manageable through n8n's permission system, and your team can rotate them without touching the server. Environment variables are better suited to instance-wide secrets (the encryption key itself, access to an external secrets manager) rather than business-specific API keys tied to a single workflow.

How do I rotate an API key without breaking production workflows?

Generate the new key with the provider without revoking the old one, update the value inside the existing n8n credential (the same credential, so every node referencing it switches automatically), run a test execution, then revoke the old key on the provider's side. You never need to touch the workflow itself — only the credential's contents change.

Do I need an external secrets manager like Vault with n8n?

Not for most teams. n8n's built-in encrypted credential system, combined with sound permission management and a properly backed-up N8N_ENCRYPTION_KEY, covers the essentials. An external secrets manager (Vault, AWS Secrets Manager) starts to make sense in self-hosted setups when you already have automated rotation policies across your whole infrastructure, not just for n8n.

Does n8n Cloud have access to my API keys?

On n8n Cloud you don't run the server: n8n operates the instance and manages its encryption key, so you cannot hold that key yourself, back it up yourself or rotate it (n8n's data-key rotation is documented for self-hosted instances only). If your security policy requires that only your organisation can decrypt the credentials, self-hosting is the setup that gives you that control.

FlowKit Library — the English guides

€69