Skip to content
Payments · Secret guide

Leaked Stripe Test Secret Key: what to do in the first hour

High severityChecked liveLast verified · 5 min read

A Stripe test secret key works only against test mode: it can create fake customers, fake charges and test webhooks, but it moves no real money and reads no real customer. That is why it is rated lower than a live key. It is still a leak worth handling, for two reasons. A test key left in a repository often sits next to the live one in the same configuration, and a key that leaks once tells you something about how the project handles secrets. Roll the key, then check whether a live key leaked with it.

Check your GitHub account for leaked secrets — free

Provider
Stripe
Severity
High
Impact
Limited impact
Checked live by LeakWatch
Yes
Revoke at
Stripe

What a Stripe test secret key looks like

A test secret key starts with sk_test_ followed by a long run of letters and digits. A restricted key, which carries only the permissions chosen for it, starts with rk_test_ or rk_live_:

sk_test_XXXX…XXXX   Stripe test secret key (masked, 24 or more characters after the prefix)
rk_test_XXXX…XXXX   Stripe restricted key, test mode (masked, 24 characters after the prefix)

The prefix tells you the mode and the type. sk_ is a secret key, rk_ is a restricted key, pk_ is a publishable key that is meant to be public, and test or live is the mode. A sk_live_ or rk_live_ key acts on real money and is a different, much more serious guide. In code you will find them in variables such as STRIPE_SECRET_KEY, STRIPE_API_KEY or STRIPE_TEST_KEY, in the Authorization: Bearer header of an API call, or in the constructor of a Stripe client library.

How Stripe test secret keys get leaked

  • Tutorials and quickstarts. Sample code that is copied with a real test key typed in, and then committed.
  • Environment files. A .env that holds both the test and the live key and is pushed by mistake.
  • Test suites and CI. Integration tests that need a test key, with the value written in the test configuration or in a public pipeline file.
  • Front-end by mistake. A secret key placed in browser or mobile code instead of the publishable one, because the sample used the wrong variable.
  • Shared screenshots and tickets. A Dashboard page showing the revealed key, or a request pasted into a support thread.

What to do in the first hour

  1. Search the same files for live keys. Before anything else, look in the repository, its history and the environment file for sk_live_ and rk_live_. If one is there, switch to the live key guide and handle it first.
  2. Open the API keys page of the Stripe Dashboard in test mode (see the link below) and find the exposed key.
  3. Roll the key. Stripe lets you roll a key, which creates a new one and sets an expiry on the old one. For a test key you can choose to expire the old one right away. Restricted keys also offer a delay of up to 7 days if you want a safety window.
  4. Deploy the new key to the test environment and CI, and run your test suite once.
  5. Check test-mode logs. In the Dashboard in test mode, look at the request logs and events since the exposure. Look for traffic that does not come from your servers or test runs.
  6. Check test webhooks. Look at the webhook endpoints and the events sent. A stolen key could register an endpoint that receives your test events.
  7. Review restricted keys. If a rk_ key leaked, check its permissions and give any new one only what it needs.
  8. Clean up the code, keep keys out of the repository, and search for other secrets. See I accidentally pushed an API key to GitHub.

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 Stripe

Stripe keys are managed from the API keys page of the Stripe Dashboard, after you sign in with a user allowed to manage keys. Make sure the Dashboard is in test mode, because test and live keys are listed separately. Find the exposed key and roll or delete it. The Stripe documentation on API keys explains rolling, expiration of the old key, and restricted keys. A person has not confirmed the exact menu wording for this guide, and the interface can change, so if what you see differs, look for the page where keys are listed and follow Stripe’s documentation.

How LeakWatch detects it

This guide covers two rules. The rule called Stripe Test Secret Key matches sk_test_ followed by at least 24 letters or digits, with no upper bound and no word boundary, so a longer key is reported whole and a key embedded in a larger string is still found. Its severity is medium. The rule called Stripe Restricted Key (test) matches rk_ followed by live or test, an underscore and exactly 24 letters or digits. Despite its name, it therefore also reports restricted live keys, and its severity is high, because a restricted key can carry real permissions. Both are case-sensitive, so SK_TEST_ in capitals is not reported, and a short body is refused.

LeakWatch can check whether a detected key is still active with a read-only request to Stripe. It never reads your data or spends your credits.

This type is checked live. LeakWatch sends one read-only request to the balance endpoint of the Stripe API, with the key as a Bearer token. A 200 answer means the key is valid, and LeakWatch only records whether the key is in live mode or test mode. A 401 answer means the key is not valid. A 403 answer means the key authenticated but a restricted key lacks the balance permission, which still counts as valid. A 429 answer is recorded as rate limited, and nothing else is stored from the response.

FAQ

Can someone charge real cards with a test secret key?

No. A test key only acts on test-mode data, which has no connection to real cards, customers or payouts. The risk is that a live key sits in the same place.

Why is the restricted key rule rated higher than the test key rule?

It also matches restricted live keys, and a restricted key can have real permissions such as reading customers or creating charges. Check its mode and permissions in the Dashboard before deciding how serious it is.

Do I need to roll a test key if I already deleted the file?

Yes. Once a key has been in a public commit, removing the file does not remove it from the history or from copies. Roll it.

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

LeakWatch is not affiliated with Stripe.