Track 09 · Lesson 1 of 9Shipping safely

Track 09 · Shipping safely

Secrets and their blast radius

Lesson 1 of 9· 6 min

A secret is any value that grants access: API keys, signing keys, database URLs, tokens. Its blast radius is how much damage one leak allows, and you choose most of it on the day you create the key.

What does each key open?

Pick a key, then narrow it

If this leaked today, the holder could:

  • Read every customer upload
  • Overwrite any upload
  • Delete every upload
  • Change account settings

Doors open across all five keys

14 of 14

Most keys are master keys. Narrow the ones you can: the scope you pick on the day you create a key is the damage you accept on the day it leaks.

Narrow before you need to#

Most providers offer scoped keys: read-only, one bucket, one repository, restricted to the calls you make. Admin keys are convenient on day one and catastrophic on the day they leak. Some secrets can’t be narrowed at all, like a JWT signing secret, which can forge any session. Those must never leave the server.

Keep an inventory#

For every secret, write down where it lives, who and what can read it, when it was last rotated, and how to rotate it. Writing the rotation steps before a leak turns a panic into a checklist.

What ships to the browser#

In Next.js, any environment variable prefixed NEXT_PUBLIC_ is written into the JavaScript bundle at build time, for every visitor to read. Some keys are designed for that; many aren’t.

Public or secret?

Judge each variable

  • NEXT_PUBLIC_PAYMENTS_PUBLISHABLE_KEY=pk_live_51Hx…Ships to the browser
  • NEXT_PUBLIC_AI_API_KEY=sk-proj-8f2…Ships to the browser
  • PAYMENTS_SECRET_KEY=sk_live_51Hx…Server only
  • NEXT_PUBLIC_SENTRY_DSN=https://4f1…@o123.ingest…Ships to the browser
  • NEXT_PUBLIC_DB_ANON_KEY=eyJhbGciOi…Ships to the browser
  • DATABASE_URL=postgres://app:…@db:5432/appServer only
  • NEXT_PUBLIC_ADMIN_PASSWORD=hunter2…Ships to the browser

0 of 7 judged

Check yourself

Which secret can’t be made safer by narrowing its scope?