Skip to content
Exposed keys

I leaked an API key. What now?

Revoke or rotate the exposed credential through its provider first, then review usage and replace legitimate consumers safely. Deleting the string from code is not enough because earlier downloads, deployments or repository history may retain it.

Check your app free, first fix free
By Brennan ZamboUpdated
In short

Classify the value, revoke any real private credential, investigate activity and move the replacement behind the correct server boundary. Clean the source, deployment and relevant history only after access is invalidated. Keep a short incident record, verify normal users still work and check that the replacement never appears in public output.

1. Decide what was exposed without spreading it

Do not paste the complete value into a public issue, assistant chat or screenshot. Record the provider, key type, affected project and source location privately. A masked prefix and suffix are usually enough to distinguish the credential during repair. Keep the full value only where incident responders genuinely need it.

Distinguish public identifiers from secrets. A Supabase publishable key or Stripe publishable key is intended for client use; its visibility alone is not an incident. An OpenAI key, a payment secret, an administrator service-account credential or a Supabase service-role key is different. When a value is ambiguous, consult the provider's key documentation rather than testing it against random APIs.

Also distinguish an example from a real credential. A scanner can recognize a shape without proving that the key is active. Do not describe a documentation placeholder as a confirmed compromise. If you cannot determine whether a private-looking value was genuine, the provider's account controls and audit trail are a better source of truth than an outside guess.

2. Revoke the authority, not just the visible string

Use the provider dashboard or documented rotation procedure to invalidate the exposed credential. If an overlapping rotation is supported and needed to keep a critical service running, minimize the overlap and verify that the old credential is actually retired. Avoid leaving both active indefinitely because the new code appears to work.

Revocation changes the credential's authority. Removing a file merely changes one place it is distributed. Browser caches, old release assets, forks, logs and downloaded source maps can all retain copies. An attacker who already has the key does not need the current repository file to remain public.

If the credential belongs to a third party, report it privately through the appropriate channel and do not try to use it. This procedure is for accounts and applications you control. Possessing a leaked key is not authorization to access somebody else's data or account.

3. Review activity and billing

Review the provider's usage, request logs, resource changes and billing for the relevant period. Look for unexpected endpoints, locations, spend or resources, while remembering that available logs vary by provider and account. Record what you could inspect and any gaps rather than concluding that no visible spike means no misuse.

For a database administrator credential, review access and configuration changes as well as costs. For an email or messaging key, inspect sending activity. For a payment secret, review API request activity and account events without attempting real transactions as a diagnostic step. Respond to the actual authority the credential carried.

If customer data may have been accessed, involve the people responsible for incident response and applicable reporting obligations. A public scan cannot determine the full incident scope. Do not label the issue fully contained merely because a follow-up scan no longer sees the string.

4. Replace legitimate consumers safely

Create a least-privileged replacement if the integration still needs it. Keep it in trusted server-side configuration. Update each legitimate consumer deliberately, then exercise a controlled successful operation without printing the key into logs. Remove obsolete deployments or jobs that no longer need the capability.

A frontend environment prefix is not a secure place for a private key. In Vite, VITE_ values can enter the browser bundle; in Next.js, NEXT_PUBLIC_ values are client-facing. Moving a key from a source literal into one of those variables changes its location in the build process, not its exposure to visitors.

text
Containment: old credential revoked at the provider
Replacement: least-privilege credential stored on the server
Consumers: each legitimate integration updated and checked
Public output: no replacement credential in assets or responses
Investigation: usage reviewed, gaps and follow-up owners recorded

Do not make an unrestricted proxy that allows anyone to spend with the hidden key. The server endpoint needs its own authentication, authorization, validation and limits appropriate to the operation. A hidden secret with publicly available authority can still produce the same loss.

5. Remove the source and rebuild

Find how the secret reached the public output. Common paths include direct source literals, client environment variables, serialized configuration, debug responses and a private key committed beside an example. Fix the mechanism so the replacement does not repeat the mistake during the next deployment.

Search the built output as well as source. Deploy the repaired build and inspect the live page's referenced assets. If old deployment assets remain public, follow your host's supported removal process, but do not treat successful cache cleanup as the reason the old credential is safe. Its revocation is the important containment step.

Check logs and monitoring destinations for accidental copies. A debugging statement that prints all environment variables can turn a local repair into a new exposure channel. Prefer presence checks and masked identifiers when diagnosing configuration.

6. Handle Git history deliberately

Deleting a secret in a new commit leaves earlier commits intact. After revocation, decide whether repository history needs cleanup under your team's process. History rewriting changes commit identities and can disrupt branches, open changes and collaborators' clones. Coordinate it rather than automatically force-pushing during an incident.

Use the repository provider's current sensitive-data removal guidance for the actual repository. Do not promise that rewriting history erases every fork or download. Teammates may need to re-clone or follow a documented recovery process so the old commit does not get reintroduced.

Avoid publishing the incident credential as a test fixture. If you need a regression check, use a clearly synthetic value and prevent it from being interpreted as a working customer secret. The test should catch the exposure mechanism, not preserve a real credential for future readers.

7. Close the loop with bounded evidence

Recheck the public app, preserve the masked finding and record the production version tested. Separately confirm that legitimate integrations still work and that unauthorized callers cannot invoke the privileged action. A scanner can establish that a supported pattern is visible; it cannot certify every copy was removed or every unauthorized action was identified.

Document the earliest known exposure, the revocation action, the remediation and the unanswered questions. This makes future maintenance more reliable than a vague note saying the key was fixed. If the result is shared with a buyer or user, state the tested surface and avoid disclosing the replacement or private report link.

Turn the check into a release decision

Keep a small record of the production URL, the time you checked it, the exact finding and the action you took. A local preview and a deployed application can have different environment variables, response headers and database projects. After a repair, deploy the intended version and check the public address again. Do not assume that changing a repository file changed the live system.

Read coverage as carefully as the score. A timed-out asset, an ambiguous backend configuration or a request that could not safely establish access should remain unknown. It should not disappear from your release notes merely because there is no red finding. If a check was not completed, decide who will review it and what additional evidence is needed.

ProofForge's free report includes the first fix. The $9 Fix Report unlocks all findings' available repair guidance and builder prompts, with a PDF and private report link. Fix + Guard costs $29 once and adds builder rules, on-demand deploy-hook scans for 30 days and four weekly rechecks you start yourself. These are different deliverables, not different promises that an application is completely secure.

Keep private report URLs out of public issues and commits. If you need shareable evidence, use the owner-verification and publication flow for an eligible receipt. A signature protects the recorded assessment against undetected changes; it does not make the assessment exhaustive, prove a business outcome, or show that a later deployment still matches an earlier result.

Questions builders ask

Can I just delete the key and redeploy?
No. Revoke or rotate it through the provider. A deployed copy, old commit or earlier download may retain the value even after the current source is clean.
Do I need to rewrite Git history?
Possibly, after revocation and a coordinated review. Rewriting has collaboration consequences and does not recall copies already downloaded elsewhere.
Can a passing rescan prove nobody used the key?
No. It checks the observable current surface. Investigate provider activity and preserve the limits of available logs.
What if the key was designed to be public?
Review its restrictions and backend permissions. Do not revoke expected public client configuration merely because it appears in a bundle.

Continue with a related guide

Sources

Read-only, about a minute

Scan your app free

See what your live app ships to every visitor, with the first fix free. A clean scan is not a full audit. Run it only on an app you own or have permission to test.

Scan your app free
All guides