# A Stripe secret key is exposed in my app. How do I fix it?

> Short answer: roll or revoke the exposed Stripe secret key, inspect recent activity, and keep payment operations on the server. 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.

## What the exposed Stripe secret key check covers

A Stripe secret key is a server credential, not a browser publishable key. If it appears in client code, a visitor may be able to call APIs allowed by that key outside your checkout interface.

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.

Identify whether the value is a secret or restricted key, but do not paste it into a third-party checker. A publishable key is intended for client use; secret and restricted keys need server-side handling.

## Understand the evidence before changing code

Use Stripe's key-management controls to roll or revoke the exposed key and review available request logs and account activity. Update every dependent server service before removing the old credential.

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

Keep the replacement in a server secret store and create checkout sessions or other privileged operations through authenticated backend code. Never return the secret to the browser or embed it in a redirect URL.

Create a session on the server:

```ts
const stripeKey = process.env.STRIPE_SECRET_KEY;
if (!stripeKey) throw new Error("Stripe is not configured");
// Authenticate the buyer before creating a checkout session.
```

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 new server configuration, inspect the public assets for the old key, and run a test payment in the appropriate environment. Verify webhook signatures separately and do not use test keys in production.

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 restricted keys where the required API permissions allow, separate live and test environments, and set a rotation owner. Add a CI scan for secret prefixes in the final build.

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

A public scan cannot establish whether a key was used or whether a payment was altered. Review the Stripe Dashboard's available logs and follow Stripe's incident guidance if you see unknown requests.

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.

## FAQ

**Can a clean exposed Stripe secret key check prove the app is secure?**

No. It is evidence about the advertised public surface only. No. Publishable keys are intended for client code; secret and restricted keys are not.

**What should I do first if the finding is real?**

Roll or revoke the key, review account activity, and update the server-side secret.

**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?**

Check production assets, test checkout, and verify webhook signature handling.

## Key facts

- Stripe publishable keys and secret keys have different intended locations.
- A secret key can call APIs beyond the visible checkout flow.
- Webhook signature verification is separate from protecting the API key.

## Sources

- [docs.stripe.com](https://docs.stripe.com/keys)
- [docs.stripe.com](https://docs.stripe.com/keys-best-practices)

## Related

- https://proofforge.live/fix
- https://proofforge.live/tools
- https://proofforge.live/check
- https://proofforge.live/methodology

---
Last updated 2026-11-25 · Reviewed by ProofForge. Methodology: https://proofforge.live/methodology. Scan your app: https://proofforge.live/
