PC-001CRITICALSecrets & API Keys

Stripe Live Secret or Restricted Key Exposed

Detects hardcoded Stripe production secret keys (sk_live_) and live restricted keys (rk_live_) in source files, scripts, or configuration manifests before they enter Git history.

Rule Slug
stripe-live-secret-key
Affected Files
*
Detection Method
Regex + Entropy (>= 3.2)
Live Rule Tester100% Browser-Local
CRITICAL: Detected 1 violation
Line 5:sk_live_51N9••••••••••••••fG8kL2(entropy: 4.837)

Vulnerable Pattern vs. Hardened Fix

Vulnerable Pattern
// payments/stripeClient.ts
import Stripe from 'stripe';

// CRITICAL: Production secret key hardcoded in source
export const stripe = new Stripe('sk_live_51N9xK2L8pQ4mV7wR9zT3yB6cH1jD4fG8kL2', {
  apiVersion: '2024-06-20',
});
Recommended Fix
// payments/stripeClient.ts
import Stripe from 'stripe';

const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
if (!stripeSecretKey) {
  throw new Error('Missing STRIPE_SECRET_KEY environment variable');
}

export const stripe = new Stripe(stripeSecretKey, {
  apiVersion: '2024-06-20',
});

Why This Fails in Production

A Stripe live secret key grants full programmatic authority over your production Stripe account. Unlike publishable keys (pk_live_), which are intentionally embedded in frontend checkout code and restricted to tokenization flows, an exposed sk_live_ credential permits any caller to issue unauthorized refunds, list customer records, read billing metadata, create payouts, cancel active subscriptions, or alter webhook endpoints. Even a live restricted key (rk_live_) carries significant blast radius depending on its scoped permissions, frequently exposing customer PII, invoice histories, or charge endpoints.

Automated secret-scraping bots continuously monitor public GitHub events, package registries, and client-side JavaScript bundles in near real time. Security incident post-mortems consistently show that live Stripe credentials pushed to a public repository are discovered and probed within seconds, often faster than a developer can run git revert or force-push an amended commit. Because Git stores immutable object snapshots, deleting the line in a follow-up commit leaves the exposed credential permanently accessible in the commit tree unless history is rewritten and the key is immediately revoked.

The operational fallout extends beyond direct financial fraud. When Stripe detects or is notified of a leaked live secret key, automated risk controls may force-roll the key immediately, breaking live checkout sessions, webhook verification, and subscription renewals until your deployment pipeline is updated with a replacement key. Worse, if the key was committed to a private repository shared across contractors, CI logs, or forked mirror environments, any compromise of a single developer workstation or build artifact can silently harvest the static credential without triggering public leak alerts.

Keeping Stripe keys strictly inside runtime secret managers or deployment environment variables, and validating local workspaces before every push, eliminates both immediate financial exposure and emergency production downtime caused by forced credential rotation.

Remediation Steps

  1. 1Immediately roll or revoke the exposed key inside the Stripe Dashboard under Developers -> API Keys; choose an expiration window of "Now" if the key reached any public or shared Git remote.
  2. 2Audit Stripe Dashboard -> Developers -> Logs for unexpected API calls, refunds, payout destination changes, or newly registered webhook endpoints during the exposure window.
  3. 3Remove the hardcoded key from source code and reference process.env.STRIPE_SECRET_KEY (or your runtime equivalent) injected through your hosting provider secret store.
  4. 4If the secret was already committed to Git, scrub the commit history with git-filter-repo or BFG Repo-Cleaner, force-push cleaned branches, and treat the old key as permanently compromised.

Frequently Asked Questions

Are Stripe publishable keys (pk_live_) dangerous to commit?
Publishable keys (pk_live_ and pk_test_) are designed for client-side use in Stripe.js and Checkout to tokenize payment methods. They cannot read sensitive account data or initiate refunds, so PushCheck specifically targets sk_live_ and rk_live_ secret credentials.
Does PushCheck flag Stripe test keys (sk_test_)?
No. This rule targets live production prefixes (sk_live_ and rk_live_) to avoid noisy alerts on local test fixtures. However, you should still store sk_test_ keys in ignored .env files rather than committing them to shared repositories.
Is deleting the key in a new Git commit enough to secure my account?
No. Deleting a key in a subsequent commit leaves the original value intact in Git history. You must immediately roll the key in the Stripe Dashboard first, then clean repository history if required.

Related Secrets & API Keys Rules

Scan local project folder →