StoicBuilder

HandbookIII the CastraSecrets and API keys

IIIthe Castra, Stay in control

Secrets and API keys

1 min readUpdated 28 November

In plain words

A secret key lets your code act as you on a service like Stripe or OpenAI, so anyone who copies it can spend your money or read your data.

Where you see it

Most services hand you two kinds of key. Stripe's publishable key (pk_live_...) is safe in the browser and its secret key (sk_live_...) is not; Supabase has a publishable (anon) key and a secret (service_role) key that skips every access rule.

.env.localconfig
# public: only works within your access rulesNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_... # secret: server only, skips every access ruleSUPABASE_SECRET_KEY=sb_secret_...STRIPE_SECRET_KEY=sk_live_...
Public keys may reach the browser. Secret keys never leave the server.

What goes wrong

  1. Swapping in the secret key to make an error go away

    A query fails on permissions, so the agent switches to the service_role key. The error stops because every access rule is now skipped, sometimes in code that ships to the browser.

  2. Deleting a leaked key from the code and calling it fixed

    The key is still in your git history and in any copy someone already made. Revoke it at the provider and create a new one.

  3. Pasting keys into chats, screenshots and logs

    A key in a support thread, a screen recording or a console.log line is as leaked as one on GitHub.

    console.log("stripe key", process.env.STRIPE_SECRET_KEY);

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
List every API key this app uses, mark each as public or secret, and confirm no secret key appears in browser code or in git history. Never use the Supabase service_role or secret key to get past a permissions error; fix the access rule instead.

Quick check

Sign in to earn +10 XP for it

You find your OpenAI key in a public GitHub commit from last month. What do you do first?

Got a prompt that touches secrets and API keys?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.