Skip to content
Databases & keys · Secret guide

Leaked Neon API Key: what to do in the first hour

Critical severityDetected onlyLast verified · 5 min read

A Neon API key is a management credential for Neon, the serverless Postgres service. It is not the connection string your application uses to read and write rows. With a management key, whoever holds it can create and delete projects and branches, manage roles, and read the connection details that include a database password. That makes it more dangerous than a single database login, because it can reach every project the account or organization owns. Revoke the key first, then check what was changed or read.

Check your GitHub account for leaked secrets — free

Provider
Neon
Severity
Critical
Impact
Cloud infrastructure access
Checked live by LeakWatch
No

What a Neon API Key looks like

Neon API keys begin with napi_, followed by a long run of letters and digits. The prefix is what identifies the type in a file:

napi_…XXXX   Neon API key (masked)

The napi_ prefix belongs to Neon. A Postgres connection string starts with postgres:// or postgresql:// and carries a database user and password, which is a separate and narrower secret. Some tools ask for both, and a leak of one often happens next to the other. A key from another vendor will not have this prefix. If you find a Neon key in a .env file, it is usually named something like NEON_API_KEY, but the name is only a hint, because the value is what the rule checks.

How Neon API Keys get leaked

  • Infrastructure scripts committed to a repository. A Terraform, Pulumi or shell script that hard-codes the key so that a branch can be created on each pull request.
  • CI variables echoed in logs. A workflow step that prints its environment, or a debug line that writes the request headers used to call the API.
  • Local environment files. A .env file used by a migration tool or a seed script, pushed by accident or copied into a shared template.
  • Notebooks and snippets. A key pasted into a notebook cell, a support request or a blog post that shows how to create a branch.
  • Front-end code. A management key placed in a browser bundle or a mobile app. Neon’s own guidance is that keys like this belong on a server or in CI, never in client code.

What to do in the first hour

  1. Revoke the key. Open the account settings in the Neon Console, go to the API keys section, find the key by its name and creation date, and revoke it. A revoked key stops working at once, so do this before you clean the code.
  2. Create a replacement only if a pipeline needs one. Name it for the job that uses it, store it in your CI secret store, and avoid sharing one key between people and automation.
  3. List what changed. Review projects, branches and roles for the period since the exposure. Look for projects you did not create, branches that copy production data, and roles that were added or given higher privileges.
  4. Rotate database passwords. If the key could read connection details, assume the database passwords for the affected projects were seen. Reset the role passwords, then update every application that connects with the old one.
  5. Check the data path. Look at network access rules and any branches or endpoints that expose data outside your team. A new branch created with a copy of production data is a common result of this kind of access.
  6. Clean the repository. Remove the value from the current files, use the secret store for the next deployment, and rewrite history if the repository is public. A deleted commit remains in clones, so the rotation is the real fix. For the wider process, see I accidentally pushed an API key to GitHub.
  7. Look at the other secrets next to it. A leaked deploy file often holds more than one credential. Revoke any other key in the same place.

Not sure what else leaked from the same repository? Run a free scan.

Not sure what else leaked? Run a free scan.

Revoke it at Neon

Personal keys are listed under the account settings in the Neon Console, in the API keys section. Keys that belong to an organization or a project are listed under that organization’s settings instead. Revocation is permanent: the Revoke button ends the key immediately, and any request that still uses it then fails. Only the account owner can revoke a personal key, and only an organization admin can revoke an organization key, so a team member may not be able to revoke a key that a colleague created. Neon does not rotate keys automatically, so the recommended approach is to create a new key, switch your callers over, and then revoke the old one. Keep in mind that the secret is shown only once, when it is created, so store the replacement immediately. If the key is not in the list you expect, check whether it belongs to a different organization.

How LeakWatch detects it

The rule is called “Neon API Key”. It looks for the prefix napi_ followed by exactly 64 letters or digits, with a word boundary before the prefix and a quote, space, semicolon or line end after the value. The rule does not depend on a variable name, so a bare key in a text file is reported too. The severity is critical, with the infrastructure and cloud impact class, because a management key can reach every project in the account. This type is not checked live: LeakWatch does not call Neon with the value, so a finding means the value has the right shape, not that it is still active.

LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.

FAQ

Is the Neon API key the same as my database password?

No. The API key manages the Neon platform, while the database password is for a Postgres role inside one project. A management key can, however, reveal connection details, so an exposed key should lead you to reset the passwords that matter.

Can I just delete the project that was affected?

Deleting a project ends the data it holds, which may not be what you want. First confirm the key is revoked, then take a copy if you need the data, and only then remove anything. Deleting a project does not, by itself, remove the attacker’s access to the key.

Who should hold a Neon API key?

Only the systems that need it, such as a CI job that creates preview branches. Give it its own name, store it in a secret manager, and rotate it when people who knew it leave the team.

Get alerted next time a secret leaks — create a free account

LeakWatch is not affiliated with Neon.