Skip to content

An Anthropic API key is exposed in my app. What should I do?

Short answer

Short answer: revoke the exposed key in the Anthropic Console, review usage, and make provider requests only from protected server code. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.

Check yours now
Read-only. No writes or row contents.

What the exposed Anthropic API key check covers

An Anthropic API key included in a public JavaScript bundle can be copied and used outside your application. The resulting requests are associated with the organization and key permissions that issued it.

The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.

A scanner may mask a detected value to avoid repeating it. Do not post the raw key into an issue or chat; use the provider's console to identify and revoke the affected credential.

Understand the evidence before changing code

Disable the exposed key, review available usage and organization activity, then create a replacement only after the server-side path is ready. Keep the replacement in your hosting secret manager.

Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.

Apply the narrow, safe change

Move the Anthropic API call to a server route or trusted function. Authenticate the user, validate the requested operation, set limits, and return only the result the client needs—not the key or provider headers.

Keep the credential in server code · ts
const apiKey = process.env.ANTHROPIC_API_KEY;
if (!apiKey) throw new Error("ANTHROPIC_API_KEY is not configured");
// Authenticate and authorize before making the provider request.

Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.

Verify the production result

Deploy the change and inspect the final browser assets for old key patterns. Test that the route works for the intended user and rejects direct anonymous calls or excessive request sizes.

Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.

Keep the issue from returning

Use separate development and production credentials, give them distinct names, and restrict who can access each one. Add a build scan so an accidental frontend import fails before publishing.

Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.

Limits and next steps

The public scan cannot reveal whether a credential was used or which data was processed. Review the provider's available organization activity and address any unexpected usage with Anthropic.

Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.

A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.

Key facts

  • A public API key can be replayed outside the app that originally shipped it.
  • A server endpoint must authorize callers independently of its UI.
  • Replacing source text does not invalidate the old credential.

Questions

Can a clean exposed Anthropic API key check prove the app is secure?
No. It is evidence about the advertised public surface only. Revoke a confirmed exposed key in the Anthropic Console.
What should I do first if the finding is real?
Review usage, rotate the credential, and proxy requests through protected server code.
Does ProofForge change application data?
No. The scan is read-only and does not sign in, write records, or use a discovered secret. You make and review any remediation in your own project.
What should I do after the repair?
Verify the production bundle and confirm the endpoint rejects anonymous requests.

Official documentation referenced

Related

Last updated 2026-11-25 · Reviewed by ProofForge · Methodology · Markdown